Description
Describe the bug
dotnet publish
fails when <PublishAot>
is set to true and <NoWarn>
includes newlines.
To Reproduce
-
Create a new console application
dotnet new console -n AoTNoWarn
-
Update the AoTNoWarn.csproj to match the below, specifically the second property group
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>net7.0</TargetFramework> <ImplicitUsings>enable</ImplicitUsings> <Nullable>enable</Nullable> </PropertyGroup> <PropertyGroup> <PublishAot>true</PublishAot> <!-- These for demonstration purposes. Don't disable the 'Division by constant zero' error. --> <NoWarn> CS0020, CS0021, </NoWarn> </PropertyGroup> </Project>
-
Run
dotnet publish
Exceptions (if any)
The exception I see is
EXEC : error : No files matching CS0021, [/path/to/AoTNoWarn/AoTNoWarn.csproj]
I read this as implying the compiler invocation is being constructed in such a way that <NoWarn>
options after a newline are being read as files to compile, rather than --nowarn
option arguments.
Further discussion
Running dotnet publish --verbosity diag
is helpful for tracking down the source of the issue;
10:21:55.965 1:7>Target "IlcCompile: (TargetId:179)" in file "/home/drew/.dotnet/sdk/7.0.102/Sdks/Microsoft.DotNet.ILCompiler/build/Microsoft.NETCore.Native.targets" from project "/path/to/AoTNoWarn/AoTNoWarn.csproj" (target "LinkNative" depends on it):
Building target "IlcCompile" completely.
Output file "obj/Debug/net7.0/linux-x64/native/AoTNoWarn.o" does not exist.
Task "Message" (TaskId:118)
Task Parameter:Importance=high (TaskId:118)
Task Parameter:Text=Generating native code (TaskId:118)
Generating native code (TaskId:118)
Done executing task "Message". (TaskId:118)
Task "Exec" (TaskId:119)
Task Parameter:Command="/home/drew/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.2/tools/ilc" @"obj/Debug/net7.0/linux-x64/native/AoTNoWarn.ilc.rsp" (TaskId:119)
"/home/drew/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.2/tools/ilc" @"obj/Debug/net7.0/linux-x64/native/AoTNoWarn.ilc.rsp" (TaskId:119)
10:21:56.086 1:7>EXEC : error : No files matching CS0021, [/path/to/AoTNoWarn/AoTNoWarn.csproj]
Looking at the contents of /path/to/AoTNoWarn/obj/Debug/net7.0/linux-x64/native/AoTNoWarn.ilc.rsp, we can see (what I believe to be) the root of the problem:
--scanreflection
--nowarn:"
CS0020,
CS0021,
;IL2121;1701;1702"
--singlewarn
--root:obj/Debug/net7.0/linux-x64/AoTNoWarn.dll
If I remove the whitespace, and replace the --nowarn:
value with "CS0020,CS0021,;IL2121;1701;1702"
(no newlines, no spaces), I'm then able to successfully execute a manual run of /home/drew/.nuget/packages/runtime.linux-x64.microsoft.dotnet.ilcompiler/7.0.2/tools/ilc obj/Debug/net7.0/linux-x64/native/AoTNoWarn.ilc.rsp
.
A Probably-Unrelated Thought
When trying to figure out why my build was failing, I also noticed that when running dotnet publish --no-build
with <PublishAot>true</PublishAot>
in my .csproj file, the --no-build
option was ignored. I assume that is because I'm missing some set of compiler flags in my dotnet build
invocation, but the behavior was surprising and disappointing.
Further technical details
$ dotnet --info
dotnet --info
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: pop
OS Version: 22.04
OS Platform: Linux
RID: linux-x64
Base Path: /home/drew/.dotnet/sdk/7.0.102/
Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb
.NET SDKs installed:
3.1.419 [/home/drew/.dotnet/sdk]
3.1.423 [/home/drew/.dotnet/sdk]
6.0.103 [/home/drew/.dotnet/sdk]
6.0.300 [/home/drew/.dotnet/sdk]
6.0.301 [/home/drew/.dotnet/sdk]
6.0.400 [/home/drew/.dotnet/sdk]
6.0.401 [/home/drew/.dotnet/sdk]
7.0.102 [/home/drew/.dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.25 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.29 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.6 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.8 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.9 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [/home/drew/.dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.25 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.29 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.6 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.8 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.9 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [/home/drew/.dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
DOTNET_ROOT [/home/drew/.dotnet]
global.json file:
Not found