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

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

Open
ighristov opened this issue Mar 1, 2025 · 7 comments
Open

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

ighristov opened this issue Mar 1, 2025 · 7 comments
Labels
Area-Compilers untriaged Request triage from a team member

Comments

@ighristov
Copy link

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.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Request triage from a team member labels Mar 1, 2025
@jaredpar jaredpar transferred this issue from dotnet/roslyn Mar 3, 2025
@baronfel
Copy link
Member

baronfel commented Mar 3, 2025

I think this is a duplicate of #43908

@alexbereznikov
Copy link

Don't think it is a duplicate, we use NET6_0_OR_GREATER and builds started to fail a few days ago on Azure (seems when they updated sdk) and locally after VS update. That issue was opened much earlier. I checked defines in msbuild log and can confirm OP observations.

@baronfel
Copy link
Member

baronfel commented Mar 4, 2025

@alexbereznikov did your binlog also say you were using .NET SDK 9.0.200 or higher? And you are also using WFP? If so, I do think it is a duplicate. The timing of the issue is not really relevant here - it was logged against the SDK while we were still working on making 9.0.200 - the only reason it hit you just now is because of the rate of update of the AzDo runners - if they updated with nightlies or previews I suspect you would have seen this much sooner.

@alexbereznikov
Copy link

@baronfel Yes the issue seems to be related. Although I see PR #44938 is included in release 9.0.200, to me it looks like it should have been fixed in this release

Image

@alexbereznikov
Copy link

I inspected binlog again and yes, the issue is very similar to #43908 but task name is different - GenerateTemporaryTargetAssembly (for WPF). AddImplicitDefineConstants does not manage to run at all for the failing project.

@alexbereznikov
Copy link

alexbereznikov commented Mar 5, 2025

So, I added this to Directory.Build.targets (essentially reverting #43908 fix)

<Target Name="AddImplicitDefineConstants_Temp"
        Condition=" '$(DisableImplicitFrameworkDefines)' != 'true' "
        DependsOnTargets="GenerateTargetPlatformDefineConstants;GenerateNETCompatibleDefineConstants;GeneratePlatformCompatibleDefineConstants;_DisableDiagnosticTracing"
        BeforeTargets="CoreCompile" >
  <PropertyGroup>
    <DefineConstants Condition=" '@(_ImplicitDefineConstant)' != '' " >$(DefineConstants);@(_ImplicitDefineConstant)</DefineConstants>
    <FinalDefineConstants Condition=" '@(_ImplicitDefineConstant)' != '' and '$(Language)' == 'VB' " >$(FinalDefineConstants),@(_ImplicitDefineConstant->'%(Identity)=-1', ',')</FinalDefineConstants>
  </PropertyGroup>
</Target>

And it started to compile again. My opinion - that change led to this regression.

For me it reproduces with msbuild as well

@baronfel
Copy link
Member

baronfel commented Mar 5, 2025

Cc @Sergio0694

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

3 participants