我正在从事的项目涉及从配置文件读取大量服务端点(url)。由于列表相当大,我决定将它们保存在自定义配置文件中,以保持我的 web.config 干净且小。我将自定义部分添加到我的网站中,如下所示:
<mySection configSource="myConfig.config" />
我工作得很好。
但项目部署到不同环境的过程中就出现了转换的问题。我有三个 web.config 文件:
网页配置
Web.Uat.config
Web.Release.config
虽然转换 web.config 有效,但自定义配置文件的转换在部署时失败。
有没有办法可以在部署期间转换自定义配置文件?
默认情况下,Visual Studio 仅转换 web.config 文件。
如果您需要针对 DEV、UAT、PROD 等环境进行转换的自定义配置文件,请尝试
- 使用 Visual Studio 的自定义扩展,例如SlowCheetah - XML 转换 https://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5用于配置转换预览功能。
- 从 Nuget 为项目添加慢猎豹 https://www.nuget.org/packages/SlowCheetah/提供构建转型。
一点细节:
Add VS Extension SlowCheetah from Extensions and Updates
Right click on your myconfig.config and choose add transorm:
在每个定义的配置中插入您自己的转换规则,如下所示:
<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>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)