How to make a package work on old/new versions of Dynamo together with the same code?

I don’t have specific code to test this but I would like to create a zero touch that would work on both previous versions of Dynamo and new ones, identifying .NET and so on… does anyone have an example of how I could do this with the same code or something like that?

Hey,

If you have a look on github, you can see how different package authors manage this. Archilab has a set of nodes per version and targets the appropriate .net framework, determined at runtime (I believe!)…

namespace test.example
{
    public class SampleClass
    {
        public static string GetSampleInfo()
        {
            Document doc = DocumentManager.Instance.CurrentDBDocument;
            string version = doc.Application.VersionNumber;

            if (int.TryParse(version, out int versionNumber))
            {
                if (versionNumber < 2021)
                {
                    return RunForOlderVersions(doc);
                }
                else
                {
                    return RunForNewerVersions(doc);
                }
            }

            return "Unknown version.";
        }

        private static string RunForOlderVersions(Document doc)
        {
            #if NET48
            // Implementation for .NET Framework 4.8 and versions earlier than 2021
            return "Running with .NET Framework 4.8 for versions earlier than 2021.";
            #endif
        }

        private static string RunForNewerVersions(Document doc)
        {
            #if NET6_0_WINDOWS
            // Implementation for .NET 6.0 and versions 2021 or later
            return "Running with .NET 6.0 for versions 2021 or later.";
            #endif
        }
    }
}

Hope that is useful,

Mark

Unfortunately, this won’t work if he referenced a dlls directly as it simply won’t load. I do believe konrad builds his package for each version, but that’s why his install process is a bit different, where users have to pay attention to the version number.

Rhythm is built with versions in mind as well. It’s one Visual Studio solution that works for Revit 2020 to Revit 2025. The correct version is loaded at Dynamo loading with a view extension. You can take a look at the source code here.

And a video overview is here: