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

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

问题描述

我有一个正在构建的WPF应用程序.我正在使用Visual Studio Community2015.为创建真实"发行版本,我正在更改一些版本设置,以便它仅生成将安装在用户计算机上的必要文件.因此,没有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文件.我不介意将此内容复制到调试版本的输出目录中,但是在我的"true"发行版本中,我不希望将其复制到该目录中.

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的处理很特殊,按名称进行处理,构建过程将选择以下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)值.
  • 在与项目相同的文件夹中选择@(无)App.Config.
  • 在与项目相同的文件夹中选择@(Content)App.Config.
  • 在项目的任何子文件夹中选择@(无)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

如果要保留文件而不删除它,则需要将构建操作"属性更改为与无"或内容"不同的名称,您可以使用列表中的任何现有值(我建议其他文件")或您要使用的任何值,例如"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天全站免登陆