@@ -3,19 +3,31 @@ Set-StrictMode -Version Latest
33$ErrorActionPreference = ' Stop'
44. $PSScriptRoot / common.ps1
55
6- $HasMSBuild = (Get-Command msbuild - ErrorAction SilentlyContinue)
7-
86Describe ' MSBuild app (<framework>)' - ForEach @ (
9- @ { framework = ' net5.0' ; msbuild = ' 16 ' },
10- @ { framework = ' net8.0' },
11- @ { framework = ' net9.0' }
12- ) - Skip:(-not $IsWindows -or -not $HasMSBuild ) {
7+ @ { framework = ' net5.0' ; sdk = ' 5.0.400 ' },
8+ @ { framework = ' net8.0' ; sdk = ' 8.0.400 ' },
9+ @ { framework = ' net9.0' ; sdk = ' 9.0.300 ' }
10+ ) - Skip:(-not $IsWindows ) {
1311 BeforeAll {
14- $path = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.IO.Path ]::GetRandomFileName())
15- Set-Location $path # temp cwd to avoid global.json
12+ $tempDir = Join-Path ([System.IO.Path ]::GetTempPath()) ([System.IO.Path ]::GetRandomFileName())
13+ New-Item - ItemType Directory - Path $tempDir | Out-Null
14+ Push-Location $tempDir
15+ @"
16+ {
17+ "sdk": {
18+ "version": "$sdk ",
19+ "rollForward": "latestFeature"
20+ }
21+ }
22+ "@ | Out-File global.json
1623
17- $path = Join-Path $path ' msbuild-app'
18- DotnetNew ' console' $path $framework
24+ dotnet -- version | ForEach-Object { Write-Host $_ }
25+ dotnet msbuild - version | ForEach-Object { Write-Host $_ }
26+ $hasDotnetSdk = $LASTEXITCODE -eq 0
27+
28+ if ($hasDotnetSdk ) {
29+ DotnetNew ' console' $tempDir / msbuild- app $framework
30+ Set-Location $tempDir / msbuild- app
1931 @'
2032using Sentry;
2133
@@ -26,49 +38,28 @@ SentrySdk.Init(options =>
2638});
2739
2840SentrySdk.CaptureMessage("Hello from MSBuild app");
29- '@ | Out-File $path / Program.cs
30-
31- Set-Location $path
32-
33- function Test-NetSdk ([string ]$framework ) {
34- $version = $framework -replace ' net(\d+)\.0' , ' $1'
35- $sdks = dotnet -- list- sdks
36- return $null -ne ($sdks | Where-Object { $_ -match " ^$version \." })
37- }
38-
39- function Test-MSBuild ([string ]$version ) {
40- $output = & msbuild - version 2>&1 | Select-Object - Last 1
41- return $output -match " ^$version \."
41+ '@ | Out-File Program.cs
4242 }
4343 }
4444
45- BeforeEach {
46- Remove-Item " ./bin/Release/$framework " - Recurse - ErrorAction SilentlyContinue
47- Remove-Item " ./obj/Release/$framework " - Recurse - ErrorAction SilentlyContinue
48- }
49-
5045 AfterAll {
5146 Pop-Location
47+ Remove-Item - Recurse - Force $tempDir
5248 }
5349
5450 It ' builds without warnings and is able to capture a message' {
55- if (-not ( Test-NetSdk $framework ) ) {
51+ if (-not $hasDotnetSdk ) {
5652 Set-ItResult - Skipped - Because " $framework is not installed"
5753 }
58- if ($msbuild -and -not (Test-MSBuild $msbuild )) {
59- Set-ItResult - Skipped - Because " MSBuild $msbuild is not installed"
60- }
54+ # TODO: pass -p:TreatWarningsAsErrors=true after #4554 is fixed
55+ dotnet msbuild msbuild- app.csproj - t:Restore, Build - p:Configuration= Release - p:TreatWarningsAsErrors= false
56+ | ForEach-Object { Write-Host $_ }
57+ $LASTEXITCODE | Should - Be 0
6158
6259 $result = Invoke-SentryServer {
6360 Param ([string ]$url )
6461 $dsn = $url.Replace (' http://' , ' http://key@' ) + ' /0'
65-
66- # TODO: pass -p:TreatWarningsAsErrors=true after #4554 is fixed
67- msbuild msbuild- app.csproj - t:Restore, Build - p:Configuration= Release - p:TreatWarningsAsErrors= false
68- | ForEach-Object { Write-Host $_ }
69- $LASTEXITCODE | Should - Be 0
70-
71- msbuild msbuild- app.csproj - t:Run - p:Configuration= Release - p:RunArguments= $dsn
62+ dotnet msbuild msbuild- app.csproj - t:Run - p:Configuration= Release - p:RunArguments= $dsn
7263 | ForEach-Object { Write-Host $_ }
7364 $LASTEXITCODE | Should - Be 0
7465 }
0 commit comments