App.Config Transformation for projects which are not Web Projects in Visual Studio?

后端 未结 14 2687
走了就别回头了
走了就别回头了 2020-11-22 04:06

For Visual Studio 2010 Web based application we have Config Transformation features by which we can maintain multiple configuration files for different environments. But the

14条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 04:20

    Note: Due to reputation I cannot comment on bdeem's post. I'm posting my findings as an answer instead.

    Following bdeem's post, I did the following (in order):

    1. I modified the [project].csproj file. Added the tags to the ItemGroup for the different config files and made them dependent on the original config file.

    Note: Using will not work with the transformation.

    
    
    
    
      App.config
    
    
      App.config
    
    

    2. At the bottom of the [project].csproj file (before the closing tag), I imported the ${MSBuildToolsPath\Microsoft.CSharp.targets file, added the UsingTask to transform the XML and added the Target to copy the transformed App.config file to the output location.

    Note: The Target will also overwrite the App.Config in the local directory to see immediate changes working locally. The Target also uses the Name="Afterbuild" property to ensure the config files can be transformed after the executables are generated. For reasons I do not understand, when using WCF endpoints, if I use Name="CoreCompile", I will get warnings about the service attributes. Name="Afterbuild" resolved this.

      
      
    
      
      
      
            
        
        
        
        
    
        
        
          
          
            $(TargetFileName).config
          
        
      
    
    

    3. Went back into Visual Studio and reloaded the modified files.

    4. Manually added the App.*.config files to the project. This allowed them to group under the original App.config file.

    Note: Make sure the App.*.config files have the proper XML structure.

    
    
    
    
    
      
        
      
    
    

    5. Re-built the project.

提交回复
热议问题