This package enables you to transform your app.config or any other XML file based on the build configuration. It also adds additional tooling to help you create XML transforms.. Written by: Sayed Ibrahim Hashimi, Chuck England and Bill Hiebert
We had several self-inflicted wounds with accidentally testing applications that had config entries that pointed to production instead of the quality assurance environment. Because of this we searched and found Slow Cheetah that let us separate the configs into Development, QA, and Production. Things are a lot safer now. Thanks for creating this.
Watched the Visual Studio Toolbox video on this some time ago, but have only just installed it. The tool is great and Its saving me heaps of time! No more building and deploying just to diff config files. Thanks for the work on this extension!
That is a cool stuff. That is to be installed on a develoer computer (VS). But how can I install on build server? Do you have any installation program for that?
Hi Yuri, see my blog post at http://sedodream.com/2012/12/24/SlowCheetahBuildServerSupportUpdated.aspx regarding how to get it working for build servers.
It's on the backlog https://github.com/sayedihashimi/slow-cheetah/issues/39. Should be the next major feature I work on. For web projects this support is much trickier than non-web projects.
Excellent. My app.config's are now updated with a Test, PreProd or Prod SQL Server connection string, even when running (rather than Deploying) my apps. A lifesaver - thanks!
Awesome! I'm just so used to web.config transforms in ASP.Net applications that I also want this functionality in a WinForms Application.
Your add-in works like a charm. Keep up the good work. I hope this add-in will be included into VS 2012 sometime in the future, just like they did with Nuget.
Even debug sessions are effected by the transform, depending on the selecte d solution configuration! Really nice work.
It won't be included in VS2012, and at this time it likely wont ever make it into VS. If you think it should I suggest you make a suggestion at http://visualstudio.uservoice.com/ and have all your friends vote it up.
I am using SlowCheetah now. In my main web.config for a WCF Service project I wanted to have blank connection strings and blank key names. Then I have transforms setup to replace these with legitmate values depending on the configuration I am in. These seem to work fine when I publish, but when I debug run the application in VS 2010 it does not transform the web.config, and errors out. Is there a way I can get SlowCheetah to implement when I hit F5?
yes there is...
SlowCheetahTargets is very handy to preview transform outputs but the transform feature does not come from it: this is a visual studio task. So you can work with SlowCheetahTargets to edit app.config and derived configuration.
Here is how I work with those features:
1. do not edit web.config : edit only app.config file and it's derived config files (preview results with SlowCheetahTargets)
2. let's visual studio build the web.config file on pre compile :
==> add the lines below to the end of project definition file (.csproj )
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="BeforeCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="Web.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>../Web.config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
enjoy...
@Anders, sorry for the late reply. I have blogged about how to do this at http://sedodream.com/SearchView.aspx?q=transform%20web.config#a68b7e248-b9f5-4d07-bdfe-eb037bcf2cbb.
Hi,
I have quite a large app.config file which I've split up using the configSource attribute to get it to point to other xml files with specific bits of configuration in.
I've used slowcheetah to create transforms on those xml files and it all seems to work well when I do a build but with my setup project only the untransformed xml is installed.
In my project I've marked the basic xml files build action as 'content' with 'copy to output directory' set to 'Copy always'. The transforms are set to build action 'none' and 'do not copy'. The setup project uses get content files to get the xml configs.
Is there some other way I should configure the installer so it get's the transformed xml files?
Thanks,
OK, so I found a work around which is a bit ugly but seems to work:
I've created a single file called config.xml in my project and set it to 'Build Action' = 'Content' and 'Copy to Output Directory' = 'Copy always'.
I've also created a file called config.transform.xml which I have 'SlowCheetahed' into transforms which stored the actual configurations I want and their transforms. This is set to 'Build Action' = 'None' and 'Copy to Output Directory' = 'Do not Copy'.
Then in the project file I've added the following:
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="BeforeBuild">
<TransformXml Source="config.transform.xml" Destination="config.xml" Transform="config.transform.$(Configuration).xml" />
</Target>
This then basically overwrites the config.xml file before the build so the correct transform of the file is there. This seems to then get through to the Setup Project and works for normal builds.
The obvious drawback is that the file gets modified all the time and can cause confusion if developers check in different versions but at least it works.
Hope this helps someone.
Sorry, forgot to mention that you need to get your installer project to install content files as well as build output for the process described above to work.
Sorry I think we have a bug here. I have created the following issue to track this https://github.com/sayedihashimi/slow-cheetah/issues/2. Feel free to add comments there.
Regarding the discussion forum here, its not very good sorry.
Hi Sayed,
I am using this on our dev and our CI server. The dev machines are using VS2010. It works fine with both command line and in the IDE with our build script. However, on the CI server which is Windows 2008 Server and have VS2010, it didn't run TransformAllFiles target in the automated process. But it works fine from command line running the same build script as an administrator on the CI server. I have tried to move the dll and the targets files to different locations in build workspace and out in other folders.
I finally changed our build service to run under a domain user with admin rights instead of local system account. And it started to work.
So it seemed to me that that target was skipped because either the target file or the dll was not imported. Is there a specific permission we need to set or is there something else I am missing?
Our build has both web projects and non web projects, the default Transformxml works fine for Web projects with local system account.
BTW, It's a really good tool
Thanks,
Hi Sayed,
I have an xml file as an embedded resource to be used for nhibernate configuration. I would like to embed the transformed file as the embedded resource rather than the original. Since the transformed files are copied in to the relative bin\$(Configuration) the build will and does include the non transformed file as the embedded resource. I was wondering if there is a simple way using "Slow Cheetah" to get the transformed file included as the embedded resource.
One way would be to run the transforms before the build begins and add the xml file as a Link from the bin\$(Configuration) so that you always get the transformed file rather that the original.
--Thanks
Hi Kamran, thanks for your feedback. This is not supported but you could always use the TransformXml task directly in your project files to realize such scenarios.
Hello Sayed and Kamran,
I am not at all familiar with msbuild tasks, but I also have the need to transform embedded .resx files and .settings files. Do either of you have suggestions how to modify the .csproj file to accomplish this?
Hi,
I want to add transforms to an EPiServer license file. However, for this to be maintainable I need to replace all content in License.config. When I'm adding xdt:Transform="Replace" to the root node I get the following error:
"Could not write Destination file: Cannot insert the node in the specified location."
This applies to any file except Web.config. Any thoughts on this?
Hello,
In our project we use a custom transformation dll by using the following syntax:
<xdt:Import path="C:\Program Files (x86)\MSBuild\Custom\asdasd.Configuration.CustomTransforms.dll"
namespace="asdasd.Configuration.CustomTransforms" />
This dll is tested and it worked, however after installing the plugin i'm not able to preview the changes in a transformation which use this dll.
Hi Marco, sorry for the late response here. SlowCheetah will likely not work with existing custom transforms. I will add this to the backlog, can you tell me what your transform is doing? I'm just curious.
Trying to get started in vs2010 console app but can't get past this compile error:
The "SlowCheetah.Tasks.TransformXml" task failed unexpectedly.
System.UriFormatException: Invalid URI: The URI is empty.
at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString)
at SlowCheetah.Tasks.TransformXml.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult)
I changed app.debug.config and release.config to content. Not sure which URI it's talking about. Is there some special setup required for console apps?
I created a console project. My solution contains 2 other solution configurations (beyond Debug and Release).
When I selected Add Transform on the app.config all it created was Debug and Release. I would have expected the other 2 as well. I tried setting my config to one of the other configs not generated and tried 'Add Transform' with no luck.
How can I get configs the the other platform configurations generated without manually hacking the .csproj file?
Thanks.
I figured it out. I forgot a step. In Configuration Manager I forgot to create a project configuration for my other 2 setups. Once I did that, the 'Add Transform' worked as I expected and generated the other 2 app.config files.
Some of the older projects in my solution have those configurations setup. The new console project I forgot to do that.
Thanks.
Does anyone know if Visual Studio 11 will have this functionality available by default? I'm looking at the Visual Studio 11 Beta and I can't see anything... Such a useful tool.