June 28, 2018

Multi-Targeting Revit Versions, CAD Terms, Textures

Here comes another solution for efficiently compiling add-ins for multiple Revit version targets from one single code base, a note on resources for CAD term databases for consistent terminology translation, and a discussion on accessing custom texture maps in Forge and Revit:

Today, Olivier 'Vilo' Bastide of BBS Slama, éditeur de logiciels de calculs thermiques,
thermal calculation software editor, suggests a different and simpler approach making use of the TargetFrameworks functionality, and a further enhancement to that using the Import tag.

In his own words:

I'd like to give you some new stuff I've recently found, that can vastly simplify Revit add-in deployment.

This is about add-in multi-targeting.

Targeting all Revit versions can become a nightmare in terms of VS projects.

I'm personally developing 6 projects for Revit, and I have to compile each one for all Revit versions (2016 to 2019), resulting in 24 projects to maintain.

Source code is (thankfully) unique using conditional coding, but having all these projects is not elegant at all.

By using the new TargetFrameworks mechanism, it is possible to configure separate settings for each version.

Actually, the trick is possible because each Revit version is targeting a different .NET framework...

I've included 'non-mandatory' things in the above example.

For example, the AssemblyName tag is optional, but I've included it to show how to change the output DLL filename according to the Revit version.

When a new Revit version is released, the only thing to do is to declare a new target in the TargetFrameworks tag and configure the matching ItemGroup to tell VS where to find new SDK's DLLs.

If the new version does not target a different .NET framework, it is possible to keep the thing working by targeting a sub-version (like 4.7.1).

Finally, to make your source code version agnostic, you can use conditional definitions such as REVIT2017, REVIT2018, REVIT2019, etc., as usual.

Hope this will help.

Further Enhancement Using the CSPROJImport Tag

MultiTarget addins : season 01 episode 02...

Here is an addendum to my preceding suggestion with a further enhancement.

In the eternal fight to reduce efforts involved to obtain the same achievements, I've made some new progress.

The csproj format (both old and new) supports a kind of sequential inheritance through the tag <Import>.

Using that, you can tailor a 'root' .csproj file that contains all the basic logic about Revit versions, and then inherits from it in each of the 'real' projects, overriding only the specific varying tags.

Here is a sample root csproj, named C:\ROOT.CSPROJ for this sample to work:

This one is suitable to compile for Revit versions 2016 to 2019 (by targeting 4 different frameworks).

And here is a sample child project using it:

<Project><!-- this group must stay before <Import> !! --><PropertyGroup><!-- this tag allows generic naming, for example this will lead to assemblies named "SomeAssembly_2016", "SomeAssembly_2017", ... --><PrefixAssembly>SomeAssembly</PrefixAssembly><!-- by setting this tag here, you can override default behaviour that is to compile for versions 2016 to 2019
Delete it to restore default behaviour and compile for 2016 to 2019 --><TargetFrameworks>net452</TargetFrameworks></PropertyGroup><!-- import root csproj --><ImportProject="C:\ROOT.CSPROJ"/><!-- FQPN to file defined above --><!-- all other stuff that is project specific -->
...
</Project>

Of course, these 2 samples are just a proof of concept, and tailored for my own needs.

Feel free to make what you want with it ;-)

Many thanks to Olivier 'Vilo' for researching and sharing this very sensible solution!

Vilo responds: Cool ;-) Hope it will help some people simplify their DevEnv.

Jeremy answers: if people take the trouble to read and the time to improve, it will for sure :-) all too often, however, one does not take the time to improve things, even though it would save ten times the time it costs to make the improvement...

CAD Terminology Resources for Consistent Translation

People occasionally ask for help translating CAD terms, and I already mentioned a couple of useful resources for this in the past.

Question: I want to use the correct Autodesk terms in our localized add-in user documentation.

I am searching for a table of translations of Revit and AutoCAD terms into multiple languages which can be used for our automated translation dictionary. I just need a mapping English term → Localized term. The supported languages are currently German, French, Spanish (Mexico), Chinese (Simplified), Portuguese (Brazil), Japanese and Italian.