3

I'm trying to create a simple multi-version hello World plug-in for Revit and I've found this article which I'm trying to follow along. however, I'm not getting very far. I'm not so familiar with how the .csproj file works. I've created plugins before for individual Revit years but not multi-versions.

Here is my .csProj code below. I'm trying to start small and just handle .net framework 4.5.2 which is Revit 2018. You'll also find snippets at the bottom for my project properties. There is no longer an open for Start External Application: so I don't know how to Debug it through Revit.

Any and all help/direction is appreciated.

With the current .csproj code below, i get this pop up error:

enter image description here

.csproj

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFrameworks>net452<!--;net46;net47--></TargetFrameworks>
        <Configurations>Debug;Release</Configurations>
        <!--<Platforms>x64</Platforms>-->
        <OutputPath>bin\Debug\</OutputPath>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|Any CPU' ">      
        <DefineConstants>DEBUG</DefineConstants>
        <Optimize>false</Optimize>
        <OutputPath>bin\Debug\</OutputPath>

        <DebugType>full</DebugType>
        <DebugSymbols>true</DebugSymbols>
    </PropertyGroup>

    <PropertyGroup Condition="'$(Configuration)'=='Release'">
        <PlatformTarget>x64</PlatformTarget>
        <DebugType>none</DebugType>
        <DebugSymbols>false</DebugSymbols>
    </PropertyGroup>

    <PropertyGroup Condition=" '$(TargetFramework)' == 'net452' ">
        <DefineConstants>$(DefineConstants);REVIT2018</DefineConstants>
        <!--<AssemblyName>helloWorld</AssemblyName>-->
    </PropertyGroup>
    

    <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
        <!--<Reference Include="AdWindows">
            <HintPath>......\2018\AdWindows.dll</HintPath>
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>-->
        <Reference Include="RevitAPI">
            <HintPath>C:\Program Files\Autodesk\Revit 2018\RevitAPI.dll</HintPath>          
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>
        <Reference Include="RevitAPIUI">
            <HintPath>C:\Program Files\Autodesk\Revit 2018\RevitAPIUI.dll</HintPath>
            <EmbedInteropTypes>false</EmbedInteropTypes>
            <Private>false</Private>
        </Reference>
    </ItemGroup>

    <ItemGroup>
      <Reference Include="PresentationCore" />
      <Reference Include="System.Windows.Forms" />
    </ItemGroup>
</Project>

project properties snippets enter image description here enter image description here enter image description here

Cflux
  • 1,423
  • 3
  • 19
  • 39
  • 2
    Take a look at this as an example and set it up this way: https://github.com/McCulloughRT/Revit2glTF/blob/master/glTFRevitExport/glTFRevitExport.csproj – Ehsan Iran-Nejad Sep 21 '20 at 23:01
  • @EhsanIran-Nejad, what do you have for the target framework in the project properties? i removed the `v4.5.2` line from my .csproj under the tag as you have shown in your link but the project properties is now defaulting to .net framework 4.0 – Cflux Sep 21 '20 at 23:45
  • 1
    @EhsanIran-Nejad, got it working! thanks. – Cflux Sep 22 '20 at 00:26
  • 1
    If you got it working, can you please share the solution with us? Thank you! – Jeremy Tammik Sep 22 '20 at 07:18
  • @EhsanIran-Nejad or JeremyTammik, any tips on [how to debug a multi-version plugin](https://stackoverflow.com/questions/64012558/c-sharp-revit-api-how-to-debug-multi-version-plugin-for-revit)? – Cflux Sep 22 '20 at 18:58

2 Answers2

1

Thanks to Ehsan for sharing his Github link. I was able to figure it out.

I added these 2 lines to my property group with assembly name.

<TargetFrameworkProfile />
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>

and then added these below in separate property groups which seem to allow me to run them in different versions. I've only tested 2018 and 2019 so far but it looks promising.

<PropertyGroup Condition="$(Configuration.Contains('2018'))">
    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
    <RevitVersion>2018</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2019'))">
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <RevitVersion>2019</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2020'))">
    <TargetFrameworkVersion>v4.7</TargetFrameworkVersion>
    <RevitVersion>2020</RevitVersion>
  </PropertyGroup>
  <PropertyGroup Condition="$(Configuration.Contains('2021'))">
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <RevitVersion>2021</RevitVersion>
  </PropertyGroup>
Cflux
  • 1,423
  • 3
  • 19
  • 39
  • 1
    As you might have seen in the example csproj file from the previous comments, you can use the `RevitVersion` value on the rest of the csproj to have dynamic build paths, ... that are automatically set when the build profile is changed – Ehsan Iran-Nejad Sep 23 '20 at 00:11
1

Thanks to your post, I have learned something about multi version plug-in. Now, for the direct question, you can debug your class library by starting Revit when you start debug process. And the setting is as follow:

  1. set your project as start up project (right click project on "solution Exploration" panel => Set as Start up project) so that it will be the first project to run when debug

  2. Open your "Project properties" tab, select "Debug"

  3. From "Start action" on Debug, choose "Start external program". then click "browse" button to select the executable file for Revit. By default, it should be at:

    C:\Program Files\Autodesk\your_version_of_revit

  4. Save the process, build the project and hit F5 (or whatever key you set for debug)

This is a little bit late since you already solve your problem, but hope it can be helpful in some similar situation.

Thế Long
  • 516
  • 7
  • 19