inexcitus
inexcitus

Reputation: 2649

Only compile certain parts of my program depending on the calling assembly

I have three assemblies. One assembly contains code that relies on the 'NETWORKING' COM service. This service is not available on some machines and I would like to only compile the code depending on the assembly that consume this assemblies.

I have two assemblies that rely on this shared assembly: One GUI and one CLI assembly. I tried to use the #define preprocessor check, but this only works within the same assembly (right?). The obvious yet time consuming choice would be to extract the code into a separate assembly.

I was wondering if there is another possibility. Just like defining symbols or something like. The CLI assembly would define the CLI keyword and the GUI assembly would define a keyword 'GUI'. In the shared assembly I could then use something similiar to

#if CLI
using NETWORKLIST;
#endif

Is this somehow possible in Visual Studio / C#?

Upvotes: 1

Views: 138

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064304

Assemblies are independent, so unless you're using the same "build" each time, the short answer would be "no, you can't do that". The most appropriate approach here is to move the relevant code to another assembly - which is probably less than 3 minutes work. Alternatively: just ignore it and accept that a few extra bytes of disk space are being used unnecessarily - it won't hurt.

Upvotes: 2

Related Questions