[Tip] How to make the reference to the dll accompanying xml comments document, pdb debug library and other files do not appear in the project output directory
The project output directory (bin/debug|release) often looks like this.
main.exe main.pdb a.dll a.xml b.dll b.pdb b.xml ...
Where xml is the annotation documentation for the dll of the same name and pdb is the debugging library. We should only want the exe and dll eventually, and besides deleting them manually, there are two tricks I know of to keep the xml and pdb from appearing after the project is generated:.
1. Use the project [Generate Events]. There is a generated event in the project properties, with two events, pre and post, so you can write the delete statement in the post event. Supported here are cmd command line statements, example.
del /f /q /a $(TargetDir)a.xml del /f /q /a $(TargetDir)b.pdb rem can also be used with the wildcard character del /f /q /a $(TargetDir)x?x*.xml
One problem, which doesn't work for web projects, is that it's gone from the local bin directory, but the bin directory on the server will have it. I guess the web project publishing action is not first into the local bin, and then copy the past, but possibly first into a temporary directory, and then copy from the temporary directory to the bin and remote respectively, so only delete the bin in the unhelpful, the key is to delete the temporary directory, I guess is the obj directory, practice another day, a clear friend hope to be able to guide. I had previously used this trick until today when I learned the following new trick.
2. Add element nodes to the project csproj fileAllowedReferenceRelatedFileExtensions . The details are as follows.
<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> ...
AllowedReferenceRelatedFileExtensions As you can see from the name, it is dedicated to this (compared to what generating events can do), the parent element PropertyGroup is usually divided into two nodes Debug and Release (the example above is the Release node), Allow... element added to Debug will work when generating the debug version, same for release, can be added to both debug/release, or can have different configurations, e.g. allow pdb for debug and block it for release. .allowedextension is the type of files allowed to be included, e.g. .pdb means pdb files are allowed to be included, then pdb may appear in the bin. Multiple types can be separated by semicolons, such as .pdb;.xml, so that both pdb and xml are allowed to be included.Wildcard not supported ; leaving it blank would be any file allowed, so if you want to block pdb and xml, you have to get an extension other than them both, like .allowedextension above. BTW, learned this trick from stackoverflow.http://stackoverflow.com/questions/2011434/preventing-referenced-assembly-pdb-and-xml-files-copied-to-output。
It should be noted that whether the project's own pdb and xml are generated or not is correctly set in [Project Properties Generation]. The Generate Event method works on the project's own related files, but Allow... The element method does not, it is only valid for the files associated with the referenced assembly.