如何添加配置的转换在Visual Studio中的自定义配置文件? [英] How to add config transformations for a custom config file in Visual Studio?
问题描述
我正在参与这一项目的一个配置文件读了很多服务端点(URL)的。由于清单将是相当大的,我决定让他们在自定义配置文件,以保持我的web.config清洁小。我包括如下自定义栏目给我的网站:
The project I am working on involves reading a lot of service endpoints (url) from a config file. Since the list would be quite large I decided to keep them in a custom config file to keep my web.config clean and small. I included the custom section to my web as below:
<mySection configSource="myConfig.config" />
我工作完全正常。
I works perfectly fine.
但转型的问题,该项目对不同环境的部署过程中出现。我有三个web.config文件中:
But the problem of transformation appears during the deployment of the project to different environments. I have three web.config files:
Web.config文件
Web.config
Web.Uat.config
Web.Uat.config
Web.Release.config
Web.Release.config
虽然改造工程web.config中,自定义配置文件的转换失败的部署。
While the transformation web.config works, the transformations for custom config files fails at deployment.
有没有办法在部署过程中,我可以转换自定义配置文件?
Is there an way I can transform the custom config file during deployment?
推荐答案
Visual Studio中默认情况下只转换web.config文件中。
Visual Studio transforms only web.config files by default.
如果你需要自定义配置文件与DEV,UAT,PROD等环境改造,然后尝试
If you need custom config file with transformation for DEV, UAT, PROD, etc environments, then try to
- 为Visual Studio如 SlowCheetah使用自定义的扩展 - XML变换为配置transormation preVIEW功能。
- 添加从 SlowCheetah 该项目转型提供了内置。
- Use custom extensions for Visual Studio like SlowCheetah - XML Transforms for Config transormation preview functionality.
- Add for the project from Nuget SlowCheetah to provide build in transformation.
一点点的细节:
Add VS Extension SlowCheetah from Extensions and Updates
右键点击您的 myconfig.config 并选择添加transorm:
Right click on your myconfig.config and choose add transorm:
在每个定义的配置插入自己的transormation rulles这样的:
Inside each defined configurations insert your own transormation rulles like that:
<services xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<service name="WebApplication1.Services.Service2" xdt:Transform="Replace" xdt:Locator="Match(name)" >
<endpoint address="http://localhost:57939/Services/DebugService" behaviorConfiguration="WebApplication1.Services.Service2AspNetAjaxBehavior"
binding="webHttpBinding" contract="WebApplication1.Services.Service2" />
</service>
</services>
希望这是有帮助的。
Hope it was helpful
这篇关于如何添加配置的转换在Visual Studio中的自定义配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!