app.config Transformations

2020-05-17 04:55发布

I'm a huge fan of the addition of web.config transformations in Visual Studio 2010. See also Scott Hanselman's recent talk at MIX2011.

What sucks is that this functionality (appears at least) to only be available to web projects.

In our solution we have several Windows Services that connect to a different database dependant on the environment they are deployed under.

Has anyone come up with a nice, tidy way of achieving similar 'app.config transformation' functionality?

Note: We are using TFS 2010 to build our solutions in a Continuous Integration manner.

5条回答
smile是对你的礼貌
2楼-- · 2020-05-17 05:25

If you have multiple client assemblies and don't want to duplicate the same configuration data, I created Profigurator. It'll take a JSON file as input and apply the settings to an app.config or web.config.

It's a little rough as I write this, but I am currently using it on a production system for deploys and it works great.

查看更多
forever°为你锁心
3楼-- · 2020-05-17 05:33

I wrote nice extension to automate app.config transformation like the one built in Web Application Project Configuration Transform

查看更多
贪生不怕死
4楼-- · 2020-05-17 05:35

Using Luke Bennett's answer to set me off on the right track. I found this to be the answer for us.

FTA (see link for code snippets):

  1. Add a new property ProjectConfigFileName that points to your App.Config file

  2. Add a version of App.Config for each configuration, i.e., App.Debug.config To have them nested under App.Config, edit your csproj file,

  3. Import Microsoft.Web.Publishing.targets into your csproj file right after the Microsoft.CSharp.targets import.

  4. Call the TransformXml task in your AfterBuild target. Note, the BeforeBuild and AfterBuild targets are commented out by default.

查看更多
相关推荐>>
5楼-- · 2020-05-17 05:36

You can use the XML transformation functionality with any XML file - we do this all the time. It's available via an MSBuild task.

Try adding the following to your build script:

<UsingTask TaskName="TransformXml"
           AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

<TransformXml Source="Path\To\Your\Xml.config"
              Transform="Path\To\Your\Xml.$(Configuration).config"
              Destination="Path\To\Your\Output.config" />
查看更多
三岁会撩人
6楼-- · 2020-05-17 05:45

I realize you already have an answer, but I stumbled across SlowCheetah this morning which is the best implementation I've seen to date. There is also a blog post on getting this running from a CI server.

查看更多
登录 后发表回答