Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent Visual Studio from "publishing" XML documentation files in web projects?

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?

like image 523
Heinzi Avatar asked Feb 16 '12 15:02

Heinzi


People also ask

Where does XML go in Visual Studio project?

Add the XML file to Visual Studio Project Open up Visual Studio and create a new project or open an existing one. Add an existing item to the C# project. – Select the XML file we created earlier and press Add. – The file will be added to the project.

Where are publish settings stored in Visual Studio?

The PublishProfiles folder is under Properties in a C# web application project, under My Project in a VB web application project, or under App_Data in a web site project. Each .

Where are Pubxml files stored?

It's stored in the Properties/PublishProfiles/{PROFILE NAME}. pubxml. user file.

What does Visual Studio publish do?

Publishing creates the set of files that are needed to run your application. To deploy the files, copy them to the target machine.


3 Answers

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.

like image 53
Grant Thomas Avatar answered Nov 12 '22 04:11

Grant Thomas


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.

like image 35
Henk Holterman Avatar answered Nov 12 '22 03:11

Henk Holterman


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.

like image 21
mark Avatar answered Nov 12 '22 02:11

mark