Preventing referenced assembly PDB and XML files copied to output

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

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

I can exclude *.pdb when ZIP'ing but I cannot blanket exclude the *.xml files as I have deployment files with the same extension.

Is there a way to prevent the project from copying referenced assembly PDB and XML files?

Answers


You can also specify this via the command line:

MsBuild.exe build.file /p:AllowedReferenceRelatedFileExtensions=none

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.targets looking for something that would work and found the AllowedReferenceRelatedFileExtensions property. It defaults to .pdb; .xml so 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.

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

You can add a Post Build event command similar to del "$(TargetDir)YourAssembly*.xml", "$(TargetDir)YourAssembly*.pdb"


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.

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.


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.

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.


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" (TargetDir is a built in variable, included automatically) under the "Project" tag:

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

Why generate the .pdb and .xml files at all if you're not going to need them? You could just disable debug symbols and documentation file generation in your project's PropertiesBuild (→ Advanced…). (Probably just for the Release build.)


If you only want to exclude the XML files (for say a debug release) you can do something like this:

<AllowedReferenceRelatedFileExtensions>
  <!-- Prevent default XML from debug release  -->
      *.xml
 </AllowedReferenceRelatedFileExtensions>

Basically, each extension (delimited by a semi-colon) listed will be excluded.


Need Your Help

JSON to string variable dump

javascript jquery json variables

Is there a quick function to convert JSON objects received via jQuery getJSON to a string variable dump (for tracing/debugging purposes)?