How to conditionally link to a DLL based on a compilation symbol?

Visual Studio 2013.

I have an external DLL that I reference in the csproj file:

<ItemGroup> <Reference Include="NameOfDll"> <HintPath>Path\To\Dll\NameOfDll.dll</HintPath> </Reference> 

I want this link to function when the compiler symbol exists and not function when this compiler symbol does not exist. (To answer the first comment, below, let's say the compiler symbol is called Fred.)

This question [ Conditional link ] made me think that I can add the Condition attribute to the link element shown above, but I can’t determine what value this attribute will give to accomplish what I want.

I would be very happy if you would be given a way to do this in the VS UI, but I will take any method.

+13
c # visual-studio-2013 csproj compiler-directives
source share
1 answer

Conditional compilation characters are in the DefineConstants MSBuild property. Make sure this contains your character:

 <Reference Include="NameOfDll" Condition="$(DefineConstants.Contains('Fred'))"> <HintPath>Path\To\Dll\NameOfDll.dll</HintPath> </Reference> 

Select a distinguished name for the character. Not that it can be a substring of another constant, such as Debug or Trace.

+21
source share

All Articles