Skip to content

Commit 5a85fb5

Browse files
committed
Try dotnet msbuild
1 parent 355b616 commit 5a85fb5

File tree

2 files changed

+40
-98
lines changed

2 files changed

+40
-98
lines changed

.github/workflows/build.yml

Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ jobs:
293293
- name: Setup Environment
294294
uses: ./.github/actions/environment
295295

296+
- name: Install .NET 5.0 SDK
297+
uses: actions/setup-dotnet@v4
298+
with:
299+
dotnet-version: '5.0.x'
300+
296301
- name: Build Native Dependencies
297302
uses: ./.github/actions/buildnative
298303

@@ -303,6 +308,11 @@ jobs:
303308
id: msbuild
304309
run: msbuild Sentry-CI-Build-Windows.slnf -t:Restore,Build,Pack -p:Configuration=Release --nologo -v:minimal -flp:logfile=msbuild.log -p:CopyLocalLockFileAssemblies=true -bl:msbuild.binlog
305310

311+
- name: Test MSBuild
312+
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
313+
with:
314+
path: integration-test/msbuild.Tests.ps1
315+
306316
- name: Upload logs
307317
if: ${{ always() }}
308318
uses: actions/upload-artifact@v4
@@ -313,65 +323,6 @@ jobs:
313323
msbuild.binlog
314324
if-no-files-found: ignore
315325

316-
- name: Archive NuGet Packages
317-
uses: actions/upload-artifact@v4
318-
with:
319-
name: msbuild-${{ github.sha }}
320-
if-no-files-found: error
321-
path: |
322-
src/**/Release/*.nupkg
323-
src/**/Release/*.snupkg
324-
325-
msbuild-test:
326-
needs: msbuild-sentry
327-
name: MSBuild Test (${{ matrix.name }})
328-
runs-on: windows-latest
329-
strategy:
330-
fail-fast: false
331-
matrix:
332-
include:
333-
- name: VS 2022
334-
- name: VS 2019
335-
dotnet-version: '5.0.x'
336-
vs-build-tools: 2019
337-
vs-version: '[16.0,17.0)'
338-
339-
steps:
340-
- name: Checkout
341-
uses: actions/checkout@v5
342-
with:
343-
submodules: recursive
344-
345-
- name: Setup Environment
346-
if: ${{ !matrix.dotnet-version }}
347-
uses: ./.github/actions/environment
348-
349-
- name: Install .NET SDK
350-
if: ${{ matrix.dotnet-version }}
351-
uses: actions/setup-dotnet@v4
352-
with:
353-
dotnet-version: ${{ matrix.dotnet-version }}
354-
355-
- name: Install VS Build Tools
356-
if: ${{ matrix.vs-build-tools }}
357-
run: choco install visualstudio${{ matrix.vs-build-tools }}buildtools
358-
359-
- name: Setup MSBuild
360-
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2
361-
with:
362-
vs-version: ${{ matrix.vs-version }}
363-
364-
- name: Fetch NuGet Packages
365-
uses: actions/download-artifact@v5
366-
with:
367-
name: msbuild-${{ github.sha }}
368-
path: src
369-
370-
- name: Run MSBuild tests
371-
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
372-
with:
373-
path: integration-test/msbuild.Tests.ps1
374-
375326
# Unsupported Native AOT runtimes should have SentryNative auto-disabled
376327
# to avoid native library loading errors on startup.
377328
unsupported-aot:

integration-test/msbuild.Tests.ps1

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,31 @@ Set-StrictMode -Version Latest
33
$ErrorActionPreference = 'Stop'
44
. $PSScriptRoot/common.ps1
55

6-
$HasMSBuild = (Get-Command msbuild -ErrorAction SilentlyContinue)
7-
86
Describe '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
@'
2032
using Sentry;
2133
@@ -26,49 +38,28 @@ SentrySdk.Init(options =>
2638
});
2739
2840
SentrySdk.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

Comments
 (0)