Can I force the installer project to use the .config file from the built solution instead of the original one?

前端 未结 7 1261
我在风中等你
我在风中等你 2021-02-01 09:41

I am using the solution to this question in order to apply configuration changes to App.config in a Winforms project. I also have an installer project for the proj

7条回答
  •  深忆病人
    2021-02-01 10:08

    I combined the best of the following answers to get a fully working solution without using any external tools at all:

    1. Setup App.Config transformations

    Source: https://stackoverflow.com/a/5109530

    In short:

    Manually add additional .config files for each build configuration and edit the raw project file to include them similar to this:

    
    
      App.config
    
    
      App.config
    
    

    Then include the following XML at the end of the project file, just before the closing tag:

    
    
      
      
        
        
          $(TargetFileName).config
        
      
    
    

    Finally edit the additional .config files to include the respective transformations for each build configuration:

    
    
      
    
    

    2. Include the appropriate .config in the setup project

    First, add a command in the postbuild event of your main project to move the appropriate transformed .config file to a neutral location (e.g. the main bin\ directory):

    copy /y "$(TargetDir)$(TargetFileName).config" "$(ProjectDir)bin\$(TargetFileName).config"
    

    (Source: https://stackoverflow.com/a/26521986)

    Open the setup project and click the "Primary output..." node to display the properties window. There, add an ExludeFilter "*.config" to exclude the default (untransformed) .config file.

    (Source: https://stackoverflow.com/a/6908477)

    Finally add the transformed .config file (from the postbuild event) to the setup project (Add > File).

    Done.

    You can now freely add build configurations and corresponding config transforms and your setup project will always include the appropriate .config for the active configuration.

提交回复
热议问题