Using Converted Web.config with IIS Express During Debugging

I have a Visual Studio application that has several solution configurations. There is a Web.config conversion file for each configuration. For example, Web.Debug.config, Web.Release.config, etc.

We also have several developers working on this project who have non-standard SQL Express instance names because of how they installed SQL Express, and instead of constantly editing Web.Debug.config to run in their environment. I have a solution configuration setting for each of them and added the following to the very bottom of the .csproj file. This code works in that it starts creating Web.config and MyWebApp.dll.config in the VS / obj / Debug-DeveloperName / folder.

The converted .config files are ideal, but IIS Express still uses the root Web.config (not converted).

Is there a way to force IIS Express to use these converted Web.config files for local debugging?

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" /> <Target Name="AfterCompile" Condition="exists('Web.$(Configuration).config')"> <!-- Generate transformed config in intermediate directory --> <TransformXml Source="Web.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="Web.$(Configuration).config" /> </Target> 

Using the Web.Debug.Config web application works for most of us, but not for everyone.

Should there be a way to force IIS Express to use the converted Web.Debug-DeveloperName.config during local debugging?

Do I need to copy the converted Web.config file to another folder?

+5
source share
1 answer

I ran into this problem before and I found a solution. Unfortunately, the solution is not based on forcing IIS to use a different configuration name, but if you follow the steps below, you just select the configuration and run the application (which you think you think). The Web.config conversion will occur before the build, and it will replace the original Web.config file with the converted one. Then, when the deployment begins (before the local IIS Express), it will already use the converted one.

Here is a step by step, as I did in one project (VS2012):

  • Right-click on the project and select "Unload"
  • Right-click on it again and select "Edit."
  • Go to the bottom of the file and add follwing to the right above the "" tag (this will be the last element)
 <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" /> <Target Name="BeforeBuild" Condition="'$(PublishProfileName)' == '' And '$(WebPublishProfileFile)' == ''"> <TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="Web.config" /> </Target> 

A condition to prevent duplication in publishing.

  1. Save the file, right-click on it and select "Update"

Now, every time you run the build, your Web.config will be converted according to your chosen configuration.

+8
source

Source: https://habr.com/ru/post/1215514/


All Articles