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>

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s