Switching assembly references based on build configuration

By Balaji Ramamoorthy

Recently, a developer came up with this query :

Is there a simple way to have a single copy of my code configured to compile to different folders with different references based on the desired version of AutoCAD to be run ?

This is not strictly an AutoCAD API related query but it is very relevant to how we build plugins for AutoCAD. It is a common requirement that we add references from different paths based on the AutoCAD version for which we are building the plugin.

A simple way to get this working is to create separate build configurations in your Visual Studio solution.

Now, open the .csproj in a text editor and manually include the "Condition" for each of the references.

As an example, here is the change to include different versions of the interop assembly for Sheetset manager for each build configuration.

<Reference Include="Interop.ACSMCOMPONENTS20Lib" Condition="'$(Configuration)'=='Debug2015'">
<HintPath>........\ObjectARX 2015\inc-x64\ACSMCOMPONENTS20Lib.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>
<Reference Include="Interop.ACSMCOMPONENTS20Lib" Condition="'$(Configuration)'=='Debug2016'">
<HintPath>........\ObjectARX 2016\inc-x64\ACSMCOMPONENTS20Lib.dll</HintPath>
<EmbedInteropTypes>True</EmbedInteropTypes>
</Reference>

If you are using any other technique to achieve this already, please do share by posting your comments. I am sure that will help many other developers. Thank you.


Comments

2 responses to “Switching assembly references based on build configuration”

  1. This has been discussed a lot at The Swamp. See http://www.theswamp.org/index.php?topic=50202.0 and have a look at the other threads linked in the first post for a variety of approaches.
    I wrote Code Linker (it’s on that Swamp link) because the housekeeping got too unwieldy with a lot of build configurations and phantom project references (see http://www.theswamp.org/index.php?topic=49039.msg541744#msg541744) but I think different approaches will work for different people in different situations.

  2. Thanks for sharing the Code Linker and that detailed discussion.
    There is a treasure of information in that post.
    Regards,
    Balaji

Leave a Reply to BalajiCancel reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading