With Rhino 8, we can now compile our .NET plugins for .NET 4.7, .NET Core 7, and .NET Core 8. Do you have a guide or recommendation on how we could distribute them? My goal is to create a single installer that works seamlessly for all three versions, without requiring any additional setup from the user. Is this achievable? Thank you very much in advance!
Rafa
Rafael,
Not sure, but maybe this post will help you.
– Jason
hey Rafa – it is indeed possible, given that for my plugin I have a single rhp each for windows & macos (along w/native lib & dotnet wrapper dlls for render sdk & core), which supports rhino 6/7/8, on x64 for windows, and x86_64/arm64 universal for macos; the plugin works regardless which rhino tries to load it, whether it was started with /netfx or not, running under rosetta on macos or not
technically, the major points are that I target a v6 rhinocommon, restrict myself to dotnet apis that are common to v4.7.2 and .net 7, and use reflection in cases where I want to use something added in rhinocommon v7 or v8, or where I cannot avoid using something from .net 7 (e.g. the roslyn compiler)
to make this a bit more concrete, here are the first parts of my csproj files:
windows
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<ProjectGuid>{<removed>}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>bella_rhino</RootNamespace>
<AssemblyName>bella_rhino</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<Prefer32Bit>false</Prefer32Bit>
<ErrorReport>prompt</ErrorReport>
<PlatformTarget>x64</PlatformTarget>
</PropertyGroup>
...
macos
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{<removed>}</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>bella_rhino</RootNamespace>
<AssemblyName>bella_rhino</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<TargetFrameworkProfile />
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunPostBuildEvent>Always</RunPostBuildEvent>
<Prefer32Bit>false</Prefer32Bit>
<ErrorReport>prompt</ErrorReport>
<!-- important: mac rhino 8 will not load if this is x64 -->
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
...
I never use the project editor, I always just edit csproj manually, so that some visual studio update doesn’t decide to give me trouble; it may be possible to get this all working using “sdk” style csproj files but I did not immediately have luck with that, and there is no payoff, so did not waste time with it
so anyway this is one way – I hope it helps
If you haven’t already, I recommend taking a look at the updated Rhino 8 project templates for Visual Studio from McNeel (https://github.com/mcneel/RhinoVisualStudioExtensions). They multi-target and include a yak packaging step. Yak will install all of framework versions included in the package.