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:

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 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 Files\Autodesk\Revit 2014 by default, other people may use Revit Architecture, Revit Structure or Revit MEP. The default location of Revit Architecture is C:\Program Files\Autodesk\Revit 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 Files\Autodesk\Revit 2014\UIFramework.dll</HintPath>

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

  <Reference Include="UIFramework">
    <HintPath>C:\Program Files\Autodesk\Revit 2013\Program\UIFramework.dll</HintPath>

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.