Multi-Version Visual Studio Revit Add-In Wizard

Developers often ask how to support multiple versions of a Revit add-in from the same codebase.

Many have implemented solutions for this using various Visual Studio project settings.

Alexander Ignatovich of

Investicionnaya Venchurnaya Companiya
went
one step further and implemented a version of the

Visual Studio Revit add-in wizard
that
automatically generates an add-in skeleton supporting both Revit 2013 and 2014 in the same Visual Studio project.

He is very kindly sharing is with us here, saying:

I have one another thing I want to share.
I found very nice way to support both Revit 2013 and Revit 2014.
I created a project wizard, based on the

Visual Studio Revit 2014 add-in wizards
.

Look at the csproj file. There are four build configurations in it:

  • Debug
  • Release
  • Debug2014
  • Release2014

First, I used choose tags to determine what reference should be used in the build configuration.
Unfortunately, there are some problems with $(ProgramW6432), so I replaced it with C:Program files.

Secondly, I defined a VERSION2014 compilation constant and add it as an example in Command.cs.

Thirdly, I add copying files to 2013 add-ins folder in post-build event.
Unfortunately, I can’t use choose tag there – it does not work – so the add-in files are copied to both 2013 and 2014 add-ins folders.

Lastly, StartProgram tags contain the proper Revit executable path for each build configuration.

Many thanks to Alexander for analysing, setting up and sharing this!

Here is an overview of the affected files in the highly recommended
kdiff3 file comparison tool:

Modified files

The differences in Command.cs are purely for testing purposes, reporting what release we compiled for in the Visual Studio debug output window:

Compiler pragmas

The differences in the main template file are pure syntactic sugar, affecting only the user interface display strings.

The only significant changes are the ones that Alexander describes above in the C# project file.

Here is Alexander’s
Revit2014AddinWizardCs3Ai.zip for
you to explore in detail for yourself.

Please note that this version of the wizard lacks the ResolveAssemblyWarnOrErrorOnTargetArchitectureMismatch tag that I added to suppress the

processor architecture mismatch warning
when
compiling for Revit 2014.

You could always post-process the resulting project files using my tool to

recursively disable the architecture mismatch warning
.

Support for Revit Flavours and Additional Assembly References

Alexander added some more details on the CSPROJ file editing:

I think it might be useful to briefly describe *.csproj file, maybe only the “Reference Include” tags for Revit API assemblies.

I specify an absolute path, because my Visual Studio 2010 sometimes does not correctly change the project configuration.

One issue with the references is that everybody has installed a different flavour of Revit.
I use the Revit Building Design Suite, which is located in C:Program FilesAutodeskRevit 2014 by default, other people may use Revit Architecture, Revit Structure or Revit MEP.
The default location of Revit Architecture is C:Program FilesAutodeskRevit Architecture 2014, and if there is no Building Design Suite on developers computer, the wizard template files need to be edited, replacing the reference paths in *.csproj.

Furthermore, if you want to reference additional Revit API assemblies, you can do so by adding them to the csproj file.
For example, if I want to add the Revit UIFramework assembly, I can open *.csproj in an external editor – my choice is

Notepad++

and add the Revit 2014 version to the Choose – When – ItemGroup tag:


<Reference Include="UIFramework">
<HintPath>C:Program FilesAutodeskRevit 2014UIFramework.dll</HintPath>
<Private>False</Private>
</Reference>

Similarly, add the Revit 2013 version to the Choose – Otherwise – ItemGroup tag:


<Reference Include="UIFramework">
<HintPath>C:Program FilesAutodeskRevit 2013ProgramUIFramework.dll</HintPath>
<Private>False</Private>
</Reference>

Here is what it looks like:

Additional UIFramework assembly reference

Today is the Last Day

Before closing, let me point out that we are reaching the end of another week, and today is the

deadline for submitting the handouts
for
my Autodesk University classes.
So I will do just that.

Let me also wish you a wonderful weekend.


Comments

One response to “Multi-Version Visual Studio Revit Add-In Wizard”

  1. Great info re using the Choose variables in the .csproj file! Thanks!
    One additional enhancement, it is possible to use if statements in the post build events to copy the resulting build only to the desired destinations. Thus:
    echo Configuration: $(Configuration)
    if $(Configuration) == Debug goto 2013
    if $(Configuration) == Release goto 2013
    if $(Configuration) == Debug2014 goto 2014
    if $(Configuration) == Release2014 goto 2014
    :2013
    echo Copying results to 2013
    copy “$(ProjectDir)RevitAddin2.addin” “$(AppData)\Autodesk\REVIT\Addins\2013”
    xcopy “$(TargetDir)RevitAddin2.dll” “$(AppData)\Autodesk\REVIT\Addins\2013” /k /e /y /r
    goto exit
    :2014
    echo Copying results to 2014
    copy “$(ProjectDir)RevitAddin2.addin” “$(AppData)\Autodesk\REVIT\Addins\2014”
    xcopy “$(TargetDir)RevitAddin2.dll” “$(AppData)\Autodesk\REVIT\Addins\2014” /k /e /y /r
    goto exit
    :exit

Leave a Reply

Discover more from Autodesk Developer Blog

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

Continue reading