How to not copy app.config file to output directory

后端 未结 2 612
不思量自难忘°
不思量自难忘° 2020-12-18 04:18

I have a WPF application I am building. I am using Visual Studio Community 2015. In an effort to create a \"true\" release build, I am changing up some build settings so i

相关标签:
2条回答
  • 2020-12-18 04:42

    Add /p:AllowedReferenceRelatedFileExtensions=.pdb in the MSBuild parameters to suppress library project .config files, library xml docs, etc. With the above, only PDBs are retained.

    This parameter can also be added to csproj files, but personally I find it easier to manage as part of the build configuration.

    0 讨论(0)
  • 2020-12-18 04:53

    The handling of app.config is special, it is treated By Name, the build process will select the app.config file following this order:

    • Choose the value $(AppConfig) set in the main project.
    • Choose @(None) App.Config in the same folder as the project.
    • Choose @(Content) App.Config in the same folder as the project.
    • Choose @(None) App.Config in any subfolder in the project.
    • Choose @(Content) App.Config in any subfolder in the project.

    $(AppConfig) is an MSBuild Property, if it is empty, it will look for a file with name "App.Config" in the "None" or "Content" MSBuild Item Groups, if there's a match, the file will be used and will be copied to the output directory replacing the app.config name by [AssemblyName].config

    If you want to keep the file without delete it, you will need to change the "Build Action" property to something different to "None" or "Content", you can use any existing value on the list (I suggest "AdditionalFiles") or any value you want to use i.e. "MyConfigFile", and now the that will keep the file inside the project, but without the logic that generates the configuration file in the output directory.

    Or you can rename the file to something different than "app.config" and keep the current property values for "Build Action" and "Copy to Output Directory".

    0 讨论(0)
提交回复
热议问题