Button config: How to target version-based dll's based on Revit version?

Hi everyone

I’m attempting to configure a button to target a different dll based on the Revit version and my attempt so far appears to have done nothing:

  1. Create a script (named script.py) which targets the required version (this is a mockup). This is stored in the folder which defines the button:
import os
import sys

def get_revit_version():
    # This function should return the Revit version, e.g., 2022 or 2025
    # You can use the `revit` module from pyRevit to get the version
    import revit
    return revit.version

def set_assembly_path():
    revit_version = get_revit_version()
    if revit_version == 2022:
        assembly_path = r"C:\SomeLocation\SomeApp2022.dll"
    elif revit_version == 2023:
        assembly_path = r"C:\SomeLocation\SomeApp2023.dll"
    elif revit_version == 2024:
        assembly_path = r"C:\SomeLocation\SomeApp2024.dll"
    elif revit_version == 2025:
        assembly_path = r"C:\SomeLocation\SomeApp2025.dll"
    else:
        raise Exception(f"Unsupported Revit version: {revit_version}")

    # Write the assembly path to a temporary file or environment variable
    os.environ["ASSEMBLY_PATH"] = assembly_path

if __name__ == "__main__":
    set_assembly_path()
  1. The yaml:
author: ""
highlight:
assembly: ${ASSEMBLY_PATH}
command_class: LaunchCommand
  1. Import the script in startup.py:

The error when clicking the button in Revit states “The target assembly is not set correctly and cannot be loaded”

The dlls exist in the locations specified in the script. How can the problem be resolved?

2 Likes

Hey @Thomas_Mahon did you end up finding a solution to this?

Have you considered targeting netstandard2.0 or one of the solutions here?

You’re right I’m so sorry @pyrevti for never getting back to you on this!!

The problem with .net standard 2.0 is that you can only use it with the libraries that support .net standard, which means that they cannot use any windows-specific things (e.g. WPF or Windows Forms).
For example, the first issue that we ran into, was authenticating into a database through the Microsoft.Identity.Client library, which has a dependency on Windows Forms.

I also suspect that Revit-dependent libraries will have the same issue.

Have you had any success using .net standard?

(I’m gonna reply to your original post too for completeness. Sorry again for this!