4

I am using web.config transforms in Visual Studio 2010.

I have added transforms by right clicking on the web.config file and selected option called Add Config Transforms. By this i have added few config files to my solution. After publishing my project through VS2010 my web.config is updated with selected config file (like web.dev.config).

My Question is:

Can i update my web.config file with the selected config file(like web.dev.config) while building(or After Building).

Thanks, Mahi

Mahi Kumar
  • 171
  • 1
  • 11

2 Answers2

2

I agree to Pablo's comments.You shouldn't be overwriting the web.config.

If needed, you can get all the files transformed at compile time.

Here is how to do it. Edit the project file (.csproj) and add the below code. Make sure that the path are correct.

<Target Name="AfterBuild">
    <TransformXml Source="$(SolutionDir)WCFServices\Web.config" 
                  Transform="$(SolutionDir)WCFServices\Web.Release.config" 
                  Destination="$(OutDir)WebRelease.config" 
                  StackTrace="true" />
</Target>
Charls
  • 319
  • 1
  • 9
  • 1
    Thanks for your answer. However that would be great if you had explained where to add that code in .csproj – curiousBoy Nov 21 '13 at 20:38
1

Well, actually one of the purposes of config transforms was that the original .config remained unchanged (I will try to locate the MS documentation that mentioned this).

The default web.config should in fact be your DEV configuration, for it to work in your environment as well as when deployed.

And to me it actually seems a bit safer to leave the config file unchanged, because if not, you'd start having issues when working with source control, such as TFS or SVN. You probably want to stay away from build processes that alter the code-base you check-in on a daily basis.

Pablo Romeo
  • 11,298
  • 2
  • 30
  • 58