c# - Revit api - multi version plugin .csproj file

1.2k views Asked by At

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

2

There are 2 answers

0
Thế Long On

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.

1
Cflux On

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>