Skip to content
Merged
129 changes: 86 additions & 43 deletions BuildAll.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,59 +88,102 @@ if ([string]::IsNullOrEmpty($ComponentPackageVersion))
Write-Host "Updating ComponentPackageVersion from MicrosoftWindowsAppSDKVersionPackageVersion in Directory.Packages.props: $ComponentPackageVersion"
}

# Build a lookup of package versions from Directory.Packages.props for nuspec dependency updates.
# The XML defines properties in PropertyGroups and references them in PackageVersion items.
# Internal packages have IsInternal="true" metadata; when -WindowsAppSDKVersionPinned is set,
# those use the pinned version (matching MSBuild behavior).
$dppPath = Join-Path $env:Build_SourcesDirectory 'Directory.Packages.props'
[xml]$dppXmlForVersions = [xml](Get-Content -Path $dppPath -Raw)

# First, build a property lookup from all PropertyGroups.
# Properties may contain ValueOrDefault expressions — extract the fallback value,
# or use the pinned version when WindowsAppSDKVersionPinned is set.
$msbuildProps = @{}
$vodPattern = [regex]"ValueOrDefault\([^,]+,\s*'([^']+)'\)"
foreach ($pg in $dppXmlForVersions.Project.PropertyGroup) {
foreach ($prop in $pg.ChildNodes) {
if ($prop.NodeType -eq 'Element' -and -not [string]::IsNullOrEmpty($prop.InnerText)) {
$value = $prop.InnerText
$vodMatch = $vodPattern.Match($value)
if ($vodMatch.Success) {
if (-not [string]::IsNullOrEmpty($WindowsAppSDKVersionPinned)) {
$value = $WindowsAppSDKVersionPinned
} else {
$value = $vodMatch.Groups[1].Value
$internalPackageVersions = @{}
if (($AzureBuildStep -eq 'all') -or ($AzureBuildStep -eq 'PackNuget')) {
# Build a lookup of package versions for nuspec dependency updates. Process both the local
# CPM file and the optional shared props file because raw XML does not evaluate MSBuild imports.
$dppPath = Join-Path $env:Build_SourcesDirectory 'Directory.Packages.props'
[xml]$dppXmlForVersions = Get-Content -Path $dppPath -Raw
$msbuildProps = @{}
$vodPattern = [regex]"ValueOrDefault\([^,]+,\s*'([^']+)'\)"

function Add-VersionProperties([xml]$PropsXml, [bool]$HasSharedProps, [bool]$ApplyImportConditions) {
foreach ($propertyGroup in $PropsXml.Project.PropertyGroup) {
if ($ApplyImportConditions) {
$condition = $propertyGroup.GetAttribute('Condition')
if (($condition -match 'WindowsAppSDKPackageVersionProps.*!=' -and -not $HasSharedProps) -or
($condition -match 'WindowsAppSDKPackageVersionProps.*==' -and $HasSharedProps)) {
continue
}
}

foreach ($property in $propertyGroup.ChildNodes) {
if ($property.NodeType -ne 'Element' -or [string]::IsNullOrWhiteSpace($property.InnerText)) {
continue
}

$value = $property.InnerText
$vodMatch = $vodPattern.Match($value)
if ($vodMatch.Success) {
$value = if ([string]::IsNullOrEmpty($WindowsAppSDKVersionPinned)) {
$vodMatch.Groups[1].Value
} else {
$WindowsAppSDKVersionPinned
}
}
$msbuildProps[$property.Name] = $value
}
$msbuildProps[$prop.Name] = $value
}
}
}

# Then resolve PackageVersion items
$internalPackageVersions = @{}
foreach ($ig in $dppXmlForVersions.Project.ItemGroup) {
foreach ($pv in $ig.SelectNodes("*[local-name()='PackageVersion']")) {
$pkgName = $pv.GetAttribute("Include")
$versionExpr = $pv.GetAttribute("Version")

# Resolve $(PropertyName) references
$resolved = $versionExpr
if ($versionExpr -match '\$\(') {
foreach ($propMatch in [regex]::Matches($versionExpr, '\$\(([^)]+)\)')) {
$propName = $propMatch.Groups[1].Value
if ($msbuildProps.ContainsKey($propName)) {
$resolved = $msbuildProps[$propName]
}
function Resolve-VersionExpression([string]$Value) {
$resolved = $Value
foreach ($propertyMatch in [regex]::Matches($Value, '\$\(([^)]+)\)')) {
$propertyName = $propertyMatch.Groups[1].Value
if (-not $msbuildProps.ContainsKey($propertyName)) {
throw "Package version property '$propertyName' was not found."
}
$resolved = $resolved.Replace($propertyMatch.Value, $msbuildProps[$propertyName])
}
return $resolved
}

$sharedPropsPath = $null
$searchDirectory = Split-Path $dppPath -Parent
while (-not [string]::IsNullOrWhiteSpace($searchDirectory)) {
$candidate = Join-Path $searchDirectory 'WindowsAppSDK.PackageVersion.props'
if (Test-Path -LiteralPath $candidate -PathType Leaf) {
$sharedPropsPath = $candidate
break
}
$parentDirectory = Split-Path $searchDirectory -Parent
if ($parentDirectory -eq $searchDirectory) {
break
}
$searchDirectory = $parentDirectory
}

Add-VersionProperties $dppXmlForVersions ($null -ne $sharedPropsPath) $true
if ($sharedPropsPath) {
[xml]$sharedPropsXml = Get-Content -LiteralPath $sharedPropsPath -Raw
Add-VersionProperties $sharedPropsXml $true $false
Add-VersionProperties $dppXmlForVersions $true $true
}

foreach ($itemGroup in $dppXmlForVersions.Project.ItemGroup) {
foreach ($packageVersionItem in $itemGroup.SelectNodes("*[local-name()='PackageVersion']")) {
$packageId = $packageVersionItem.GetAttribute('Include')
if ($internalPackageVersions.ContainsKey($packageId)) {
throw "Duplicate PackageVersion item '$packageId' in '$dppPath'."
}

$isInternal = $packageVersionItem.GetAttribute('IsInternal') -eq 'true'
$resolvedVersion = if ($isInternal -and -not [string]::IsNullOrEmpty($WindowsAppSDKVersionPinned)) {
$WindowsAppSDKVersionPinned
} else {
Resolve-VersionExpression $packageVersionItem.GetAttribute('Version')
}
if ([string]::IsNullOrWhiteSpace($resolvedVersion) -or $resolvedVersion -match '\$\(') {
throw "PackageVersion '$packageId' did not resolve to a version: '$resolvedVersion'."
}
$internalPackageVersions[$packageId] = $resolvedVersion
}
}

$internalPackageVersions[$pkgName] = $resolved
if (-not [string]::IsNullOrEmpty($WindowsAppSDKVersionPinned)) {
Write-Host "Pinned internal WindowsAppSDK packages to version '$WindowsAppSDKVersionPinned' for nuspec dependency rewriting."
}
}
if (-not [string]::IsNullOrEmpty($WindowsAppSDKVersionPinned)) {
Write-Host "Pinned internal WindowsAppSDK packages to version '$WindowsAppSDKVersionPinned' for nuspec dependency rewriting."
}

$configurationForMrtAndAnyCPU = "Release"
$MRTSourcesDirectory = "dev\MRTCore"
Expand Down
13 changes: 12 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@

Mono-build override: when $(WindowsAppSDKVersionPinned) is set, all internal WinAppSDK
package versions are pinned to that value instead of their fallback defaults.

When this repository is checked out beneath a mono-build package configuration,
WindowsAppSDK.PackageVersion.props is imported last and supplies internal package versions.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
<WindowsAppSDKPackageVersionProps>$([MSBuild]::GetPathOfFileAbove('WindowsAppSDK.PackageVersion.props', '$(MSBuildThisFileDirectory)'))</WindowsAppSDKPackageVersionProps>
</PropertyGroup>

<!-- ═══════════════════════════════════════════════════════════════════════
Expand Down Expand Up @@ -45,7 +49,7 @@
and by eng/PackageReference/*.csproj PackageDownload items.
ValueOrDefault resolves to $(WindowsAppSDKVersionPinned) when set (mono-build),
otherwise falls back to the pinned version literal. -->
<PropertyGroup Label="WindowsAppSDK Package Version Properties">
<PropertyGroup Label="WindowsAppSDK Package Version Properties" Condition="'$(WindowsAppSDKPackageVersionProps)' == ''">
<MicrosoftWindowsAppSDKBasePackageVersion>$([MSBuild]::ValueOrDefault('$(WindowsAppSDKVersionPinned)', '2.0.6-dev.experimental1'))</MicrosoftWindowsAppSDKBasePackageVersion>
<MicrosoftFrameworkUdkPackageVersion>$([MSBuild]::ValueOrDefault('$(WindowsAppSDKVersionPinned)', '3.0.0-experimental-27300.1896.260713-1015.0'))</MicrosoftFrameworkUdkPackageVersion>
<MicrosoftProjectReunionInteractiveExperiencesTransportPackagePackageVersion>$([MSBuild]::ValueOrDefault('$(WindowsAppSDKVersionPinned)', '3.0.0-experimental-27300.1896.260713-1015.0'))</MicrosoftProjectReunionInteractiveExperiencesTransportPackagePackageVersion>
Expand All @@ -69,6 +73,12 @@
<MicrosoftWindowsAppSDKProtobufVersion>3.21.12</MicrosoftWindowsAppSDKProtobufVersion>
</PropertyGroup>

<Import Project="$(WindowsAppSDKPackageVersionProps)" Condition="'$(WindowsAppSDKPackageVersionProps)' != ''" />
<PropertyGroup Condition="'$(WindowsAppSDKPackageVersionProps)' != ''">
<MicrosoftWindowsAppSDKBasePackageVersion>$(MicrosoftWindowsAppSDKBasePackagePackageVersion)</MicrosoftWindowsAppSDKBasePackageVersion>
<MicrosoftWindowsAppSDKInteractiveExperiencesPackageVersion>$(MicrosoftWindowsAppSDKInteractiveExperiencesPackagePackageVersion)</MicrosoftWindowsAppSDKInteractiveExperiencesPackageVersion>
</PropertyGroup>

<!-- ═══════════════════════════════════════════════════════════════════════
CPM PackageVersion items: reference the properties above.
Each version is defined exactly once (in the PropertyGroups).
Expand Down Expand Up @@ -123,4 +133,5 @@
<PackageVersion Include="System.Net.Http" Version="4.3.4" />
<PackageVersion Include="System.Text.Json" Version="8.0.5" />
</ItemGroup>

</Project>