使用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.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念
xml文件介绍及使用
xml编程(一)-xml语法
XML文件结构和基本语法
第2章 包装类
XML入门的常见问题(二)
Java对象的强、软、弱和虚引用
JS解析XML文件和XML字符串详解
java中枚举的详细使用介绍
了解Xml格式
XML入门的常见问题(四)
深入SQLite多线程的使用总结详解
PlayFramework完整实现一个APP(一)
XML和YAML的使用方法
XML轻松学习总节篇