I started to finally fix my place up a bit by grouping up commonly used functions into a single namespace so they can be used by many projects at once.

This question is related to three problems I am having:
  • Final executable size
  • Compatibility of PInvoke methods
  • Security (antivirus triggers)


Having all this common code means that a large portion of it is not used at all by the final application. However, there is a lot of interconnected calls (for example, from 'Path' to 'File' and 'Window' to 'User32') which means it is not possible to just delete the files not of interest. Since the executable contains so many PInvoke calls for Windows API, pretty much any antivirus will detect this and flag it as a virus, even though none of the code paths lead to these functions. It makes sense that an application with the ability to read text in other applications is a hazard, same for global keyboard hooks.

There is one solution to this, and it is commonly found when compiling C/C++ code: do not compile functions and classes that are not being used. I've found that the Visual Basic (or .NET compiler in general) is doing a poor job, if any, to exclude code from compiling when it is not being used.

Is there a way to configure the .NET compiler so it will not include unused functions in the final executable? If not, is there perhaps a tool available that can do it?
It is not a good idea to distribute programs to friends and then having to proof to them I'm not hijacking their installation after they receive 5 antivirus warnings.