Skip to content

Commit 6598f9f

Browse files
authored
Read package information from msbuild (Azure#22352)
In order to avoid duplication of logic we are creating an msbuild target that dumps out the properties for each of the projects and then parsing that for our other engineering system needs.
1 parent 4d0e869 commit 6598f9f

File tree

3 files changed

+36
-30
lines changed

3 files changed

+36
-30
lines changed

eng/Directory.Build.Common.targets

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,5 +264,23 @@
264264
<Target Name="RunApiCompat" DependsOnTargets="ValidateApiCompatForSrc" Condition="'$(ApiCompatVersion)' != ''">
265265
</Target>
266266

267+
<Target Name="GetPackageInfo">
268+
<PropertyGroup>
269+
<PackageIsNewSdk>false</PackageIsNewSdk>
270+
<PackageIsNewSdk Condition="'$(IsClientLibrary)' == 'true'">true</PackageIsNewSdk>
271+
272+
<PackageSdkType>data</PackageSdkType>
273+
<PackageSdkType Condition="'$(IsClientLibrary)' == 'true'">client</PackageSdkType>
274+
<PackageSdkType Condition="'$(IsMgmtLibrary)' == 'true'">mgmt</PackageSdkType>
275+
276+
<PackageRootDirectory>$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory)/../).Trim("/").Trim("\\"))</PackageRootDirectory>
277+
278+
<!-- Parse out the service directory based on the relative path to the sdk folder -->
279+
<ServiceDirectory><![CDATA[$([System.Text.RegularExpressions.Regex]::Replace($(PackageRootDirectory), '^.*[\\/]+sdk[\\/]+([^\\/]+).*$', '$1'))]]></ServiceDirectory>
280+
</PropertyGroup>
281+
282+
<Message Condition="'$(IsShippingLibrary)' == 'true'" Text="'$(PackageRootDirectory)' '$(ServiceDirectory)' '$(PackageId)' '$(_VersionInProject)' '$(PackageSdkType)' '$(PackageIsNewSdk)'" Importance="High" />
283+
</Target>
284+
267285
<Import Project="$(CentralPackageVersionPackagePath)\Sdk.targets" />
268286
</Project>

eng/scripts/Language-Settings.ps1

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,26 @@ $packagePattern = "*.nupkg"
66
$MetadataUri = "https://raw.githubusercontent.com/Azure/azure-sdk/main/_data/releases/latest/dotnet-packages.csv"
77
$BlobStorageUrl = "https://azuresdkdocs.blob.core.windows.net/%24web?restype=container&comp=list&prefix=dotnet%2F&delimiter=%2F"
88

9-
function Get-dotnet-PackageInfoFromRepo ($pkgPath, $serviceDirectory)
9+
function Get-AllPackageInfoFromRepo($serviceDirectory)
1010
{
11-
$projDirPath = (Join-Path $pkgPath "src")
11+
$allPackageProps = @()
12+
$msbuildOutput = dotnet msbuild /nologo /t:GetPackageInfo $EngDir/service.proj /p:ServiceDirectory=$serviceDirectory
1213

13-
if (!(Test-Path $projDirPath))
14+
foreach ($projectOutput in $msbuildOutput)
1415
{
15-
return $null
16-
}
17-
18-
$projectPaths = @(Resolve-Path (Join-Path $projDirPath "*.csproj"))
16+
if (!$projectOutput) { continue }
1917

20-
if ($projectpaths.Count -ge 1) {
21-
$projectPath = $projectPaths[0].path
22-
if ($projectPaths.Count -gt 1) {
23-
LogWarning "There is more than on csproj file in the projectpath/src directory. First project picked."
24-
}
25-
}
26-
else {
27-
return $null
28-
}
18+
$pkgPath, $serviceDirectory, $pkgName, $pkgVersion, $sdkType, $isNewSdk = $projectOutput.Split(' ',[System.StringSplitOptions]::RemoveEmptyEntries).Trim("'")
2919

30-
if ($projectPath -and (Test-Path $projectPath))
31-
{
32-
$pkgName = Split-Path -Path $projectPath -LeafBase
33-
$projectData = New-Object -TypeName XML
34-
$projectData.load($projectPath)
35-
$pkgVersion = Select-XML -Xml $projectData -XPath '/Project/PropertyGroup/Version'
36-
$sdkType = "client"
37-
if ($pkgName -match "\.ResourceManager\." -or $pkgName -match "\.Management\.")
38-
{
39-
$sdkType = "mgmt"
40-
}
4120
$pkgProp = [PackageProps]::new($pkgName, $pkgVersion, $pkgPath, $serviceDirectory)
4221
$pkgProp.SdkType = $sdkType
43-
$pkgProp.IsNewSdk = $pkgName.StartsWith("Azure")
22+
$pkgProp.IsNewSdk = ($isNewSdk -eq 'true')
4423
$pkgProp.ArtifactName = $pkgName
45-
return $pkgProp
24+
25+
$allPackageProps += $pkgProp
4626
}
4727

48-
return $null
28+
return $allPackageProps
4929
}
5030

5131
# Returns the nuget publish status of a package id and version.

eng/service.proj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@
6363
<Message Text="Final Build References:" Importance="high"/>
6464
<Message Text=" %(ProjectReference.Identity)" Importance="high"/>
6565
</Target>
66+
67+
<Target Name="GetPackageInfo">
68+
<MSBuild Projects="@(ProjectReference)"
69+
Targets="GetPackageInfo"
70+
BuildInParallel="$(BuildInParallel)"
71+
SkipNonexistentProjects="false"
72+
SkipNonexistentTargets="true" />
73+
</Target>
6674
</Project>

0 commit comments

Comments
 (0)