Is there a way to specify assembly references based on the assembly configuration in Visual Studio?

I have a project that adds some extensibility to another application through their API. However, I want to be able to use the same project for several versions of my application, because most of the code is the same.

However, for each version of the application, a link to the corresponding assembly for this version of the software is required. They load their assemblies into the GAC, so even if I could specify the version of the assembly to use based on the assembly configuration, everything would be okay. Is there a way to do this from inside VS or do I need an external build tool?

+44
reference build-process visual-studio assemblies
Nov 23 '09 at 23:55
source share
2 answers

There is a way to do this, but you will have to manually edit the project files. Project files can have the Condition attribute applied to them in many elements, including for links.

You can add them to your links to indicate when to use the link:

 <Reference Include="Product, Version=1.0.0.0" Condition="'$(Configuration)'=='V1'"> </Reference> <Reference Include="Product, Version=2.0.0.0" Condition="'$(Configuration)'=='V2'"> </Reference> <Reference Include="Product, Version=3.0.0.0" Condition="'$(Configuration)'=='V3'"> </Reference> 

Then you define several assembly configurations ( V1 , V2 , V3 ), and each link will be included only in the corresponding selected assembly configuration.

Combine this with conditional compilation symbols and #if statements in your code, and you can do what you want.

Care should be taken if you do this because Visual Studio can easily remove conditional attributes from a project file.

+53
Nov 24 '09 at 0:36
source share
 <Reference Include="log4net, Version=1.2.11.0, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\SharedLibs\log4net\$(Platform)\$(Configuration)\log4net.dll</HintPath> </Reference> 

You can replace the tooltip path with properties:

$ (Configuration) is equivalent to Release / Debug or any other configuration you have. $ (Platform) is equivalent to x86 / x64 / Any CPU

If your configuration includes Any CPU, you will need to put single quotes around $ (Configuration)

Also refer to the condition parameters referenced by adrianbanks

+8
Dec 19 '13 at 7:37
source share



All Articles