Skip to content

Commit f666304

Browse files
authored
fix: Native AOT linking (#4298)
1 parent 30dffad commit f666304

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- Fix linking of libsentry-native to avoid DllNotFoundException in Native AOT applications ([#4298](https://github.com/getsentry/sentry-dotnet/pull/4298))
8+
39
## 5.11.0
410

511
### Features

integration-test/aot.Tests.ps1

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# This file contains test cases for https://pester.dev/
2+
Set-StrictMode -Version Latest
3+
$ErrorActionPreference = 'Stop'
4+
5+
Describe 'Publish' {
6+
BeforeAll {
7+
$package = Get-ChildItem -Path "$PSScriptRoot/../src/Sentry/bin/Release/Sentry.*.nupkg" -File | Select-Object -First 1
8+
if (-not $package)
9+
{
10+
throw "No NuGet package found in src/Sentry/bin/Release."
11+
}
12+
13+
$tempDir = Resolve-Path ([System.IO.Path]::GetTempPath())
14+
$tempDir = Join-Path $tempDir ([System.IO.Path]::GetRandomFileName())
15+
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
16+
Set-Location $tempDir
17+
Write-Host "Testing $package in $tempDir"
18+
19+
Write-Host "::group::Setup local NuGet source"
20+
$localPackages = Join-Path $tempDir "packages"
21+
New-Item -ItemType Directory -Path $localPackages -Force | Out-Null
22+
Copy-Item $package $localPackages
23+
$localConfig = Join-Path $tempDir "nuget.config"
24+
Copy-Item $PSScriptRoot/nuget.config $localConfig
25+
(Get-Content $localConfig) -replace '\./packages', $localPackages | Set-Content $localConfig
26+
$env:NUGET_PACKAGES = Join-Path $tempDir "nuget"
27+
New-Item -ItemType Directory -Path $env:NUGET_PACKAGES -Force | Out-Null
28+
dotnet nuget list source | Write-Host
29+
Write-Host "::endgroup::"
30+
31+
Write-Host "::group::Create test project"
32+
dotnet new console --aot --name hello-sentry --output . | Write-Host
33+
dotnet add package Sentry --prerelease --source $localPackages | Write-Host
34+
@"
35+
SentrySdk.Init(options =>
36+
{
37+
options.Dsn = "https://foo@sentry.invalid/42";
38+
options.Debug = true;
39+
});
40+
Console.WriteLine("Hello, Sentry!");
41+
"@ | Set-Content Program.cs
42+
Write-Host "::endgroup::"
43+
}
44+
45+
AfterAll {
46+
if ($tempDir -and (Test-Path $tempDir))
47+
{
48+
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
49+
}
50+
}
51+
52+
It 'Aot' {
53+
dotnet publish -c Release | Write-Host
54+
$LASTEXITCODE | Should -Be 0
55+
56+
$tfm = (Get-ChildItem -Path "bin/Release" -Directory | Select-Object -First 1).Name
57+
$rid = (Get-ChildItem -Path "bin/Release/$tfm" -Directory | Select-Object -First 1).Name
58+
& "bin/Release/$tfm/$rid/publish/hello-sentry" | Write-Host
59+
$LASTEXITCODE | Should -Be 0
60+
}
61+
62+
It 'Container' -Skip:(!$IsLinux -or !(Get-Command docker -ErrorAction SilentlyContinue)) {
63+
dotnet publish -p:EnableSdkContainerSupport=true -t:PublishContainer | Write-Host
64+
$LASTEXITCODE | Should -Be 0
65+
66+
docker run --rm hello-sentry | Write-Host
67+
$LASTEXITCODE | Should -Be 0
68+
}
69+
}

src/Sentry/Platforms/Native/buildTransitive/Sentry.Native.targets

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,13 @@
1818
Trim="true" />
1919
</ItemGroup>
2020

21+
<!-- Helpful properties copied from Sentry.props -->
22+
<PropertyGroup Condition="'$(TargetFramework)' != ''">
23+
<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion>
24+
<_SentryIsNet8OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 8.0))</_SentryIsNet8OrGreater>
25+
<_SentryIsNet9OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 9.0))</_SentryIsNet9OrGreater>
26+
</PropertyGroup>
27+
2128
<PropertyGroup>
2229
<!-- net8.0 or greater -->
2330
<FrameworkSupportsNative Condition="'$(_SentryIsNet8OrGreater)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</FrameworkSupportsNative>

0 commit comments

Comments
 (0)