-1

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

arn9000
  • 133
  • 1
  • 10

2 Answers2

0

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).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
mdecode
  • 16
  • Revit migration to .net 6 or higher is now on their [road map](https://portal.productboard.com/s1ebfo2zoltimspd9rhy4l2j/c/397-revit-to-net-6-or-higher) (for what it's worth) – Leetheus Aug 29 '23 at 22:36
0

In summary, the answer is - IT'S NOT RECOMMENDED (because Revit's underlying technology is dependent on .NET Framework and it doesn't guaranty that everything will work)


Found the same question asked in Autodesk forum. Below is a quote from one of the answers given by the great Jeremy Tammik:

[Q] Will we be able to use the Revit API with .NET 5?

[A] The factory should try to be prepared to answer. So far, there are complications. Revit consumes Autodesk-wide .NET components. We'd need to ensure that those are .NET 5 compatible before we switch our runtime. Revit API also runs in-process using Revit's runtime, so I'm not sure it would be possible to preserve Revit's 4.8 runtime and allow add-in code to run .NET 5.0. We have not tested either scenario yet.

Basically, developers will be able to reference Revit's dlls (.NET 4.8) in their .NET 5 projects, but there is no guarantee that everything will work. Some (if not most) things might, but I would not recommend going that way. The problem is that .NET 5 is based on .NET Core, not on the big .NET framework, and there are some incompatibilities.

As for switching Revit to .NET 5, that's something we will definitely need to do as .NET 4.8 is the last version of the big .NET. However, the switch is not as trivial as changing the version dropdown (like it was from 4.7 to 4.8). We will have to convert to a new project format, fix some code and possibly find replacement for some frameworks that were present in .NET 4.8, but are not anymore in .NET 5.

I hope this helps.

Gangula
  • 5,193
  • 4
  • 30
  • 59