Search code examples
revit-api.net-5

Revit api and .net 5


I wonder if it is possible to use .net5 to develop plugins for revit since the native platform for developing a plug-in for Revit is net47.

A simple test case showing a message in 2 different ways, MessageBox from PresentationFramework and TaskDialog from Revit api

    public class RevitExternalCommand : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            //MessageBox.Show("net 5 test");
            TaskDialog.Show("net 5 test", "Revit");

            return Result.Succeeded;
        }
    }

When TaskDialog.Show("net 5 test", "Revit") is used everything is ok. The message show when command starts.

MessageBox.Show("net 5 test") do not work because "could not load file or assembly" error:

enter image description here


Solution

  • From what I find online and understand, it seems that using .NET 5 is not guaranteed to work with the Revit API (currently on .NET Framework 4.8): Code that is compatible with .NET Framework 4.8 should work. However, while .NET 5 and .NET Framework 4.8 seem to fully include .NET Standard 2.0 and while there is a ".NET Framework compatibility mode" allowing for .NET Standard projects to reference .NET Framework projects (https://learn.microsoft.com/en-us/dotnet/standard/net-standard), that compatibility mode is not guaranteed to work with all .NET Framework projects, depending on what those projects are using (e.g. WPF). Thus, I think there is a risk that the Revit API might use parts of .NET Framework 4.8 that are not fully .NET Standard compliant and not covered by that "compatibility mode" (such as WPF). This is also how I interpret the answers on https://thebuildingcoder.typepad.com/blog/2021/01/face-triangulation-lod-net-5-and-core.html

    I guess that, as long as Revit doesn't migrate its API to .NET 5, the add-ins should be targeting .NET Framework, but they could reference .NET Standard 2.0 libraries of course, making those libraries more easily re-usable for other other projects that are not made in .NET Framework.

    This is the route I am following in general, putting as much of my codes as possible in .NET Standard 2.0 libraries (for compatibility reasons) and using .NET Framework only when really needed (e.g. because of links with existing API's in .NET Framework).