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.71k stars 1.07k forks source link

When Targeting .NET Framework TFM ASP.NET Core Module gets added needlessly to Web.config. #34595

Open AraHaan opened 1 year ago

AraHaan commented 1 year ago

Describe the bug

Let's say for example you have a project that is the following:

Now when you do an in place migration to SDK Style (without changing framework) and carefully made the needed changes to make the project compile (the migration tool sets output to Exe and nukes some important properties so reverting those will fix it) you will notice the following:

Things I had to do after migration:

The diff between the Web.config files (yellow means added from the .NET SDK's Sdk.Web): image

To Reproduce

Exceptions (if any)

No exceptions, just that I expect the publish directory to match for a project with no difference in framework, just the style of csproj (SDK vs non-SDK style for an important reason which is IIS which probably show exceptions when trying to use any of the razor pages (they are all razor pages cshtml files) with it not being able to find roslyn).

Further technical details

Runtime Environment: OS Name: Windows OS Version: 10.0.22631 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\8.0.100-preview.7.23376.3\

.NET workloads installed: There are no installed workloads to display.

Host: Version: 8.0.0-preview.7.23375.6 Architecture: x64 Commit: 65b696cf5e RID: win-x64

.NET SDKs installed: 6.0.413 [C:\Program Files\dotnet\sdk] 7.0.100-rc.2.22477.23 [C:\Program Files\dotnet\sdk] 7.0.110 [C:\Program Files\dotnet\sdk] 8.0.100-preview.7.23376.3 [C:\Program Files\dotnet\sdk]

.NET runtimes installed: Microsoft.AspNetCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0-rc.2.22476.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-rc.2.22472.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 6.0.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.21 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0-rc.2.22472.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 8.0.0-preview.7.23376.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found: x86 [C:\Program Files (x86)\dotnet] registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables: Not set

global.json file: Not found

Learn more: https://aka.ms/dotnet/info

Download .NET: https://aka.ms/dotnet/download


- The IDE: Visual Studio Enterprise 2022 v17.8 Preview 1
AraHaan commented 1 year ago

While this is similar to https://github.com/dotnet/sdk/issues/462, I need the handlers from before the Web.Sdk inserted the additional handler which is rather problematic.

AraHaan commented 1 year ago

Looks like the real problem is the task assembly itself, disabling that entirely does not run transforms for Web.Debug.config and Web.Release.config when needed.

https://github.com/dotnet/sdk/blob/9c2f7f17ca4e9592d7418279ea3079ebc3f573f8/src/WebSdk/Publish/Tasks/WebConfigTransform.cs

AraHaan commented 1 year ago

Hmm to me it looks like all that file is doing is setting up the 2 aspNetCore elements in the xml and then adding them to the web.config before finally adding the project guid at the bottom. Now to find where it would transform Web.Debug.config and Web.Release.config.