I have a Visual Studio application that has multiple Solution Configurations. There is a Web.config transform file for each configuration. For example, Web.Debug.config, Web.Release.config, etc.
We also have a couple of developers working on this project that have nonstandard SQL Express instance names due to the way they installed SQL Express and rather than having them continually editing Web.Debug.config to run in their environment I have setup a Solution Configuration for each of them and added the following to the very bottom of the .csproj file. This code does work in that it triggers the creation of Web.config and MyWebApp.dll.config in the VS /obj/Debug-DeveloperName/ folder.
The transformed .config files are perfect, but IIS Express still uses the root Web.config (not transformed).
Is there a way to get IIS Express to use these transformed Web.config files while debugging locally?
<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 application's Web.Debug.Config works for most of us, but not all.
There must be a way of getting IIS Express to use the transformed Web.Debug-DeveloperName.config during local debug?
Does the transformed Web.config have to be copied into a different folder?
I faced this problem before and I found a solution. Unfortunately, the solution is not based on forcing IIS to use different name of the config, but if you follow steps below, you will just select the configuration and run you app (which is ewhat you need I think). The Web.config transform will occur before build and it will replace the original Web.config by the transformad one. Then, when the deployment (to local IIS Express) begins, it will already use the transformed one.
Here is step by step how I did this in one project (VS2012):
<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>
The condition there is to prevent duplicate transformation when publishing.
Now, everytime you run a build, your Web.config will be transformed according to selected configuration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With