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

后端 未结 5 2035
日久生厌
日久生厌 2020-12-03 06:58

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 conf

5条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-03 07:50

    Since the OP asked about Web.config transformations during the deployment lets assume a WPP is already in there. So I've hacked on the WPP.

    I use the following snippet to transform Umbraco's own config files (but indeed any configs suit well):

    
    
      
        
          Config\umbracoSettings.config
        
      
    
      
        
          $(CollectWebConfigsToTransformDependsOn);
          CollectUmbracoConfigsToTransform
        
      
    
      
        
        
          
            false
            $([System.String]::new($(WebPublishPipelineProjectDirectory)\$([System.IO.Path]::GetDirectoryName($([System.String]::new(%(DestinationRelativePath)))))).TrimEnd('\'))\%(Filename).$(Configuration)%(Extension)
            $(TransformWebConfigIntermediateLocation)\original
            $(TransformWebConfigIntermediateLocation)\assist
            $(TransformWebConfigIntermediateLocation)\transformed\%(DestinationRelativePath)
            $([System.IO.Path]::GetFullPath($(WPPAllFilesInSingleFolder)\%(DestinationRelativePath)))
          
        
      
    
    

    I name it Umbraco.wpp.targets and drop inside project's root. The the WPP automatically imports it.

    All you have then to do is add a transform file (Config\umbracoSettings.Release.config is case of this sample).

提交回复
热议问题