Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- Fix linking of libsentry-native to avoid DllNotFoundException in Native AOT applications ([#4298](https://github.com/getsentry/sentry-dotnet/pull/4298))

## 5.11.0

### Features
Expand Down
69 changes: 69 additions & 0 deletions integration-test/aot.Tests.ps1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to get to the bottom of why these props are not being read from:

<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion>
<_SentryIsNet8OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 8.0))</_SentryIsNet8OrGreater>
<_SentryIsNet9OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 9.0))</_SentryIsNet9OrGreater>

... and the closely related:

Note: The following platform-specific properties need to be set in both Directory.Build.props and Directory.Build.targets.
TODO: Figure out how to consolidate to a single location.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sentry.props is read but before TargetFramework is set 🙁

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so no. See:

I think MS Build runs a couple of passes though... once to do stuff that is framework specific (when the TargetFramework is set) and once to do stuff that is framework agnostic. That's why this condition was added to the props file:

<PropertyGroup Condition="'$(TargetFramework)' != ''">

In the experimenting that I did, the agnostic run seems to happen after the specific stuff.

Any code in the props/targets/csproj files that depends on the TargetFramework being set really needs to be guarded by that condition then, since otherwise it will get executed with an effective target framework version of 0 (and likely do something unexpected).

All of this is just from experimenting and trying to reverse engineer it though... I'd feel way more comfortable if there were some docs somewhere explaining what the heck is going on. Whatever it is, it's not very intuitive.

Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# This file contains test cases for https://pester.dev/
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'

Describe 'Publish' {
BeforeAll {
$package = Get-ChildItem -Path "$PSScriptRoot/../src/Sentry/bin/Release/Sentry.*.nupkg" -File | Select-Object -First 1
if (-not $package)
{
throw "No NuGet package found in src/Sentry/bin/Release."
}

$tempDir = Resolve-Path ([System.IO.Path]::GetTempPath())
$tempDir = Join-Path $tempDir ([System.IO.Path]::GetRandomFileName())
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
Set-Location $tempDir
Write-Host "Testing $package in $tempDir"

Write-Host "::group::Setup local NuGet source"
$localPackages = Join-Path $tempDir "packages"
New-Item -ItemType Directory -Path $localPackages -Force | Out-Null
Copy-Item $package $localPackages
$localConfig = Join-Path $tempDir "nuget.config"
Copy-Item $PSScriptRoot/nuget.config $localConfig
(Get-Content $localConfig) -replace '\./packages', $localPackages | Set-Content $localConfig
$env:NUGET_PACKAGES = Join-Path $tempDir "nuget"
New-Item -ItemType Directory -Path $env:NUGET_PACKAGES -Force | Out-Null
dotnet nuget list source | Write-Host
Write-Host "::endgroup::"

Write-Host "::group::Create test project"
dotnet new console --aot --name hello-sentry --output . | Write-Host
dotnet add package Sentry --prerelease --source $localPackages | Write-Host
@"
SentrySdk.Init(options =>
{
options.Dsn = "https://[email protected]/42";
options.Debug = true;
});
Console.WriteLine("Hello, Sentry!");
"@ | Set-Content Program.cs
Write-Host "::endgroup::"
}

AfterAll {
if ($tempDir -and (Test-Path $tempDir))
{
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}

It 'Aot' {
dotnet publish -c Release | Write-Host
$LASTEXITCODE | Should -Be 0

$tfm = (Get-ChildItem -Path "bin/Release" -Directory | Select-Object -First 1).Name
$rid = (Get-ChildItem -Path "bin/Release/$tfm" -Directory | Select-Object -First 1).Name
& "bin/Release/$tfm/$rid/publish/hello-sentry" | Write-Host
$LASTEXITCODE | Should -Be 0
}

It 'Container' -Skip:(!$IsLinux -or !(Get-Command docker -ErrorAction SilentlyContinue)) {
dotnet publish -p:EnableSdkContainerSupport=true -t:PublishContainer | Write-Host
$LASTEXITCODE | Should -Be 0

docker run --rm hello-sentry | Write-Host
$LASTEXITCODE | Should -Be 0
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@
Trim="true" />
</ItemGroup>

<!-- Helpful properties copied from Sentry.props -->
<PropertyGroup Condition="'$(TargetFramework)' != ''">
<_SentryTargetFrameworkVersion>$([MSBuild]::GetTargetFrameworkVersion($(TargetFramework)))</_SentryTargetFrameworkVersion>
<_SentryIsNet8OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 8.0))</_SentryIsNet8OrGreater>
<_SentryIsNet9OrGreater>$([MSBuild]::VersionGreaterThanOrEquals($(_SentryTargetFrameworkVersion), 9.0))</_SentryIsNet9OrGreater>
</PropertyGroup>

<PropertyGroup>
<!-- net8.0 or greater -->
<FrameworkSupportsNative Condition="'$(_SentryIsNet8OrGreater)' == 'true' and ('$(OutputType)' == 'Exe' or '$(OutputType)' == 'WinExe')">true</FrameworkSupportsNative>
Expand Down
Loading