azureasp.net-coreweb-configvisual-studio-2022

Visual Studio 2022: ASP.NET Core web application and web.config transformations


Platform

IDE

Problem

I have a simple ASP.NET Core 8.0 web application (NOT using MVC or Razor), built using Visual Studio 2022 with C#.

I have two separate web app services running on Azure (Windows/IIS) - one for development and one for production. When publishing the web application to Azure (using Visual Studio), I needed the web.config file to contain different URL rewrite rules for IIS depending on the build configuration, i.e.:

For the Release build:

For the Debug build:

I edited the project file and included the following task to perform web.config transformations:

   <UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
   <Target Name="Web_config_AfterBuild" AfterTargets="AfterBuild" Condition="Exists('web.$(Configuration).config')">
      <Message Importance="high" Text="****&gt; Transforming web.$(Configuration).config to web.config" />
      <TransformXml Source="web.config" Destination="$(OutputPath)web.config" Transform="web.$(Configuration).config" />
   </Target>

Everything works as it should when publishing to Azure.

A snapshot of the web application solution explorer is shown below:

Web app solution explorer

Note that the web.release.config file is NOT stacked below the web.config file as it is in other web site projects in Visual Studio, i.e.: the snapshot below is from a different web site project (also in Visual Studio 2022):

Web site solution explorer

Question

Is this normal behavior for the solution explorer in Visual Studio 2022?

That is, does Visual Studio solution explorer treat an ASP.NET Core web application project differently than a web site project?

For now, it seems to be the case, as I cannot find any way to get the web.{Configuration}.config files to be nested below the web.config file as it does in web site projects.

It is not a big issue, I was just looking for some clarification (or documentation) if this is "normal" behavior for Visual Studio as it seems somewhat confusing (to me) as why some project types stack files and others do not.

Thanks in advance.


Solution

  • The credit goes to @Fen Han who provided the answer in the comments.

    For those looking for the MS documentation that describes Visual Studio file nesting options, the link is: https://learn.microsoft.com/en-us/visualstudio/ide/file-nesting-solution-explorer?view=vs-2022

    Note that the above link deals with file nesting in the IDE only. Transformations regarding web.config still have to be handled depending on the project type.

    Thanks again.