visual-studio 如何防止在发布模式构建中复制 XML 文档文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3980958/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to prevent the copy of XML documentation files in a release mode build?
提问by Humberto
I have a Visual Studio 2010 project which references some third-party components. Their assemblies are accompanied by XML documentation files, which are useful for us (and only us) developers. And whenever the project is built (either in Debug or Release modes) these XML files are copied to the build directory.
我有一个 Visual Studio 2010 项目,它引用了一些第三方组件。它们的程序集随附有 XML 文档文件,对我们(并且只有我们)开发人员很有用。并且无论何时构建项目(在调试或发布模式下),这些 XML 文件都会被复制到构建目录中。
I can't seem to find a setting or switch to disable the copy of those XML files to the build directory, either within Visual Studio or though MSBuild. A post-build script may be an option, but a smelly one. Any ideas? Thank you.
我似乎无法在 Visual Studio 中或通过 MSBuild 找到设置或开关以禁用将这些 XML 文件的副本复制到构建目录。构建后脚本可能是一种选择,但很糟糕。有任何想法吗?谢谢你。
回答by Sayed Ibrahim Hashimi
When you build a project the .xml/.pdb files are gathered through the ResolveAssemblyReference task. When ResolveAssemblyReference is called it is passed a list of file extensions for related files. That list of file extensions is captured in the MSBuild property AllowedReferenceRelatedFileExtensions. By default that list will contain ".pdb;.xml".
构建项目时,.xml/.pdb 文件是通过 ResolveAssemblyReference 任务收集的。当调用 ResolveAssemblyReference 时,它会传递相关文件的文件扩展名列表。该文件扩展名列表在 MSBuild 属性AllowedReferenceRelatedFileExtensions 中捕获。默认情况下,该列表将包含“.pdb;.xml”。
If you want to exclude all related reference files from being picked up then just override the value of the property to something which related files won't have extensions of. For example you can set AllowedReferenceRelatedFileExtensionsto "-".
如果您想排除所有相关参考文件,则只需将属性值覆盖为相关文件没有扩展名的内容。例如,您可以将AllowedReferenceRelatedFileExtensions设置为“-”。
You can also customize the list of file which are returned by that. If you only want to find only .pdb files then you will need to pass in AllowedReferenceRelatedFileExtensions=".pdb". In that case any references which have .pdb file next to the .dll/.exe they will be copied as well. You can also use this to copy other related files which may not end in .pdb/.xml. For example if you have a referenced assembly named, MyAssembly.dll and in that same folder there exists MyAssembly.pdb and MyAssembly.foo If you set AllowedReferenceRelatedFileExtensions=".pdb;.foo"then both the .pdb and .foo file will be copied to the output directory.
您还可以自定义由此返回的文件列表。如果您只想找到 .pdb 文件,那么您需要传入AllowedReferenceRelatedFileExtensions=".pdb". 在这种情况下,任何在 .dll/.exe 旁边有 .pdb 文件的引用也将被复制。您还可以使用它来复制其他可能不以 .pdb/.xml 结尾的相关文件。例如,如果您有一个名为 MyAssembly.dll 的引用程序集,并且在同一文件夹中存在 MyAssembly.pdb 和 MyAssembly.foo 如果您设置,AllowedReferenceRelatedFileExtensions=".pdb;.foo"则 .pdb 和 .foo 文件都将复制到输出目录。
回答by Alex
Visual studio project file has the same format as any msbuild file. So you can manually add the condition into corresponding section to not copy your xml files if configuration name is 'Release'.
Visual Studio 项目文件的格式与任何 msbuild 文件的格式相同。因此,如果配置名称为“Release”,您可以手动将条件添加到相应的部分,以不复制您的 xml 文件。
It should be changing
应该会变
<ItemGroup>
to
到
<ItemGroup Condition="'$(CONFIG)'=='RELEASE'">
or something like this.
或类似的东西。
回答by Marc Gravell
If the .xml/.pdb are marked as build-action "Content" (etc), you can change them to "None". You should also ensure they copy-to-build-output is false.
如果 .xml/.pdb 被标记为构建操作“内容”(等),您可以将它们更改为“无”。您还应该确保它们 copy-to-build-output 为false。
Are both of those set?
这两个都设置了吗?
回答by Russell McClure
What is the problem with having the XML files get copied into the folder on release builds? It seems to me that this is fine and that the real problem is with the code that picks up files to place them in the installer. Picking up third party dlls from your own bin\release folder is not a good practice in my opinion. I'd have my installer pick up third party dlls from their own folder in my source tree.
在发布版本中将 XML 文件复制到文件夹中有什么问题?在我看来,这很好,而真正的问题在于提取文件以将它们放入安装程序的代码。在我看来,从您自己的 bin\release 文件夹中获取第三方 dll 不是一个好习惯。我会让我的安装程序从我的源代码树中他们自己的文件夹中选择第三方 dll。
回答by Benjamin Howarth
The setting is in the Properties of the project in question, under the "Build" tab, uncheck "XML documentation file". It's also an MSBuild property called <DocumentationFile>under the applicable <PropertyGroup>for your build configuration in the .*proj file.
该设置位于相关项目的属性中,在“构建”选项卡下,取消选中“XML 文档文件”。它也是一个 MSBuild 属性,在 .*proj 文件中<DocumentationFile>的适用<PropertyGroup>于您的构建配置下调用。

