使用SlowCheetah扩展插件解决测试环境和生产环境xml配置文件内容切换

https://marketplace.visualstudio.com/items?itemName=WillBuikMSFT.SlowCheetah-XMLTransforms

What

This package allows you to automatically transform your app.config (or any file) when you press F5 in Visual Studio. You can have different transformations based on the build configuration. This will enable you to easily have different app settings, connection strings, etc for Debug versus Release. If you want to transform other files you can do that too. Here are some other reasons why you might want to install this package.

Have you ever:

  1. Wanted to have different appSettings for debug and release when building your 
    app?
  2. Wanted to use different connection strings based on your build configuration 
    when building your app?
  3. Wanted to transform any XML file with a clean and simple syntax?
  4. Wanted to tweak WCF service configuration in a straight foward way?
  5. Wanted to preview your XML transform without building/publishing your app?
  6. Wanted to transform files in addition to web.config on publish for Web projects?

If you answered Yes to any of these then you should download this package.

How

Getting started is really simple, just install this package. Then in the solution explorer you can easily add your config transform by right-clicking and selecting Add Transform.

After you add the transform you will notice a transform for each build configuration.

You can place your customizations inside of the transform files, for example if you want to tweak app settings and connection strings you might use the syntax shown below.

<?xml version="1.0" encoding="utf-8" ?> <!-- For more information on using transformations       see the web.comfig examples at http://go.microsoft.com/fwlink/?LinkId=214134. --> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"&gt;    <appSettings>   <add key="appName" value="WPF Demo-Release" xdt:Transform="Replace" xdt:Locator="Match(key)"/>   <add key="url" value="http://contoso.com/&quot; xdt:Transform="Replace" xdt:Locator="Match(key)"/>   <add key="email" value="release@contoso.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/> </appSettings>   <connectionStrings>   <add name="RecordsDb" connectionString="db.contoso.com;Initial Catalog=RecordsDb;Integrated Security=true"        xdt:Transform="Replace" xdt:Locator="Match(name)"/>   <add name="InventoryDb" connectionString="db.constos.com;Initial Catalog=InventoryDb;Integrated Security=true"        xdt:Transform="Insert" xdt:Locator="Match(name)" /> </connectionStrings>    </configuration> 

When you build your applicatoin the files are transformed and dropped into the output directory. If you are transforming the app.config then when the file is transformed it will be renamed in the output directory as usual to ensure that your application picks it up at runtime.

For web projects the files are transformed when you publish or package your application.

You can also quickly preview your transform using the Preview Transform context menu on the transform file.

Setup Projects

In version 1.3 we now have support for Setup projects. If your setup project has the Project Outputs of a referenced project which is using SlowCheetah then the transformed app.config will be the configuraiton file used which is laid on disk in the installer.

ClickOnce

In version 1.3 we have added support for ClickOnce. If you publish a project with ClickOnce which uses SlowCheetah then the transformed files (instead of the source files) will be published.

F# Projects

We now (as of version 1.3) have support for F# projects. When you add a transform into an F# project they will not show up as child items, but the transformations will run correctly.

 

Getting Help 

If you need some help please do not post in the QA here, instead use these methods.

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值