sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Regression in dotnet publish using .NET 9 SDK 9.0.200

Open ighristov opened this issue 1 year ago • 17 comments

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.

ighristov avatar Mar 01 '25 23:03 ighristov

I think this is a duplicate of https://github.com/dotnet/sdk/issues/43908

baronfel avatar Mar 03 '25 20:03 baronfel

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.

alexbereznikov avatar Mar 04 '25 14:03 alexbereznikov

@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.

baronfel avatar Mar 04 '25 15:03 baronfel

@baronfel Yes the issue seems to be related. Although I see PR https://github.com/dotnet/sdk/pull/44938 is included in release 9.0.200, to me it looks like it should have been fixed in this release

Image

alexbereznikov avatar Mar 05 '25 07:03 alexbereznikov

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 avatar Mar 05 '25 08:03 alexbereznikov

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

alexbereznikov avatar Mar 05 '25 08:03 alexbereznikov

Cc @Sergio0694

baronfel avatar Mar 05 '25 12:03 baronfel

@Sergio0694 any updates on the underlying issue?

marcpopMSFT avatar Mar 11 '25 20:03 marcpopMSFT

Sorry for the delay. My understanding is that that initial fix attempt didn't actually address the issue, as it didn't move the XAML precompile target early enough. That said, it's not entirely clear to me why that change would've broken this, would need to take a look at the binlog. I also know @teo-tsirpanis made https://github.com/dotnet/sdk/pull/45877 with a proper fix for the original issue. I wonder if that would also address this? Either way, we should make sure that that change both fixes the original issue and avoids this regression. Teo, would you be able to help check this with your changes? 🙂

Sergio0694 avatar Mar 11 '25 20:03 Sergio0694

Triage: @Sergio0694 so is merging the linked issue enough? Should we consider backporting to 9.0.300 (200 is now in approval mode and I'm not clear if this meets the bar).

marcpopMSFT avatar Mar 18 '25 20:03 marcpopMSFT

It's not clear to me whether that fix would also fully address this regression. The point of that fix was mainly to actually address the issue with the XAML compile target in UWP/WinUI scenarios. We should verify if it also fixes this issue.

@teo-tsirpanis would you be able to check? Otherwise I could try with the repro in this issue.

Sergio0694 avatar Mar 18 '25 20:03 Sergio0694

Unfortunately I don't have time to verify.

teo-tsirpanis avatar Mar 18 '25 20:03 teo-tsirpanis

Alright I'll try to find some time to test this then, no worries 🙂

@marcpopMSFT what's the simplest way to test this? Do I just patch the .targets from #45877 locally in my installed SDK?

Sergio0694 avatar Mar 18 '25 20:03 Sergio0694

Yes, what I have done is download an SDK tarball and patch that, instead of messing with my installation.

teo-tsirpanis avatar Mar 18 '25 20:03 teo-tsirpanis

Alright I tried this out in a bunch of configurations. Here's what I get:

Branch Build Project Result
main VS UWP .NET 9 Fails ❌
main VS WPF Succeeds ✅
main PS (build) UWP .NET 9 Fails ❌
main PS (publish) UWP .NET 9 Fails ❌
main PS (build) WPF Succeeds ✅
main PS (publish) WPF Succeeds ✅
PR VS UWP .NET 9 Succeeds ✅
PR VS WPF Succeeds ✅
PR PS (build) UWP .NET 9 Succeeds ✅
PR PS (publish) UWP .NET 9 Succeeds ✅
PR PS (build) WPF Succeeds ✅
PR PS (publish) WPF Succeeds ✅

Configuration:

  • .NET SDK 9.0.300-preview.0.25169.3
  • VS 17.13.4 (with preview .NET SDK enabled)

@marcpopMSFT basically TLDR I couldn't repro the issue reported here, but I can confirm that with the change in #45877 I can correctly build/publish a UWP .NET 9 project both from VS and from CLI. If possible, I'd suggest merging the PR that @teo-tsirpanis made and backporting it to 9.0.300 if possible? That would finally fix the build error on UWP, and hopefully the one on WPF too.

Sergio0694 avatar Mar 20 '25 02:03 Sergio0694

Thanks for taking a look, @Sergio0694 . We've gotten a lot of customer reports of issues in 9.0.200 with WPF publishing so hopefully 45877 helps with that. I merged the other change and ported it to 9.0.3xx as well which is open for another two weeks.

It's probably not worth a fix in 2xx as we're too late for April and 300 releases in May (and 2xx goes out of support in May).

marcpopMSFT avatar Mar 22 '25 00:03 marcpopMSFT

This should be closeable now, given what @marcpopMSFT said above. 9.0.200 also goes out of support in May.

nagilson avatar Mar 25 '25 20:03 nagilson