Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVCRT build warning when building Windows App SDK (WinUI) release binaries with native AOT #3928

Open
kirwan-safesurfer opened this issue Feb 1, 2025 · 4 comments

Comments

@kirwan-safesurfer
Copy link

kirwan-safesurfer commented Feb 1, 2025

Package

Sentry

.NET Flavor

.NET

.NET Version

8.0.12

OS

Windows

SDK Version

5.0.1

Self-Hosted Sentry Version

No response

Steps to Reproduce

(Please find a minimal project attached below.)

  1. In Visual Studio 2022, create a Blank App, Packaged (WinUI 3 in Desktop), and add Sentry 5.0.1 as a NuGet package. Set the project to Release mode and apply Native AoT (right-click project > Properties > Build > Publish > enable Publish native AOT).
  2. Add the WinUI (with trimming) code to the project.
  3. Package the project (right-click project > Package and publish > Create App Packages, and create a Release x64 MSIX binary).

During the Release build, after mentioning Generating native code, the build log will output the following warning: LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

I was able to discover this by using PowerShell:

cd "C:\Users\User\source\repos\Project\src\Project"

Get-ChildItem -Recurse | Select-String "msvcrt" -List | Select Path | Format-List *

Path : C:\Users\User\source\repos\Project\src\Project\bin\ARM64\Release\net8.0-windows10.0.26100.0\win-arm64\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\Release\net8.0-windows10.0.26100.0\win-arm64\publish\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\Release\net8.0-windows10.0.26100.0\win-x64\publish\project.exe

Path : C:\Users\User\source\repos\Project\src\Project\bin\Release\net8.0-windows10.0.26100.0\win-x64\publish\project.pdb

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Debug\net8.0-windows10.0.26100.0\win-x64\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Debug\net8.0-windows10.0.26100.0\win-x64\AppX\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Release\net8.0-windows10.0.26100.0\win-x64\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Release\net8.0-windows10.0.26100.0\win-x64\AppX\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Release\net8.0-windows10.0.26100.0\win-x64\native\project.exe

Path : C:\Users\User\source\repos\Project\src\Project\bin\x64\Release\net8.0-windows10.0.26100.0\win-x64\native\project.pdb

Path : C:\Users\User\source\repos\Project\src\Project\obj\ARM64\Release\net8.0-windows10.0.26100.0\win-arm64\linked\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\obj\ARM64\Release\net8.0-windows10.0.26100.0\win-arm64\R2R\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\obj\x64\Release\net8.0-windows10.0.26100.0\win-x64\linked\Sentry.dll

Path : C:\Users\User\source\repos\Project\src\Project\obj\x64\Release\net8.0-windows10.0.26100.0\win-x64\native\project.obj

Path : C:\Users\User\source\repos\Project\src\Project\obj\x64\Release\net8.0-windows10.0.26100.0\win-x64\R2R\Sentry.dll

Expected Result

No warning should appear in the build log.

Actual Result

LINK : warning LNK4098: defaultlib 'MSVCRT' conflicts with use of other libs; use /NODEFAULTLIB:library

Minimal project (SentryAotTest.zip)

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 1, 2025
@kirwan-safesurfer kirwan-safesurfer changed the title MSVCRT build warning when building Windows App SDK (WinUI) release binaries MSVCRT build warning when building Windows App SDK (WinUI) release binaries with native AOT Feb 1, 2025
@bruno-garcia
Copy link
Member

bruno-garcia commented Feb 3, 2025

Does WinUI support Native AOT? My understanding is that WinUI has its own AOT.
This is odd because Sentry itself supports Native AOT (on .NET apps).

If you remove Sentry, does it compile and run normally?

@kirwan-safesurfer
Copy link
Author

Yes, WinUI 3 is bundled with the Windows App SDK, where Windows App SDK 1.6 has full support for Native AOT (as per the minimal project ZIP at the bottom of the report).

Yep, when Sentry is removed, the warning disappears—the warning is specifically caused by placing the WinUI (with trimming) code inside the App.xaml.cs file, as per the minimal project. The issue seems to be that Sentry references MSVCRT, whereas I believe UCRT is now used elsewhere as the default C library: https://stackoverflow.com/a/68609918/29290956

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Feb 4, 2025
@jamescrosswell
Copy link
Collaborator

jamescrosswell commented Feb 4, 2025

Tricky... I'm wondering where the reference to MSVCRT comes from. The sentry-dotnet sdk doesn't have any dependencies for net8.0 or net9.0.

It might be coming from the Sentry Native SDK (which we bundle/wrap for AOT compiled apps). The only explicit reference I can find to it there seems to be XBox specific though. Perhaps it's referenced implicitly somehow though.

@vaind any ideas?

@vaind
Copy link
Collaborator

vaind commented Feb 4, 2025

Yes, this could be some part of the native SDK or it could be our native binding code:

[DllImport("msvcrt", EntryPoint = "vsnprintf")]
private static extern int vsnprintf_windows(IntPtr buffer, UIntPtr bufferSize, IntPtr format, IntPtr args);

I don't believe we've explicitly tested the WinUI+nativeAOT combination so that would be the first step, then we'd see what needs to be adapted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Status: No status
Development

No branches or pull requests

4 participants