Skip to content

Commit 3c45ff4

Browse files
committed
integration test: MSBuild 16 & NET 5.0
1 parent bc5c060 commit 3c45ff4

File tree

3 files changed

+126
-2
lines changed

3 files changed

+126
-2
lines changed

.github/workflows/build.yml

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ jobs:
271271
with:
272272
path: integration-test
273273

274-
msbuild:
274+
msbuild-sentry:
275275
needs: build-sentry-native
276276
name: MSBuild
277277
runs-on: windows-latest
@@ -313,6 +313,64 @@ jobs:
313313
msbuild.binlog
314314
if-no-files-found: ignore
315315

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+
vs-build-tools: 2019
336+
vs-version: '[16.0,17.0)'
337+
338+
steps:
339+
- name: Checkout
340+
uses: actions/checkout@v5
341+
with:
342+
submodules: recursive
343+
344+
- name: Install .NET 5.0 SDK
345+
uses: actions/setup-dotnet@v4
346+
with:
347+
dotnet-version: '5.0.x'
348+
349+
- name: Install .NET SDK
350+
uses: actions/setup-dotnet@v4
351+
with:
352+
global-json-file: global.json
353+
354+
- name: Install VS Build Tools
355+
if: ${{ matrix.vs-build-tools }}
356+
run: choco install visualstudio${{ matrix.vs-build-tools }}buildtools
357+
358+
- name: Setup MSBuild
359+
uses: microsoft/setup-msbuild@6fb02220983dee41ce7ae257b6f4d8f9bf5ed4ce # v2
360+
with:
361+
vs-version: ${{ matrix.vs-version }}
362+
363+
- name: Fetch NuGet Packages
364+
uses: actions/download-artifact@v5
365+
with:
366+
name: msbuild-${{ github.sha }}
367+
path: src
368+
369+
- name: Run MSBuild tests
370+
uses: getsentry/github-workflows/sentry-cli/integration-test/@a5e409bd5bad4c295201cdcfe862b17c50b29ab7 # v2.14.1
371+
with:
372+
path: integration-test/msbuild.Tests.ps1
373+
316374
# Unsupported Native AOT runtimes should have SentryNative auto-disabled
317375
# to avoid native library loading errors on startup.
318376
unsupported-aot:

integration-test/common.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ BeforeAll {
197197
if ($type -eq 'console')
198198
{
199199
AddPackageReference $name 'Sentry'
200-
if (!$IsMacOS -or $framework -eq 'net8.0')
200+
if ((!$IsMacOS -or $framework -eq 'net8.0') -and $framework -ne 'net5.0')
201201
{
202202
@"
203203
<Project>

integration-test/msbuild.Tests.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# This file contains test cases for https://pester.dev/
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = 'Stop'
4+
. $PSScriptRoot/common.ps1
5+
6+
$HasMSBuild = (Get-Command msbuild -ErrorAction SilentlyContinue)
7+
8+
Describe 'MSBuild app (<framework>)' -ForEach @(
9+
@{ framework = 'net5.0' },
10+
@{ framework = 'net8.0' },
11+
@{ framework = 'net9.0' }
12+
) -Skip:(-not $IsWindows -or -not $HasMSBuild) {
13+
BeforeAll {
14+
$path = './msbuild-app'
15+
DotnetNew 'console' $path $framework
16+
@'
17+
using Sentry;
18+
19+
SentrySdk.Init(options =>
20+
{
21+
options.Dsn = args[0];
22+
options.Debug = true;
23+
});
24+
25+
SentrySdk.CaptureMessage("Hello from MSBuild app");
26+
'@ | Out-File $path/Program.cs
27+
28+
function Test-NetSdkInstalled([string]$framework) {
29+
$version = $framework -replace 'net(\d+)\.0', '$1'
30+
$sdks = dotnet --list-sdks
31+
return $null -ne ($sdks | Where-Object { $_ -match "^$version\." })
32+
}
33+
34+
Push-Location $path
35+
}
36+
37+
BeforeEach {
38+
Remove-Item "./bin/Release/$framework" -Recurse -ErrorAction SilentlyContinue
39+
Remove-Item "./obj/Release/$framework" -Recurse -ErrorAction SilentlyContinue
40+
}
41+
42+
AfterAll {
43+
Pop-Location
44+
}
45+
46+
It 'builds without warnings and is able to capture a message' {
47+
if (-not (Test-NetSdkInstalled $framework)) {
48+
Set-ItResult -Skipped -Because "$framework is not installed"
49+
}
50+
51+
$result = Invoke-SentryServer {
52+
Param([string]$url)
53+
$dsn = $url.Replace('http://', 'http://key@') + '/0'
54+
55+
msbuild msbuild-app.csproj -t:Restore,Build -p:Configuration=Release -p:TreatWarningsAsErrors=true
56+
| ForEach-Object { Write-Host $_ }
57+
$LASTEXITCODE | Should -Be 0
58+
59+
msbuild msbuild-app.csproj -t:Run -p:Configuration=Release -p:RunArguments=$dsn
60+
| ForEach-Object { Write-Host $_ }
61+
$LASTEXITCODE | Should -Be 0
62+
}
63+
$result.HasErrors() | Should -BeFalse
64+
$result.Envelopes() | Should -AnyElementMatch "`"message`":`"Hello from MSBuild app`""
65+
}
66+
}

0 commit comments

Comments
 (0)