开发者

When do Web.Config transformations in VS2010 fire?

开发者 https://www.devze.com 2023-03-18 06:28 出处:网络
Our code uses different settings for development and production environments so we were looking at using VS2010\'s web.config transform capabilities. After hours of trial and error, nothing has worked

Our code uses different settings for development and production environments so we were looking at using VS2010's web.config transform capabilities. After hours of trial and error, nothing has worked. We found a Web.config transformation tester and found that what we had been trying was supposed to work (according to this tool.)

We tried testing the transformations using Build, not Publish. Does it only run on Publish 开发者_如何学编程or could something else be wrong?


Yes, it only runs on Publish. To test, publish to a local dir. You'll want to publish your application with the correct target environment set.

You can also integrates web config transformations with MS Build.


It seems you don't have to be in Publish mode to generate a transformed Web.config file. There's just a bit more work involved.

Open the Visual Studio Command Prompt and navigate to your working project directory that contains your .csproj file. Enter the following command:

MSBuild project.csproj /t:TransformWebConfig /p:Configuration=Debug

The example above would run the Debug transformation during the build of project.csproj. This will output a Web.config file into the obj\Debug\TransformWebConfig\transformed\ directory, where Debug is whatever Configuration you set in the command above.

Copy this file to replace your root Web.config file, and you're done. You could write a batch script to run both of those items automatically, but for larger projects with many configurations it could become unwieldy.

You might be able to add those command line arguments to the build process inside of Visual Studio, but I'm not sure how - as far as I know for this method to work you would have to build from the command line instead of inside Visual Studio. You can still use Clean inside of Visual Studio to clean out the obj folder but it will only clean the solution configuration mode selected in the IDE. Clean will not revert your edited web.config file, so you may want to back it up before proceeding if you need to.

(Command line arguments found from this MSDN article.)


You don't need run Publish/Build Package in order to test Web.config transformation. There is a cool trick to quickly know the transformation result here. Scroll down until you see a comment about creating TransformConfig project. It works like a charm, note that you can safely ignore 7th step (frankly I don't know how to do that step properly but fortunately we don't need it :)).

0

精彩评论

暂无评论...
验证码 换一张
取 消