dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.66k stars 1.06k forks source link

Self-contained publish regression in .NET 9 RC1 #43461

Closed nil4 closed 9 hours ago

nil4 commented 3 days ago

Describe the bug

A WPF project using DevExpress components, WCF and a handful of third-party NuGet packages can be published self-contained correctly when targeting net8.0-windows. All relevant .dll files are present in the published output, and the application runs as expected.

When the project is re-targeted to net9.0-windows, the self-contained publish output no longer includes certain WPF assemblies (e.g. PresentationCore.dll or PresentationFramework*.dll) The published application now crashes at startup because it cannot find these WPF assemblies.

The steps provided below are a minimal reproducible example extracted from the actual application.

To Reproduce

Note: an active subscription for access to the DevExpress NuGet package source https://nuget.devexpress.com/${YOUR_SUBSCRIPTION_KEY_HERE}/api/v3/index.json will be required.

Download the script at https://gist.github.com/nil4/9f6c787205340b8b45a7cfe504ba7400 and on line 8, replace the placeholder value with a DevExpress subscription key.

Running the script (pwsh repro.ps1) will:

The script creates two projects, first targeting net8.0 and then net9.0. The publish output for net8.0 consistently includes the WPF assemblies.

The publish output for net9.0, once the final NuGet package reference is added, no longer includes the expected WPF assemblies.

This appears to be a regression, and an unexpected breaking change in .NET 9.0 RC1.

net8.0 publishing correctly

Testing net8.0 repro under C:\repro\repro_8
Creating new net8.0 WPF project in C:\repro\repro_8
Disabling <ImplicitUsings> in C:\repro\repro_8\repro_8.csproj

Adding package DevExpress.Mvvm 24.1.5 in C:\repro\repro_8
Adding package DevExpress.Win.Navigation 24.1.5 in C:\repro\repro_8
Adding package DevExpress.Win.Grid 24.1.5 in C:\repro\repro_8
Adding package System.ServiceModel.Http 8.0.0 in C:\repro\repro_8
Adding package System.ServiceModel.Primitives 8.0.0 in C:\repro\repro_8
Adding package System.Drawing.Common 8.0.8 in C:\repro\repro_8
Adding package System.Formats.Asn1 8.0.1 in C:\repro\repro_8
Publishing C:\repro\repro_8 to C:\repro\repro_8\bin\publish
✅ Found 15 files matching C:\repro\repro_8\bin\publish\Presentation*.dll

Adding package Tulpep.ActiveDirectoryObjectPicker 3.0.11 in C:\repro\repro_8
Publishing C:\repro\repro_8 to C:\repro\repro_8\bin\publish
✅ Found 15 files matching C:\repro\repro_8\bin\publish\Presentation*.dll

net9.0 missing expected output

Testing net9.0 repro under C:\repro\repro_9
Creating new net9.0 WPF project in C:\repro\repro_9
Disabling <ImplicitUsings> in C:\repro\repro_9\repro_9.csproj

Adding package DevExpress.Mvvm 24.1.5 in C:\repro\repro_9
Adding package DevExpress.Win.Navigation 24.1.5 in C:\repro\repro_9
Adding package DevExpress.Win.Grid 24.1.5 in C:\repro\repro_9
Adding package System.ServiceModel.Http 8.0.0 in C:\repro\repro_9
Adding package System.ServiceModel.Primitives 8.0.0 in C:\repro\repro_9
Adding package System.Drawing.Common 9.0.0-rc.1.24451.1 in C:\repro\repro_9
Adding package System.Formats.Asn1 9.0.0-rc.1.24431.7 in C:\repro\repro_9
Publishing C:\repro\repro_9 to C:\repro\repro_9\bin\publish
✅ Found 16 files matching C:\repro\repro_9\bin\publish\Presentation*.dll

Adding package Tulpep.ActiveDirectoryObjectPicker 3.0.11 in C:\repro\repro_9
Publishing C:\repro\repro_9 to C:\repro\repro_9\bin\publish
⛔ Found NO files matching C:\repro\repro_9\bin\publish\Presentation*.dll

Further technical details

dotnet --info ``` .NET SDK: Version: 9.0.100-rc.1.24452.12 Commit: 81a714c6d3 Workload version: 9.0.100-manifests.a7bf2b8f MSBuild version: 17.12.0-preview-24422-09+d17ec720d Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win-arm64 Base Path: C:\Program Files\dotnet\sdk\9.0.100-rc.1.24452.12\ Host: Version: 9.0.0-rc.1.24431.7 Architecture: arm64 Commit: static .NET SDKs installed: 8.0.400 [C:\Program Files\dotnet\sdk] 9.0.100-rc.1.24452.12 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 9.0.0-rc.1.24431.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 8.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 9.0.0-rc.1.24452.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x64 [C:\Program Files\dotnet\x64] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation] x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation] Environment variables: Not set global.json file: Not found ```

The repro script for reference:

repro.ps1 ```pwsh #Requires -PSEdition Core -Version 7.4 Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $PSNativeCommandUseErrorActionPreference = $true $PSStyle.OutputRendering = 'ANSI' # Configure a DevExpress subscription/API key here $DX_SUBSCRIPTION = '!!!! Add-DevExpress-Subscription-Key-Here !!!!' $DX_NUGET_API = "https://nuget.devexpress.com/${DX_SUBSCRIPTION}/api/v3/index.json" $NUGET_API = 'https://api.nuget.org/v3/index.json' function add_package([string]$package, [string]$version, [string]$sourceUrl) { Write-Host "Adding package ${package} ${version} in ${PWD}" -ForegroundColor Cyan & dotnet.exe add package $package --version $version --no-restore --source $sourceUrl } function remove_dir([string]$dir) { if (Test-Path $dir -PathType Container) { Remove-Item $dir -Force -Recurse } } function publish_and_test([string]$publishDir) { Write-Host "Publishing ${PWD} to ${publishDir}" -ForegroundColor Cyan remove_dir $publishDir & dotnet.exe publish --self-contained --runtime win-x64 --output $publishDir --nologo $expectedFiles = Get-Item "${publishDir}\Presentation*.dll" $count = ($expectedFiles | Measure-Object).Count if ($count -gt 0) { Write-Host "✅ Found ${count} files matching ${publishDir}\Presentation*.dll" -ForegroundColor Green } else { Write-Host "⛔ Found NO files matching ${publishDir}\Presentation*.dll" -ForegroundColor Red } } function repro_with_dotnet([int]$dotnetVersion) { $name = "repro_${dotnetVersion}" $reproDir = "$PSScriptRoot\${name}" $fx = "net${dotnetVersion}.0" Write-Host "Testing ${fx} repro under ${reproDir}" -ForegroundColor Cyan Write-Host "Creating new ${fx} WPF project in ${reproDir}" -ForegroundColor Cyan remove_dir $reproDir & dotnet.exe new wpf --framework $fx --output $reproDir # disable implicit usings -- prevents `Application` in App.xaml.cs being ambiguous between WPF and WinForms Write-Host "Disabling in ${reproDir}\${name}.csproj" -ForegroundColor Cyan [string]$csprojContent = Get-Content "${reproDir}\${name}.csproj" -Raw -Encoding utf8 $csprojContent = $csprojContent.Replace('enable<', 'disable<') Set-Content "${reproDir}\${name}.csproj" $csprojContent -Encoding utf8 Push-Location $reproDir try { add_package 'DevExpress.Mvvm' '24.1.5' $DX_NUGET_API add_package 'DevExpress.Win.Navigation' '24.1.5' $DX_NUGET_API add_package 'DevExpress.Win.Grid' '24.1.5' $DX_NUGET_API add_package 'System.ServiceModel.Http' '8.0.0' $NUGET_API add_package 'System.ServiceModel.Primitives' '8.0.0' $NUGET_API if ($dotnetVersion -eq 9) { add_package 'System.Drawing.Common' '9.0.0-rc.1.24451.1' $NUGET_API add_package 'System.Formats.Asn1' '9.0.0-rc.1.24431.7' $NUGET_API } else { add_package 'System.Drawing.Common' '8.0.8' $NUGET_API add_package 'System.Formats.Asn1' '8.0.1' $NUGET_API } publish_and_test "${reproDir}\bin\publish" # NOTE: adding this package breaks publishing on .NET 9.0 RC1 add_package 'Tulpep.ActiveDirectoryObjectPicker' '3.0.11' $NUGET_API publish_and_test "${reproDir}\bin\publish" } finally { Pop-Location } } repro_with_dotnet 8 repro_with_dotnet 9 ```
baronfel commented 3 days ago

Cc @dotnet/dotnet-wpf for triage

nil4 commented 3 days ago

@baronfel appreciate the quick turn-around time!

I updated the script to also check WinForms rather than WPF projects, and the exact same issue reproduces there as well. Here is the diff for reference:

diff --git a/repro.ps1 b/repro.ps1
index f52981b..441c750 100644
--- a/repro.ps1
+++ b/repro.ps1
@@ -42,18 +42,11 @@ function repro_with_dotnet([int]$dotnetVersion) {
     $fx = "net${dotnetVersion}.0"

     Write-Host "Testing ${fx} repro under ${reproDir}" -ForegroundColor Cyan
-    Write-Host "Creating new ${fx} WPF project in ${reproDir}" -ForegroundColor Cyan
+    Write-Host "Creating new ${fx} WinForms project in ${reproDir}" -ForegroundColor Cyan

     remove_dir $reproDir
-    & dotnet.exe new wpf --framework $fx --output $reproDir
+    & dotnet.exe new winforms --framework $fx --output $reproDir

-    # disable implicit usings -- prevents `Application` in App.xaml.cs being ambiguous between WPF and WinForms
-    Write-Host "Disabling <ImplicitUsings> in ${reproDir}\${name}.csproj" -ForegroundColor Cyan
-    
-    [string]$csprojContent = Get-Content "${reproDir}\${name}.csproj" -Raw -Encoding utf8
-    $csprojContent = $csprojContent.Replace('<ImplicitUsings>enable<', '<ImplicitUsings>disable<')
-    Set-Content "${reproDir}\${name}.csproj" $csprojContent -Encoding utf8
-    
     Push-Location $reproDir
     try {
         add_package 'DevExpress.Mvvm'                 '24.1.5'  $DX_NUGET_API

I will update the title to not suggest that this is WPF-specific (or WPF-only.)

dotnet-policy-service[bot] commented 3 days ago

Thanks for creating this issue! We believe this issue is related to NuGet tooling, which is maintained by the NuGet team. Thus, we closed this one and encourage you to raise this issue in the NuGet repository instead. Don’t forget to check out NuGet’s contributing guide before submitting an issue!

If you believe this issue was closed out of error, please comment to let us know.

Happy Coding!

nil4 commented 3 days ago

The regression observed is about assemblies missing in the output of dotnet publish using .NET 9.0 RC1. If it is believed that this is about NuGet packages, it would be helpful to add some more details before closing the issue or redirecting to another repo.

Hence I believe this issue was closed in error, and kindly request it be re-opened and triaged. Thank you in advance!

baronfel commented 3 days ago

Yes, the auto-tagging is somewhat generous in what it considers a NuGet issue. I'll remove that tag and reopen.

baronfel commented 3 days ago

We don't have a 'WPF' or 'Windows' area path (cc @marcpopMSFT should we?) so I've tagged it Area-NetSDK for now until we find the proper owner.

singhashish-wpf commented 2 days ago

@nil4 could you please share a placeholder subscription for devexpress over my email, so that i can repro and check this? I tried to repro this without the devexpress references and couldn't repro.

nil4 commented 2 days ago

@singhashish-wpf thank you for taking a look at this puzzling issue! Indeed, with just the DevExpress packages referenced, or just the Tulpep package referenced, publishing works on .NET 9. Only when they both are present does the issue occur.

I am checking with the account owner if sharing the subscription details is possible, but I expect this will take a while to review and clear.

Perhaps the https://www.devexpress.com/Products/Try/ option might be helpful in the meanwhile? I think requesting a trial might grant temporary access to the NuGet feed relevant for repro:

NuGet Feed (for all .NET products/libraries)

If you'd like to install our 30-day trial using a NuGet feed, simply click the button to the right. With a NuGet feed, you can receive automatic package updates, and can optimize build/test processes via CI/CD tools approved within your enterprise.

pchaurasia14 commented 2 days ago

cc: @merriemcgaw

nil4 commented 2 days ago

@singhashish-wpf here is a simpler way to repro: download the Unified Component Installer from https://www.devexpress.com/Products/Try/ and select Winforms and WPF components to be installed.

This downloads and places the NuGet packages relevant to the repro under C:\Program Files\DevExpress 24.1\Components\System\Components\packages

Update the repro script to use that directory as its NuGet source:

diff --git a/repro.ps1 b/repro.ps1
index f52981b..debfe10 100644
--- a/repro.ps1
+++ b/repro.ps1
@@ -4,10 +4,7 @@ $ErrorActionPreference = 'Stop'
 $PSNativeCommandUseErrorActionPreference = $true
 $PSStyle.OutputRendering = 'ANSI'

-# Configure a DevExpress subscription/API key here
-$DX_SUBSCRIPTION = '!!!! Add-DevExpress-Subscription-Key-Here !!!!'
-
-$DX_NUGET_API = "https://nuget.devexpress.com/${DX_SUBSCRIPTION}/api/v3/index.json"
+$DX_NUGET_API = 'C:\Program Files\DevExpress 24.1\Components\System\Components\packages'
 $NUGET_API = 'https://api.nuget.org/v3/index.json'

 function add_package([string]$package, [string]$version, [string]$sourceUrl) {

On my machine, using these local packages still reproduces the issue as originally reported. I hope this helps.

marcpopMSFT commented 2 days ago

We don't have a 'WPF' or 'Windows' area path (cc @marcpopMSFT should we?) so I've tagged it Area-NetSDK for now until we find the proper owner.

@baronfel I believe most WD issues get moved out of the repo so we've never had a need for the area label. Is this one going to need a fix in the SDK repo?

baronfel commented 2 days ago

I'm not sure - it's unclear if the problem is something in publish we've done, or something in the framework/sdk packages that are being used here. Looks like the WD team is on it though (thanks folks!)

singhashish-wpf commented 1 day ago

binlogs.zip

@baronfel @rainersigwald I have uploaded binlogs for your reference for both NET9(fail) and NET8(pass).

nil4 commented 1 day ago

Good see that the issue is repeatable at your end -- thanks @singhashish-wpf

dsplaisted commented 9 hours ago

This should be fixed in .NET 9 RC2.

I think adding this to the project file should workaround the issue:

<ItemGroup>
  <FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
  <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
</ItemGroup>
nil4 commented 7 hours ago

Much appreciated, @dsplaisted -- thank you!