防止将引用的程序集 PDB 和 XML 文件复制到输出
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2011434/
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
Preventing referenced assembly PDB and XML files copied to output
提问by Jason Morse
I have a Visual Studio 2008 C#/.NET 3.5 project with a post build task to ZIP the contents. However I'm finding that I'm also getting the referenced assemblies' .pdb (debug) and .xml (documentation) files in my output directory (and ZIP).
我有一个 Visual Studio 2008 C#/.NET 3.5 项目,有一个后期构建任务来压缩内容。但是,我发现我还在输出目录(和 ZIP)中获取了引用程序集的 .pdb(调试)和 .xml(文档)文件。
For example, if MyProject.csproj references YourAssembly.dll and there are YourAssembly.xml and YourAssembly.pdb files in the same directory as the DLL they will show up in my output directory (and ZIP).
例如,如果 MyProject.csproj 引用 YourAssembly.dll,并且在与 DLL 相同的目录中有 YourAssembly.xml 和 YourAssembly.pdb 文件,它们将显示在我的输出目录(和 ZIP)中。
I can exclude *.pdb when ZIP'ing but I cannot blanket exclude the *.xml files as I have deployment files with the same extension.
我可以在压缩时排除 *.pdb,但我不能全面排除 *.xml 文件,因为我有具有相同扩展名的部署文件。
Is there a way to prevent the project from copying referenced assembly PDB and XML files?
有没有办法防止项目复制引用的程序集 PDB 和 XML 文件?
采纳答案by mwHymanson
You can also specify this via the command line:
您还可以通过命令行指定它:
MsBuild.exe build.file /p:AllowedReferenceRelatedFileExtensions=none
回答by Jason Morse
I wanted to be able to add and remove referenced assemblies in my primary application while avoiding the the need to maintain which files I needed to delete or exclude.
我希望能够在我的主应用程序中添加和删除引用的程序集,同时避免需要维护我需要删除或排除的文件。
I dug through Microsoft.Common.targetslooking for something that would work and found the AllowedReferenceRelatedFileExtensionsproperty. It defaults to .pdb; .xmlso I explicitly defined it in my project file. The catch is that you need something(whitespace is not sufficient) otherwise it will still use the default.
我仔细Microsoft.Common.targets寻找可行的方法并找到了该AllowedReferenceRelatedFileExtensions物业。它默认为.pdb; .xml所以我在我的项目文件中明确定义了它。问题是你需要一些东西(空格是不够的)否则它仍然会使用默认值。
<Project ...>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
...
<AllowedReferenceRelatedFileExtensions>
<!-- Prevent default XML and PDB files copied to output in RELEASE.
Only *.allowedextension files will be included, which doesn't exist in my case.
-->
.allowedextension
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
回答by AndrewHymansonZA
You can add a Post Build event command similar to del "$(TargetDir)YourAssembly*.xml", "$(TargetDir)YourAssembly*.pdb"
您可以添加类似的 Post Build 事件命令 del "$(TargetDir)YourAssembly*.xml", "$(TargetDir)YourAssembly*.pdb"
回答by Dingo
This is a rather old question, but since there is no answer about how to turn off generating PDB and XML files via UI, i figured that it should be here for completeness.
这是一个相当古老的问题,但由于没有关于如何通过 UI 关闭生成 PDB 和 XML 文件的答案,我认为它应该在这里是为了完整性。
In Visual Studio 2013: in project properties, under compile tab, uncheck "Generate XML documentation file", then click on "Advanced Compile Options" below that and change "Generate debug info" to "None", and that will do the trick.
在 Visual Studio 2013 中:在项目属性中,在编译选项卡下,取消选中“生成 XML 文档文件”,然后单击其下方的“高级编译选项”并将“生成调试信息”更改为“无”,这样就可以了。
回答by Jeffrey Zhao
My answer might be trivial now but I'd like to share the BAT script I use to delete the xml files if there's a corresponding dll for it. It's useful if you just want to cleanup the output folder and has other xml files that don't want to remove.
我的回答现在可能是微不足道的,但如果有相应的 dll,我想分享我用来删除 xml 文件的 BAT 脚本。如果您只想清理输出文件夹并且有其他不想删除的 xml 文件,它会很有用。
SETLOCAL EnableDelayedExpansion
SET targetDir=%1
ECHO Deleting unnecessary XML files for dlls
FOR %%F IN (%targetDir%*.xml) DO (
SET xmlPath=%%~fF
SET dllPath=!xmlPath:.xml=.dll!
IF EXIST "!dllPath!" (
ECHO Deleting "!xmlPath!"
DEL "!xmlPath!"
)
)
Usage:
用法:
Cleanup.bat c:\my-output-folder\
It took me an hour to finish this simple work (thanks to the "delayed expansion" stuff) with all type of searching here and there. Hope it helps other BAT newbies like me.
我花了一个小时来完成这项简单的工作(多亏了“延迟扩展”的东西)在这里和那里进行了各种类型的搜索。希望它可以帮助像我这样的其他 BAT 新手。
回答by David Rogers
I didn't have much luck with the other answers, I finally figured out how to do this in my implementation by using the built in "Delete" command, apparently there is a specific way you need to implement wildcards, it's bit nuanced, here's everything you need to be put into your "CSPROJ" (TargetDiris a built in variable, included automatically) under the "Project" tag:
我对其他答案没有多少运气,我终于通过使用内置的“删除”命令在我的实现中找到了如何做到这一点,显然你需要一种特定的方式来实现通配符,它 有点微妙,这里是您需要将所有内容放入“项目”标签下的“ CSPROJ”(TargetDir是一个内置变量,自动包含在内):
<Target Name="RemoveFilesAfterBuild">
<ItemGroup>
<XMLFilesToDelete Include="$(TargetDir)\*.xml"/>
<PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>
</ItemGroup>
<Delete Files="@(XMLFilesToDelete)" />
<Delete Files="@(PDBFilesToDelete)" />
</Target>
I've also had trouble with various language specific folders being generated, if you have that issue too, you can also remove unused language specific folders too. I've chosen to only trigger this under the build type "Release":
我也遇到了生成各种语言特定文件夹的问题,如果您也有这个问题,您也可以删除未使用的语言特定文件夹。我选择只在构建类型“发布”下触发它:
<ItemGroup>
<FluentValidationExcludedCultures Include="be;cs;cs-CZ;da;de;es;fa;fi;fr;ja;it;ko;mk;nl;pl;pt;ru;sv;tr;uk;zh-CN;zh-CHS;zh-CHT">
<InProject>false</InProject>
</FluentValidationExcludedCultures>
</ItemGroup>
<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />
<ItemGroup>
<XMLFilesToDelete Include="$(TargetDir)\*.xml"/>
<PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>
</ItemGroup>
<Delete Files="@(XMLFilesToDelete)" />
<Delete Files="@(PDBFilesToDelete)" />
</Target>
回答by ProVega
If you only want to exclude the XML files (for say a debug release) you can do something like this:
如果您只想排除 XML 文件(例如调试版本),您可以执行以下操作:
<AllowedReferenceRelatedFileExtensions>
<!-- Prevent default XML from debug release -->
*.xml
</AllowedReferenceRelatedFileExtensions>
Basically, each extension (delimited by a semi-colon) listed will be excluded.
基本上,列出的每个扩展名(以分号分隔)都将被排除在外。

