92

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.

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.

Humberto
  • 7,117
  • 4
  • 31
  • 46
  • 1
    To be clear, you added a reference to an assembly in add reference dialog. Now when you build the doc XML files show up in your output path? – Sayed Ibrahim Hashimi Oct 21 '10 at 00:52
  • 4
    possible duplicate of [Preventing referenced assembly PDB and XML files copied to output](http://stackoverflow.com/questions/2011434/preventing-referenced-assembly-pdb-and-xml-files-copied-to-output) – ShawnFeatherly Jul 01 '13 at 22:55

5 Answers5

124

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

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 AllowedReferenceRelatedFileExtensions to "-".

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.

Sayed Ibrahim Hashimi
  • 43,864
  • 17
  • 144
  • 178
  • It seems that you can set this in the .csproj file in the element: ".pdb".="" – Jay Sep 19 '13 at 12:22
  • 7
    Specifics on _how_ to specify this on the msbuild command line or in a project file: http://stackoverflow.com/questions/2011434/preventing-referenced-assembly-pdb-and-xml-files-copied-to-output – yzorg Dec 22 '14 at 20:15
  • 5
    Where in Visual Studio can we change the `AllowedReferenceRelatedFileExtensions` ? – Apostrofix Jan 19 '16 at 14:50
  • Does this still work with VS2015? Because it does not matter what I enter, looking at process explorer, `msbuild` is writing the xml accompanying files. Process Monitor shows `msbuild ... /p:AllowedReferenceRelatedFileExtensions=none`, so the argument is being set. – Hakkar May 31 '16 at 18:45
  • 2
    It would have been great to have a little more guidance here. But this post lead me to do more research on my own to find out how to get to this magical `AllowedReferenceRelatedFileExtensions` setting and found a better suggestion in my opinion. http://stackoverflow.com/a/2012506/1039753 – Arvo Bowen Dec 03 '16 at 23:01
0

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

It should be changing

<ItemGroup>

to

<ItemGroup Condition="'$(CONFIG)'=='RELEASE'">

or something like this.

Alex
  • 2,438
  • 23
  • 30
  • 3
    A Visual Studio project and solution file ARE MSBuild files. – AMissico Jun 10 '11 at 08:28
  • @AMissico Wrong, solution files are not MSBuild files. – julealgon Feb 26 '14 at 14:40
  • While they are not in the project file format (XML), they are still a support MSBuild file. Set the environment variable (`set MSBuildEmitSolution=1` or pass the property argument (`p:msbuildemitsolution=1`). – AMissico Feb 27 '14 at 00:36
-5

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.

Are both of those set?

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 2
    But to do this I'd have to add them as project items... or am I mistaken? – Humberto Oct 20 '10 at 18:23
  • .PDB and .XML files generated from the compiler should never be included in a project as you'll end up with recursive build errors and file locking. – Jamie Howarth Jun 09 '11 at 10:35
  • 1
    @codegecko did you see the "None"? they need to be adjacent to the source dll to get intellisense etc. I have *never* had a problem with this. – Marc Gravell Jun 09 '11 at 11:14
  • @Marc They need to be adjacent, yes, but it's a bad idea to include them in a project nevertheless. You also end up with file locking issues when the compiler tries to overwrite the files if the project is source-controlled. Referencing them from a folder location outside the project /bin directory, with XML files adjacent in the folder hierarchy, still results in those appropriate XMLs being included in your /bin when compiled, which still provides your Intellisense, without making your project effectively dependent on compiled output. – Jamie Howarth Jun 10 '11 at 12:42
  • 2
    @codegecko who said anything about the bin? I wouldn't reference from there... I usually referenc from a /lib, with the dll, XML and pdb. – Marc Gravell Jun 10 '11 at 14:35
  • 1
    Aaaaah, now the penny's dropped, I misunderstood. Including them in a /lib folder, referencing inside VS, adding the items to a solution folder, specifying output type as "None" - got it. Might start using that on my own projects actually - thanks! – Jamie Howarth Jun 12 '11 at 21:25
-5

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.

Russell McClure
  • 4,821
  • 1
  • 22
  • 22
  • 2
    The problem is that these files have no function besides aiding the IntelliSense feature. There's no point in including them with the release files. Besides, there's no installer involved... – Humberto Oct 20 '10 at 18:56
  • So how are you deploying your app? – Russell McClure Oct 20 '10 at 18:58
  • It's a single installation under our control, so we're deploying it by simply copying the files. – Humberto Oct 20 '10 at 19:10
  • 3
    So my solution would be to modify the copy script to not copy the files you don't want to copy. – Russell McClure Oct 20 '10 at 19:11
  • 2
    that would work for sure. But it's not the *ideal* solution, which would prevent the files from being copied in the build. I'm trying to understand the logic behind this behavior. Thanks! – Humberto Oct 21 '10 at 01:22
  • 4
    Good written XML documentation files are large. Copying them around on each build is shortening the life span of my SSD. – springy76 Jul 03 '12 at 16:09
-5

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.

bkaid
  • 51,465
  • 22
  • 112
  • 128
Jamie Howarth
  • 3,273
  • 3
  • 20
  • 26
  • 3
    This response in inaccurate. He is asking about pre-generated XML files that comes from a control vendor. Your response is only helpful if you are generating your own XML files. – Kevin Kalitowski Mar 02 '12 at 16:39
  • It seems that you can set this in the .csproj file in the element: ".pdb".="" – Jay Sep 19 '13 at 12:22