11

Note: This question is similar to How to prevent the copy of XML documentation files in a release mode build?, but it's not the same and the answers there don't apply. Read on to find out why. (Please ask in the comments or in chat if you disagree, I'll be glad to elaborate).


I have a library project (myLibrary) and an ASP.NET web application project referencing this library (both are in the same solution). "Generate XML documentation file" is checked for the library project, because I want to have those nice IntelliSense features while developing.

When I publish the web application (Context Menu on the project/Publish...), it copies only the files required for running the application (no source code, etc.) to some publish directory. That's good. Unfortunately, it also copies the XML documentation file of the library. Since I consider our library's documentation to be a trade secret, I wouldn't want it to end up on a customer's server. Thus, we have to remember to manually remove this file from the publish directory before deploying it.

Is there a way to prevent Visual Studio from copying this file when publishing the ASP.NET project, but still retain the benefit of XML documentation IntelliSense when developing?

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Heinzi
  • 167,459
  • 57
  • 363
  • 519

5 Answers5

10

Assuming you're using distinct configurations for development and release (and whatever else), unchecking 'XML documentation file'/turning off generation for a specific configuration would prevent it being deployed when not needed. Another option would be a post-build action to delete the file/s.

The former of those two options seeming more elegant.

Grant Thomas
  • 44,454
  • 10
  • 85
  • 129
  • It's not ideal, since (a) you need to manually edit the vbproj file to set this value differently for debug/release and (b) you miss some Intellisense features when coding while "Release" is set, but it seems to be the best option so far. – Heinzi Feb 20 '12 at 13:17
  • @Heinzi I'm not convinced you can't do this per configuration within the UI, but you've got me thinking of doing a sanity check. ...Sanity checked: this _can_ be specified per configuration in the UI. – Grant Thomas Feb 20 '12 at 13:33
  • 1
    I just checked as well: You can do it for C# projects but not for VB projects. In VB projects, the setting is used for *all* configurations (unless you manually override this in the vbproj file -- then the checkbox in the UI shows "the indeterminate state"). – Heinzi Feb 20 '12 at 14:16
  • @Heinzi My apologies, I wasn't so thorough to check a VB.NET project. – Grant Thomas Feb 20 '12 at 17:22
4

There is another solution. Just include the following in your csproj file somewhere in the beginning:

<AllowedReferenceRelatedFileExtensions>.pdb</AllowedReferenceRelatedFileExtensions>

That's it. XML files will no longer be published. Of course, you can make it conditional on the concrete configuration.

mark
  • 59,016
  • 79
  • 296
  • 580
  • 2
    Note: this change will stop .config files from referenced assemblies (in the same solution) from being outputed. – Lyra Apr 26 '17 at 13:45
4

Is there a way to prevent Visual Studio from copying this file when publishing the ASP.NET project,

Turn XML docs off in Release mode

but still retain the benefit of XML documentation IntelliSense when developing?

Turn XML docs on / off in Debug mode. Intellisense will work either way.

H H
  • 263,252
  • 30
  • 330
  • 514
  • I disagree on your last sentence: Method summaries are *not* shown if XML docs are turned off for the libary (just tested it: turn off, clean project, write code). – Heinzi Feb 16 '12 at 15:52
1

I'm doing this in Express, but this seemed to work for me...

  1. Went to Properties (for the Project)
  2. Clicked Publish Tab
  3. Click Application Files button
  4. Checked Show All Files
  5. Set xml File to Exclude

As I said, using Express 2010, but this worked (it didn't copy the file to the Publish location).

APrough
  • 2,671
  • 3
  • 23
  • 31
  • Thanks, but this only works for Windows application projects, not for Web applications. They have a different publishing process and, as far as I can see, you cannot configure individual files there. – Heinzi Feb 16 '12 at 16:26
  • 1
    Ah, missed that part. Sorry. – APrough Feb 16 '12 at 16:28
0

You can do this by adding the addon Web deployment project on visual studio which can be downloaded from here: http://www.microsoft.com/download/en/details.aspx?id=19995 and to exclude whatever files/folders you need please follow the steps found here

Alex
  • 5,971
  • 11
  • 42
  • 80