Closed jonathanpeppers closed 2 days ago
I don't think dotnet publish --no-build
with NativeAOT has any effect. We always need to execute the build first.
If we take for example targeting iOS with NativeAOT, during the publishing process it's necessary for the SDK to retrieve a different version of the runtime pack (NativeAOT) than what was used for the build (Mono). Retrieving and handling of the runtime packs is part of the Build
phase, which means it cannot be done during Publish
with --no-build
.
My two cents on warnings:
I think that when publishing an app with NativeAOT the duplicated warnings is the expected behaviour.
On the other hand, when building the app with PublishAot=true
the warnings will come from Roslyn analyzers only, as ILC will not run in this scenario, so there will be no duplicates. Finally, the "downside" of dotnet build
with PublishAot=true
is that the user won't see any trim/AOT/singlefile warnings coming from NuGets. For that dotnet publish
is required.
The last bit is probably making the biggest difference between Mono and NativeAOT on mobile, as with Mono we are running the trimmer (getting full program view) even during the build which makes the difference between building and publishing minimal with Mono.
Ok, I found steps that fix this are:
dotnet build -c Release -bl:build.binlog -r win-x64 nativeaotwarnings.csproj
dotnet publish -c Release -r win-x64 --no-build -bl:publish.binlog nativeaotwarnings.csproj
In this case, a build was performed with the RID, and I don't get double warnings. So, you would only get double warnings if build + publish both run.
This is basically what happens on mobile with dotnet build
, as we have to run illink and some subset of the publish targets to get a runnable app.
This is currently by-design for console apps. I don't see a good reason to change it there. If the mobile experience is different, we should address it there.
@agocke can you recommend what we should do?
On Android it seems like we should somehow disable the Roslyn analyzers if a build would run the trimmer, does that sound correct?
We want to see warnings from NuGet packages but not 2x of the project’s source code.
Yeah, I think that might be the best option. You can disable the analyzers with <EnableTrimAnalyzer>false</>
and <EnableAotAnalyzer>false</>
Disabling Roslyn analyzers would prevent our IDEs from showing squiggly lines in places where the code is not trim compatible.
Description
Building a console app with
dotnet publish -c Release -r win-x64 --no-build
, I get double warnings from the Roslyn analyzer and ILC:I would like to address this problem in the Android workload as well, but asking about console apps first. We have some cases on Android that can trigger duplicate warnings.
Reproduction Steps
I attached the repro, but you could do:
dotnet new console
PublishAot=true
in the.csproj
dotnet build -c Release -bl:build.binlog
dotnet restore -r win-x64 -bl:restore.binlog
dotnet publish -c Release -r win-x64 --no-build -bl:publish.binlog
Expected behavior
I should get two warnings:
IL2055
andIL3050
.Actual behavior
I get four warnings:
IL2055
x 2 andIL3050
x 2.Regression?
No
Known Workarounds
No response
Configuration
I assume this probably does the same thing in .NET 9, but I didn't try.
Other information
Here is a repro project: nativeaotwarnings.zip