C# conditional compilation if assembly exists

后端 未结 2 766
眼角桃花
眼角桃花 2021-01-15 05:53

I have a project with a reference that may or may not exist. I have code that uses that reference and I\'d like to compile it only if the assembly exists. I\'m thinking some

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-15 06:15

    No you cannot do this. You cannot define the result of a conditional compilation symbol at compile time.

    If you want to get fancy you could write a new program which detects the missing assembly and modifies your source. You can then execute this program in the Pre-build event of your project.

    The modification of the source could simply be the addition or removal of your suggested #define at the top of the source files.

提交回复
热议问题