1

Platform

  • Windows
  • ASP.NET Core 8.0

IDE

  • Microsoft Visual Studio Community 2022
  • Version 17.13.2
  • VisualStudio.17.Release/17.13.2+35825.156
  • Windows 10

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:

  • web.release.config would be transformed to web.config and then published to the Azure production app service.

For the Debug build:

  • web.config would be published to the development app service.

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.

14
  • please specify your .net core version. Commented Mar 6 at 11:54
  • ASP.Net Core 8.0 (updated question as well). Commented Mar 6 at 13:35
  • In my ASP.NET Core 8 app, the web.config file and web.Release.config file are nested.See this. Commented Mar 6 at 14:38
  • @Aslesha Kantamsetti - Thanks - my project does NOT make use of MVC. As the image shows in my original post, the web.config and web.Release.config files are NOT nested -- I am trying to understand why some projects nest and others do not - there MUST be some project setting that causes this behavior. Commented Mar 6 at 15:31
  • AFAIK, this is the normal behavior. To avoid such issues you can use SlowCheetah extension Doc 1 and 2 to transform config files. For me the files are stacked correctly. Commented Mar 15 at 11:40

2 Answers 2

0

I am able to see the web.config files stacked correctly for my Web App.

enter image description here

Instead of adding the Release and Debug files manually, you can use Slowcheetah extension to transform the config file.

In VS, navigate to Extensions => Manage Extensions and search for SlowCheetah and install it by closing the Visual Studio.

enter image description here

enter image description here

Check the below workaround to transform and stack the config files correctly.

  • Unable to find the Add Transform option directly on web.config file.

  • As a workaround, Initially add a file with name web1.config, right click on the newly created file. You can see the option Add Tranform.

enter image description here

  • Select Add Transform option and click on Yes.

enter image description here

  • .csproj file will be updated with the below setting.
  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.SlowCheetah" Version="4.0.50">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

two new files will be generated.

enter image description here

  • Now rename the web1.config file to web.config; you'll notice that both file names have changed.

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.