Jun 5, 2014

Posted in , , , ,

ASP.NET 4.5.2 Hosting - HostForLIFE :: Run Your Web Apps with the Web.config

Have you think that you could run your web apps with the Web.config being transformed according to the current solution configuration for Debug or Release directly from your Visual Studio? Now, we are going to try run web apps from web.config from ASP.NET 4.5.2 Hosting.
The trick is you should create a file named Web.Base.config, besides the existing Web.Debug.config and Web.Release.config. This file will be the same to your old Web.config, as it will be the base for the transformation. Then the result files is Web.config, Web.Base.config, Web.Debug.config and Web.Release.config

Then, Add the following config to the bottom of your .csproj file, just before the closing </Project> tag: 
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild">
<TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />

The \v11.0\ part is for Visual Studio 2012. If you're using VS 2010 you change this to \v10.0\.

Now you can build and run your project or publish it all depending on what Solution Configuration you have selected. Debug or Release. Just press your CTRL+SHIFT+B and see the Web.config-file be transformed.

I recommend that you leave Web.config out of your Version Control. This solution for transforming the Web.config on the fly would mean that this specific file would constantly be modified and if one person is working with Debug and another person is working with Release the Web.config would probably get big changes constantly. 


Post a Comment

thanks for your comment!