Skip to content

Regression in dotnet publish using .NET 9 SDK 9.0.200 #47227

Closed
@ighristov

Description

@ighristov

Version Used:
9.0.200

Steps to Reproduce:

  1. Install SDK 9.0.200.
  2. Open and extract attached TestApp.zip
  3. Execute the following command in the extract folder:
dotnet publish TestApp.csproj -p:DebugSymbols=false -f net8.0-windows -c Release -r win-x64 --force -v n

Expected Behavior:
Project is compiled successfully.

Actual Behavior:
Compilation fails because the directive #if NET6_0_OR_GREATER present in Program.cs file is not respected.

  1. Uninstall SDK 9.0.200 and install 9.0.103. Repeat the same steps. The publish command will pass successfully.

TestApp.zip

Description:
Seems the logic that adds the /define constants during build process has changed. Please inspect both log files I've attached, produced when compiling the same TestApp using SDKs 9.0.103 and 9.0.200. Inspect line 48 in both files.
In 9.0.103 the /define constants looks correct:

         C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\9.0.103\Roslyn\bincore\csc.dll" /noconfig /unsafe- /checked- /nowarn:1701,1702,1701,1702 /fullpaths /nostdlib+ /platform:x64 /errorreport:prompt /warn:8 /define:TRACE;RELEASE;NET;NET8_0;NETCOREAPP;WINDOWS;WINDOWS7_0;NET5_0_OR_GREATER;NET6_0_OR_GREATER;NET7_0_OR_GREATER;NET8_0_OR_GREATER;NETCOREAPP3_0_OR_GREATER;NETCOREAPP3_1_OR_GREATER;WINDOWS7_0_OR_GREATER /highentropyva+ 

while in 9.0.200 the produced set with the constants is way shorter:

         C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\9.0.200\Roslyn\bincore\csc.dll" /noconfig /unsafe- /checked- /nowarn:1701,1702,1701,1702 /fullpaths /nostdlib+ /platform:x64 /errorreport:prompt /warn:8 /define:TRACE;RELEASE;NET;NET8_0;NETCOREAPP /highentropyva+ 

Since that the constant NET6_0_OR_GREATER is not included in the CoreCompile step, the build fails, because in my test app I use it to include/exclude a non-compilable line "DoNotCompile" (Program.cs, line 10).
Not sure why, but this behavior is reproducible when I have a .xaml file and it contains a namespace to the current project (see View.xaml, line 3).
If you remove line 3 in View.xaml, the compilation will work fine with SDK 9.0.200.

The issue is not reproducible with dotnet build or msbuild commands.

Hope it will be fixed soon.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions