diff --git a/build/RunTestsOnHelix.cmd b/build/RunTestsOnHelix.cmd index f55fcf1ead42..b092458272ca 100644 --- a/build/RunTestsOnHelix.cmd +++ b/build/RunTestsOnHelix.cmd @@ -6,10 +6,15 @@ set NUGET_EXPERIMENTAL_NETWORK_RETRY_DELAY_MILLISECONDS=1000 set MicrosoftNETBuildExtensionsTargets=%HELIX_CORRELATION_PAYLOAD%\ex\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\Microsoft.NET.Build.Extensions.targets set DOTNET_ROOT=%HELIX_CORRELATION_PAYLOAD%\d +set DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR=%HELIX_CORRELATION_PAYLOAD%\r +set MSBuildSDKsPath=%HELIX_CORRELATION_PAYLOAD%\r set PATH=%DOTNET_ROOT%;%PATH% set DOTNET_MULTILEVEL_LOOKUP=0 set TestFullMSBuild=%1 +REM Ensure Visual Studio instances allow preview SDKs +PowerShell -ExecutionPolicy ByPass -NoProfile -File "%HELIX_CORRELATION_PAYLOAD%\t\eng\EnablePreviewSdks.ps1" + REM Use powershell to call partical Arcade logic to get full framework msbuild path and assign it if "%TestFullMSBuild%"=="true" ( FOR /F "tokens=*" %%g IN ('PowerShell -ExecutionPolicy ByPass -File "%HELIX_CORRELATION_PAYLOAD%\t\eng\print-full-msbuild-path.ps1"') do (SET DOTNET_SDK_TEST_MSBUILD_PATH=%%g) diff --git a/build/sdktests.ps1 b/build/sdktests.ps1 index 84a1b03a0a1f..c86257bb394b 100644 --- a/build/sdktests.ps1 +++ b/build/sdktests.ps1 @@ -7,7 +7,7 @@ Param( [string] $tests = "", [Parameter(ValueFromRemainingArguments=$true)][String[]]$additionalRunParams ) - +EnablePreviewSdks Set-StrictMode -Version 2.0 $ErrorActionPreference = "Stop" @@ -52,7 +52,7 @@ if ($run) foreach ( $name in $testNames ) { $cmd = "testSdk$name" - + & $cmd -xml ($name + "results.xml") $additionalRunParams if ($LASTEXITCODE -ne 0) diff --git a/eng/EnablePreviewSdks.ps1 b/eng/EnablePreviewSdks.ps1 new file mode 100644 index 000000000000..19c9ae8f71d9 --- /dev/null +++ b/eng/EnablePreviewSdks.ps1 @@ -0,0 +1,33 @@ +param() + +$RepoRoot = Split-Path -Parent $PSScriptRoot +if (-not $RepoRoot) { + throw "Unable to determine repository root." +} + +. "$PSScriptRoot\common\tools.ps1" + +try { + $vsInfo = LocateVisualStudio +} +catch { + Write-Host "LocateVisualStudio failed: $_" + return +} + +if ($null -eq $vsInfo) { + Write-Host "No Visual Studio instance detected; preview SDKs remain enabled by default." + return +} + +$vsId = $vsInfo.instanceId +$vsMajorVersion = $vsInfo.installationVersion.Split('.')[0] +$instanceDir = Join-Path $env:USERPROFILE "AppData\Local\Microsoft\VisualStudio\$vsMajorVersion.0_$vsId" + +Create-Directory $instanceDir + +$sdkFile = Join-Path $instanceDir 'sdk.txt' +'UsePreviews=True' | Set-Content -Path $sdkFile -Encoding ASCII + +Write-Host "Updated $sdkFile" +Get-Content -Path $sdkFile | ForEach-Object { Write-Host " $_" } diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index 9b3ad8840fdb..80ac2f853cfb 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -295,7 +295,7 @@ function InstallDotNet([string] $dotnetRoot, if ($runtime -eq "aspnetcore") { $runtimePath = $runtimePath + "\Microsoft.AspNetCore.App" } if ($runtime -eq "windowsdesktop") { $runtimePath = $runtimePath + "\Microsoft.WindowsDesktop.App" } $runtimePath = $runtimePath + "\" + $version - + $dotnetVersionLabel = "runtime toolset '$runtime/$architecture v$version'" if (Test-Path $runtimePath) { @@ -547,19 +547,25 @@ function LocateVisualStudio([object]$vsRequirements = $null){ }) } - if (!$vsRequirements) { $vsRequirements = $GlobalJson.tools.vs } + if (!$vsRequirements) { + if (Get-Member -InputObject $GlobalJson.tools -Name 'vs' -ErrorAction SilentlyContinue) { + $vsRequirements = $GlobalJson.tools.vs + } else { + $vsRequirements = $null + } + } $args = @('-latest', '-format', 'json', '-requires', 'Microsoft.Component.MSBuild', '-products', '*') if (!$excludePrereleaseVS) { $args += '-prerelease' } - if (Get-Member -InputObject $vsRequirements -Name 'version') { + if ($vsRequirements -and (Get-Member -InputObject $vsRequirements -Name 'version' -ErrorAction SilentlyContinue)) { $args += '-version' $args += $vsRequirements.version } - if (Get-Member -InputObject $vsRequirements -Name 'components') { + if ($vsRequirements -and (Get-Member -InputObject $vsRequirements -Name 'components' -ErrorAction SilentlyContinue)) { foreach ($component in $vsRequirements.components) { $args += '-requires' $args += $component @@ -576,6 +582,22 @@ function LocateVisualStudio([object]$vsRequirements = $null){ return $vsInfo[0] } +function EnablePreviewSdks() { + $vsInfo = LocateVisualStudio + if ($vsInfo -eq $null) { + # Preview SDKs are allowed when no Visual Studio instance is installed + return + } + + $vsId = $vsInfo.instanceId + $vsMajorVersion = $vsInfo.installationVersion.Split('.')[0] + + $instanceDir = Join-Path ${env:USERPROFILE} "AppData\Local\Microsoft\VisualStudio\$vsMajorVersion.0_$vsId" + Create-Directory $instanceDir + $sdkFile = Join-Path $instanceDir "sdk.txt" + 'UsePreviews=True' | Set-Content $sdkFile +} + function InitializeBuildTool() { if (Test-Path variable:global:_BuildTool) { # If the requested msbuild parameters do not match, clear the cached variables. @@ -610,7 +632,7 @@ function InitializeBuildTool() { } else { $initializeBuildToolFramework=$env:_OverrideArcadeInitializeBuildToolFramework } - + $buildTool = @{ Path = $dotnetPath; Command = 'msbuild'; Tool = 'dotnet'; Framework = $initializeBuildToolFramework } } elseif ($msbuildEngine -eq "vs") { try { diff --git a/eng/restore-toolset.ps1 b/eng/restore-toolset.ps1 index 83b1fbea151e..2aece3129a81 100644 --- a/eng/restore-toolset.ps1 +++ b/eng/restore-toolset.ps1 @@ -4,6 +4,8 @@ function InitializeCustomSDKToolset { Write-Host "INFO: Tests will run against full MSBuild in $env:DOTNET_SDK_TEST_MSBUILD_PATH" } + EnablePreviewSdks + if (-not $restore) { return } diff --git a/global.json b/global.json index 8d0dd39886de..92ab3ab340d3 100644 --- a/global.json +++ b/global.json @@ -1,6 +1,9 @@ { "tools": { "dotnet": "9.0.111", + "sdk": { + "allowPrerelease": true + }, "runtimes": { "dotnet": [ "$(VSRedistCommonNetCoreSharedFrameworkx6490PackageVersion)" @@ -22,4 +25,4 @@ "Microsoft.Build.NoTargets": "3.7.0", "Microsoft.DotNet.CMake.Sdk": "9.0.0-beta.24217.1" } -} +} \ No newline at end of file