Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Does anyone know if there is any way to remove all the references to a library in some builds of a C# .NET 4 project? I have tried using partial classes and methods and conditional compilation symbols etc.), but I can't figure out a way to remove the using statement from the main project, thus I end up still referencing an assembly I am not using.

I want to be able to have code which in a library (thus sharable between projects) but which can be included in the Debug build of the main project but completely removed from the Release build. I come from many years of using C++, where doing this was very easy, and I find it hard to believe the same thing is not possible in C#. It seems like a reasonable requirement to me when the speed and code size of the Release executable are important design issues.

Any help or pointers to useful information would be very much appreciated.


Kind wishes, Patrick
Posted

1 solution

You could use "precompiler" directives:
C#
#if DEBUG
using your.library.assembly
#endif

You could also late bind with your library based on phisical availablity of assembly file.
You could also use Dependancy Injection to provide "stub" types for your assembly.

I think there are several approaches you could use based on your requirements.
 
Share this answer
 
v2
Comments
Patrick Skelton 7-Apr-12 5:20am    
Hi,

Thank you for that.

Yes, it seems that using a combination of partial classes and 'precompiler' directives, it is possible to create a main assembly that contains no references to the debug assembly library and therefore can be deployed without the library .dll.

Kind wishes, Patrick

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900