如何不将 app.config 文件复制到输出目录 [英] How to not copy app.config file to output directory

查看:29
本文介绍了如何不将 app.config 文件复制到输出目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个 WPF 应用程序.我正在使用 Visual Studio Community 2015.为了创建一个真正的"发布版本,我正在更改一些构建设置,以便它只生成将安装在用户计算机上的必要文件.所以没有 vshost exe,没有生成的 XML 文件等等(不过,我保留了 PDB 文件生成).

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 it only generates necessary files that will be installed on the user's computer. So no vshost exe, no generated XML files, etc. etc. etc. (I am retaining PDB file generation, however).

我拥有我想要的一切,除了一个文件.我在每个项目中都有一个 App.config 文件.我不介意在我的调试版本中将其复制到输出目录,但在我的真实"版本版本中,我不希望它出现在那里.

I have everything exactly how I want it, except for one file. I have an App.config file in each project. I don't mind this getting copied to the output directory on my debug builds, but on my "true" release build I don't want it there.

该文件已在其属性中设置为请勿复制".见下图:

The file is already set as "Do not copy" in its properties. See images below:

尽管有不复制"设置,但我仍然会在每次构建项目时生成一个MyAppName.exe.config"文件.为什么会这样?我怎样才能关闭它?挺烦人的.

Despite having the "Do not copy" setting, however, I still get an "MyAppName.exe.config" file generated every single time I build the project. Why is this so? How can I turn it off? It is quite annoying.

感谢您的建议!

推荐答案

app.config 的处理比较特殊,它被处理为By Name,构建过程会选择下面的app.config文件这个顺序:

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

  • 选择在主项目中设置的值 $(AppConfig).
  • 在与项目相同的文件夹中选择@(None) App.Config.
  • 在与项目相同的文件夹中选择@(Content) App.Config.
  • 在项目的任何子文件夹中选择 @(None) App.Config.
  • 在项目的任何子文件夹中选择 @(Content) App.Config.

$(AppConfig) 是一个 MSBuild 属性,如果它为空,它将在无"或内容"MSBuild 项组中查找名为App.Config"的文件,如果匹配,则该文件将被使用并将被复制到输出目录,用 [AssemblyName].config 替换 app.config 名称

$(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

如果您想保留文件而不删除它,您需要将构建操作"属性更改为与无"或内容"不同的内容,您可以使用列表中的任何现有值(我建议"AdditionalFiles") 或您想使用的任何值,即MyConfigFile",现在将文件保存在项目中,但没有在输出目录中生成配置文件的逻辑.

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.

或者您可以将文件重命名为不同于app.config"的名称,并保留构建操作"和复制到输出目录"的当前属性值.

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".

这篇关于如何不将 app.config 文件复制到输出目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆