When I talk to people about the XDT (web.config) transforms that web projects support for package/publish one of the most common questions is “Does this work for non-web projects?” Unfortunately the answer is No, but myself and a friend of mine (Chuck England) have created a Visual Studio add in which enables just this. You can find it in the Visual Studio gallery under the name SlowCheetah – XML Transforms. Here is an overview of the features of the add in.
- Add tooling to desktop project to create XDT transforms
- Transform app.config for desktop projects based on build configuration
- Transform any XML file to the output folder base on build configuration
- Add tooling to enable previewing XDT transforms
- For web projects easily transform other XML files during package/publish
After you install the add in you will get the following menu item when you right click any XML file.
For each build configuration defined you will get a transform created as a child item.
These files are stub XDT transforms. You can place your transform content in those files and they will be executed when you debug/run your application. For example if your app.config contained the following.
And your app.debug.config contained
When you run your application the config file created will contain the following.
Transforming other files
You are not limited to transforming app.config, you can transform any XML file. When you create a transform for an arbitrary XML file when you run your application the transformed XML file will be dropped into the output (bin) folder of your application.
Previewing Transforms
You can easily preview transform results as well. After you have created the transform file you can right click on it and select Preview Transform.
After you click it you should see the following.
I hope you guys find this useful. Let me know if you have any feedback on this!
Note: This add in was created by me and a friend of mine, these are not created nor supported by Microsoft.
Sayed Ibrahim Hashimi – @sayedihashimi
http://exceptionalcode.wordpress.com/2010/06/21/visual-studio-app-config-xml-transformation/
The popup addin works great, and I could create the app.xxx.config stubs.
But the generation fails... After an hour of investigation, there is no such file as SlowCheetah.Transforms.targets in my localappdata.
I uninstalled/reinstalled with procmon in backgound to check if this file is installed somewhere else, but no trace of it.
Are you sure that your last version of your vsix contains the targets file ?
Otherwise, can you give a weblink to download this single file ?
Thank you for your help and your work.
I have found this add-in really useful but have come across an issue I hope you can help with. When I create arbitrary XML files in a project they transform as expected, but if the files are moved into a sub-folder in the project they are no longer copied to the output. Same problem if I create new XML files in a sub-folder.
When I publish to Azure or when I create a package local the app.config file in bin folder remains unchanged.
With app.config I mean Projectname.dll.config
For the web roles everything is working well because Microsoft already implemented this for web.config.
Thank you for that great tool.
Is it possible to use the SlowCheetah to transform during an MSBuild operation? We're using TeamCity to do an autodeploy of our web site, and trying to transform an XML file with specific values for development and QA servers. Can you offer a suggestion? It works great if I publish from my Visual Studio, but we need these on a daily build solution.
This is a great solution, I was thinking of developing something like this. For the time being I did the following thing for transformation :
http://www.rahulchugh.com/2012/01/configuration-files-transformation-for.html
Just to add - I am a fan of yours. I have learnt all the MSBuild from your book only!
--
Rahul Chugh
Microsoft Global Delivery
Comments are closed.