Is it possible to add a link to a C # project depending on the value of the conditional compilation symbol (preprocessor constant)?

I am developing a library that can be compiled for two different technologies. In principle, library users should be able to compile a solution for either the Unity3D game engine or the NeoAxis game engine. The problem is that although the library is ready for conditional compilation (#if UNITY using ... #endif, etc.), I cannot find a way to include a set of links or another depending on conditional compilation symbols.

Can this be done? If so, how?

+3
source share
3 answers

Yes, but you have to do it in the msbuild.csproj file. This file is just a list of data, such as links.

What you do, add a Condition for both links.

<Reference ..a.. Condition="'$LibToUse' =='NeoAxis'" />


<Reference ..b.. Condition="'$LibToUse' =='Unitv3D'" />

Then simply define the var command line called LibToUse with the desired value.

+6
source

How to add a link with a conditional compilation symbol, as in the code. those. having or not setting, for example, UNITY in the project settings, he answers this post , and is simply done by editing your .csproj file, adding a condition to the link, and calling the DefineConstants.Contains () method :

<Reference Include="yourdll" Condition="$(DefineConstants.Contains('UNITY'))">
+2
source

Go ahead and add all the necessary links. They will be automatically deleted by the compiler if they are never used in your code, which will be thanks #if/#endif. Another possibility is to provide two different files .slnthat link to two different files .csprojthat point to the same source code, but to different links. These are many projects: SomeProject_VS2008.slnand SomeProject_VS2010.sln.

+1
source

Source: https://habr.com/ru/post/1769731/


All Articles