防止引用的程序集PDB和XML文件复制到输出

我有一个Visual Studio 2008 C#/。NET 3.5项目,该项目带有后期构建任务以压缩内容。但是我发现我还在输出目录(和ZIP)中获取了引用程序集的.pdb(调试)和.xml(文档)文件。

例如,如果MyProject.csproj引用YourAssembly.dll,并且在与DLL相同的目录中有YourAssembly.xml和YourAssembly.pdb文件,它们将显示在我的输出目录(和ZIP)中。

ZIP压缩时可以排除* .pdb,但不能覆盖* .xml文件,因为我具有具有相同扩展名的部署文件。

有没有一种方法可以防止项目复制引用的程序集PDB和XML文件?


米脂
浏览 674回答 3
3回答

饮歌长啸

您也可以通过命令行指定此名称:MsBuild.exe build.file /p:AllowedReferenceRelatedFileExtensions=none

catspeake

我希望能够在主应用程序中添加和删除引用的程序集,同时避免维护需要删除或排除的文件。我通过Microsoft.Common.targets寻找可行的东西进行了挖掘,并找到了该AllowedReferenceRelatedFileExtensions物业。它默认为,.pdb; .xml因此我在项目文件中明确定义了它。要注意的是您需要一些东西(空格是不够的),否则它将仍然使用默认值。<Project ...>&nbsp; <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">&nbsp; &nbsp; ...&nbsp; &nbsp; <AllowedReferenceRelatedFileExtensions>&nbsp; &nbsp; &nbsp; <!-- Prevent default XML and PDB files copied to output in RELEASE.&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Only *.allowedextension files will be included, which doesn't exist in my case.&nbsp; &nbsp; &nbsp; &nbsp;-->&nbsp; &nbsp; &nbsp; .allowedextension&nbsp; &nbsp; </AllowedReferenceRelatedFileExtensions>&nbsp;&nbsp; </PropertyGroup>

神不在的星期二

我对其他答案不太满意,我终于想出了如何使用内置的“ Delete”命令在实现中执行此操作,显然,您需要使用一种特定的方式来实现通配符,这 有点细微差别,这是您需要将所有内容放入“项目”标签下的“ CSPROJ”(TargetDir是一个内置变量,自动包含在内):<Target Name="RemoveFilesAfterBuild">&nbsp; &nbsp;&nbsp; &nbsp; <ItemGroup>&nbsp; &nbsp; &nbsp; &nbsp; <XMLFilesToDelete Include="$(TargetDir)\*.xml"/>&nbsp; &nbsp; &nbsp; &nbsp; <PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>&nbsp; &nbsp; </ItemGroup>&nbsp; &nbsp; <Delete Files="@(XMLFilesToDelete)" />&nbsp; &nbsp; <Delete Files="@(PDBFilesToDelete)" /></Target>我在生成各种特定于语言的文件夹时也遇到了麻烦,如果您也遇到该问题,也可以删除未使用的特定于语言的文件夹。我选择仅在构建类型“发布”下触发此操作:<ItemGroup>&nbsp; &nbsp; <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">&nbsp; &nbsp; &nbsp; &nbsp; <InProject>false</InProject>&nbsp; &nbsp; </FluentValidationExcludedCultures>&nbsp;</ItemGroup><Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">&nbsp; &nbsp; <RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />&nbsp; &nbsp; <ItemGroup>&nbsp; &nbsp; &nbsp; &nbsp; <XMLFilesToDelete Include="$(TargetDir)\*.xml"/>&nbsp; &nbsp; &nbsp; &nbsp; <PDBFilesToDelete Include="$(TargetDir)\*.pdb"/>&nbsp; &nbsp; </ItemGroup>&nbsp; &nbsp; <Delete Files="@(XMLFilesToDelete)" />&nbsp; &nbsp; <Delete Files="@(PDBFilesToDelete)" /></Target>
打开App,查看更多内容
随时随地看视频慕课网APP