C# Conditional assembly reference

If you want to include assemblies conditionally upon its preprocessor from c# project, you can use Condition keyword. See the following snippet.

  • xx.csproj

<Reference Condition=” $(DefineConstants.Contains(‘XXX_LIB_OS’)) ” Include=”DRVNAME1, Version=1.1.1.0, Culture=neutral, PublicKeyToken=xxxxx, processorArchitecture=AMD64″> … </Reference>

<Reference Condition=” $(DefineConstants.Contains(‘XXX_LIB_APP’)) ” Include=”APPNAME1, Version=1.1.1.0, Culture=neutral, PublicKeyToken=xxxxxxx, processorArchitecture=AMD64″> … </Reference>

  • Then define the constant

<PropertyGroup Condition=”‘$(Configuration)|$(Platform)’ == ‘Debug|x86′”> <DebugSymbols>true</DebugSymbols>
<OutputPath> … your output path… </OutputPath> <DefineConstants>TRACE;DEBUG;XXX_LIB_APP</DefineConstants>

</PropertyGroup>