使用SlowCheetah扩展插件解决测试环境和生产环境xml配置文件内容
https://marketplace.visualstudio.com/items?itemName=WillBuikMSFT.SlowCheetah-XMLTransforms WhatThis 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:
If you answered Yes to any of these then you should download this package. HowGetting 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"> <appSettings> <add key="appName" value="WPF Demo-Release" xdt:Transform="Replace" xdt:Locator="Match(key)"/> <add key="url" value="http://contoso.com/" 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. Setup ProjectsIn 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. ClickOnceIn 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# ProjectsWe 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.
(编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |