Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to safely build addins that use CEFsharp for multiple Revit versions

10 REPLIES 10
Reply
Message 1 of 11
hzamani
1963 Views, 10 Replies

How to safely build addins that use CEFsharp for multiple Revit versions

It was officially announced that Revit 2020 uses CEFsharp version 65.0.1, whereas Revit 2019 uses version 57.0.0

If you are using CEFsharp in your addin and looking to update your solution to be able to build separately for 2020 you will then need to add multiple versions of this package to your solution. This is not possible afaik but there's a workaround which I'll share below. But before you apply it read here as some packages are not compatible with this solution. (Also I'm assuming that you already know how to modify your solution to be able to build for multiple Revit versions - i.e. including different versions of RevitAPI.dll and RevitAPIUI.dll in your project - If not or you'd like to learn more check Konrad Sobon's great write up here: http://archi-lab.net/how-to-maintain-revit-plug-ins-for-multiple-versions/). 

 

So, to add different versions of the same package to your project:

- You'll need VS 2019 or to be correct VS 2017 version 15.7 and later

- Write click on packages.config and click on Migrate packages.config to PackageReference...., complete step-by-step instructions here: https://docs.microsoft.com/en-us/nuget/reference/migrate-packages-config-to-package-reference#migrat...

- Save your solution.

- Open the .csproj file in a text editor (assuming you're using C#)

- Modify .csproj to include the following conditions:

 

<ItemGroup>
    <PackageReference Include="cef.redist.x64" Condition="'$(Configuration)' == 'Debug 2020' Or '$(Configuration)' == 'Release 2020'">
      <Version>3.3325.1758</Version>
    </PackageReference>
    <PackageReference Include="cef.redist.x86" Condition="'$(Configuration)' == 'Debug 2020' Or '$(Configuration)' == 'Release 2020'">
      <Version>3.3325.1758</Version>
    </PackageReference>
    <PackageReference Include="CefSharp.Common" Condition="'$(Configuration)' == 'Debug 2020' Or '$(Configuration)' == 'Release 2020'">
      <Version>65.0.1</Version>
    </PackageReference>
    <PackageReference Include="CefSharp.Wpf" Condition="'$(Configuration)' == 'Debug 2020' Or '$(Configuration)' == 'Release 2020'">
      <Version>65.0.1</Version>
    </PackageReference>
    <PackageReference Include="cef.redist.x64" Condition="'$(Configuration)' == 'Debug 2019' Or '$(Configuration)' == 'Release 2019'">
      <Version>3.2987.1601</Version>
    </PackageReference>
    <PackageReference Include="cef.redist.x86" Condition="'$(Configuration)' == 'Debug 2019' Or '$(Configuration)' == 'Release 2019'">
      <Version>3.2987.1601</Version>
    </PackageReference>
    <PackageReference Include="CefSharp.Common" Condition="'$(Configuration)' == 'Debug 2019' Or '$(Configuration)' == 'Release 2019'">
      <Version>57.0.0</Version>
    </PackageReference>
    <PackageReference Include="CefSharp.Wpf" Condition="'$(Configuration)' == 'Debug 2019' Or '$(Configuration)' == 'Release 2019'">
      <Version>57.0.0</Version>
    </PackageReference>
</ItemGroup>

(Obviously you need to rename the configuration name from "Debug 2019", "Release 2019" and so on, to the name of the configuration that you have in your project)

- Save .csproj file

- Reload solution and build to the Revit 2020 configuration.

 

You don't actually need to install CEFsharp version 65.0.1. The resulting dll's should work fine with Revit 2020. If you have a better suggestion would love to hear about it.

 

Cheers.

Hoss Z.

10 REPLIES 10
Message 2 of 11
jeremytammik
in reply to: hzamani

Dear Hoss,

 

Thank you very much for this valuable solution.

 

Have you seen this alternative suggestion by Kim Sivonen to use IPC to address this?

 

https://thebuildingcoder.typepad.com/blog/2019/04/set-floor-level-and-use-ipc-for-disentanglement.ht...

 

I would be interested to hear what you think about that.

 

Thank you!

 

Best regards,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 11
hzamani
in reply to: jeremytammik

This is really nifty!

 

So if I understood correctly, advantage of this method is that, because CEFsharp is running as its own process, it would enable any version of CEFsharp to run inside a Revit addin and rectify compatibility concerns altogether?

 

 

Message 4 of 11
jeremytammik
in reply to: hzamani

Yes, almost, not quite... 

 

it would enable any version of CEFsharp to run inside a Revit addin...

 

> it would enable any version of CEFsharp to run outside a Revit addin...

 

The Revit add-in runs inside the Revit.exe process.

 

Using IPC, interprocess communication, you can implement a separate external process to host the CEF stuff and use IPC to make its functionality available to another process, e.g., the Revit add-in, without interfering with it otherwise.

 

Cheers,

 

Jeremy 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 5 of 11
mastjaso
in reply to: jeremytammik

Hi Jeremy, interesting that IPC is coming up again, you had suggested it for my similar question about strong naming and ensuring DLL loading.

I looked into it a little bit, it looks very similar to an approach I had already been toying with that used websockets, but my question would be, from a practical add-in design standpoint, does it make more sense to hive off each support DLL into it's own process, or just run your entire application in it's own process and only keep a light "Revit isolation layer" that deals with marshalling data to and from Revit that runs within Revit's process?

 

In that sense you can use strong naming and whatever support DLLs you want with a guarantee that you'll get the right ones, plus there are the other benefits to keeping Revit as the isolated, single process one, in that you can then easily have modeless windows, and do things like multithreaded processing on your data etc.

 

Message 6 of 11
jeremytammik
in reply to: mastjaso

Dear Jason,

 

Thank you for your interesting suggestion.

 

I fully agree with your thoughts.

 

This Revit isolation layer may grow quite large if you have a lot of interaction with Revit.

 

In that case, it may be more efficient to integrate larger portions of functionality into the Revit add-in.

 

It depends totally on your exact needs.

 

I think both approaches are absolutely viable, and you will always end up with a mix.

 

It is great to be aware of this option, and be able to make such a choice.

 

Cheers,

 

Jeremy

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 7 of 11
boostyourbim
in reply to: hzamani

This didn't work for me and the Microsoft documentation says:

https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

You can use a condition to control whether a package is included, where conditions can use any MSBuild variable or a variable defined in the targets or props file. However, at presently, only the TargetFramework variable is supported.

Elsewhere it is suggested that the Choose/When syntax is the right solution (https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-conditional-constructs?view=vs-2019)

Message 8 of 11

Hi Jeremy,

 

I have a dockable panel that has a WPF that uses CEFSharp.

Can I use IPC?

Message 9 of 11

In general, you would use IPC to communicate between a Revit add-in and an external stand-alone application. You can use it anywhere you want, though.

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 10 of 11
jeremytammik
in reply to: boostyourbim

@boostyourbim Thank you for the heads-up. Did you solve it yet, e.g., using Choose/When, or in any other way?

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 11 of 11

Thank you!

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Customer Advisory Groups


Rail Community