How to add config transformations for a custom config file in Visual Studio?

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.

But the problem of transformation appears during the deployment of the project to different environments. I have three web.config files:

Web.config

Web.Uat.config

Web.Release.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 transforms only web.config files by default.

If you need custom config file with transformation for DEV, UAT, PROD, etc environments, then try to

  • 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.
  • A little bit details:

    Add VS Extension SlowCheetah from Extensions and Updates 扩展和更新屏幕

    Right click on your myconfig.config and choose add transorm:

    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

    链接地址: http://www.djcxy.com/p/65682.html

    上一篇: 改进此代码的方法

    下一篇: 如何在Visual Studio中为自定义配置文件添加配置转换?