I am developing a library which can be compiled for two different technologies. Basically, the users of the library should be able to compile the solution either for the Unity3D game engine or the NeoAxis game engine. The problem is: while the library is ready for the conditional compilation (#if UNITY using ... #endif, etc.), I can't find a way to enable a set of references or the other depending on the conditional compilation symbols.
Is it possible to do it? If so, how?
Yes but you have to do this in the msbuild .csproj file. This file is essentially just list of data, such as references.
What you do is add a Condition statement to both References.
<Reference ..a.. Condition="'$LibToUse' =='NeoAxis'" />
<Reference ..b.. Condition="'$LibToUse' =='Unitv3D'" />
Then just define command line var called LibToUse with the desired value.
How to add a reference by conditional compilation symbol only like you do in code. i.e. having or not having set for example UNITY in the project settings is answered in this post, and is simply done by editing your .csproj file, adding a Condition to the reference, and calling the DefineConstants.Contains() method like so:
<Reference Include="yourdll" Condition="$(DefineConstants.Contains('UNITY'))">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With