Search code examples
c#.netvisual-studiowinformsdotpeek

How to stop comments being included in C# release build .exe


To my perhaps naïve surprise, decompiling (using dotPeek) a large .NET 8, C#, WinForms app that I have been working on for many months - every single one of my comments was preserved.

Built in VS 2022, 17.8.0.

"Ah", I said... "it's a debug build, my bad, switch to Release".

To my even greater surprise, all the comments were preserved in a Release build too?

I've found multiple sources on the web, including here on SO that state Release strips out comments, such as this, except - that appears to be very much not the case.

What gives? How to exclude comments from a Release build? I suspect it's me, not you...

Screenshot below, all I've done to generate this is build the Solution in VS, then drag the Release .exe straight into dotPeek, and navigate in the left pane to the file that's shown in VS.

enter image description here


Solution

  • After installing the current dotPeek and attempting to repro this with a Debug-mode .dll of my own, and seeing my own (non-XML) comments repeated verbatim I quickly deduced it's just dotPeek's feature to show you the actual source-files using the file-paths embedded in the PDBs.

    enter image description here

    So, no, your built project output assemblies/executables do not contain your comments.