Best way to update plugin to a new Revit version? C# Visual Studio

Best way to update plugin to a new Revit version? C# Visual Studio

EATREVITPOOPCAD
Collaborator Collaborator
3,201 Views
7 Replies
Message 1 of 8

Best way to update plugin to a new Revit version? C# Visual Studio

EATREVITPOOPCAD
Collaborator
Collaborator

Curious on what is the recommended (most efficient) way to update plugin to a new Revit version? Lets say we are going from 2021 to 2022. Way I would go about it now is I have to download new Visual Studio Revit API 2022 Template, create a new project with it, attach old c# files, and then re-reference all of the DLL's used. I know its not much work to do on a single plugin, but lets say I have 20 different plugins, I wonder if there is a better way to "upgrade" existing visual studio project from Revit 2021 Visual Studio template to Revit 2022 Visual Studio Template, or something among those lines... 

 

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes
Accepted solutions (2)
3,202 Views
7 Replies
Replies (7)
Message 2 of 8

RPTHOMAS108
Mentor
Mentor
Accepted solution

You can target multiple version in the same solution:

 

Multi-Target 2021 and 2022 Using MSBuild - Autodesk Community - Revit Products

 

In some instances you have to use compilation constants with #If...Then...#Else directives (where API calls differ).

 

I find it easier to just copy the solution and change the references. I then know I have a historic version I haven't inadvertently changed shared parts of.

 

The biggest thing I've realised from creating backups etc. is to output dll to shared location for all projects rather than the default of output to project sub folder. If you output to project sub folder you end up with hundreds of dlls in each of the project folders. If you output to shared location you separate source from compilation and drastically cut down on backup time due to not having to backup dlls. Ideally we are told not to to copy local but in reality that's never caused issues for me when I forget (other than the 100's of dlls). You could avoid the dlls but then there is all the other things (the xml files etc.).

 

With that project packages folder in NuGet definitely going to be wishing for the days of OldGet, I try to work on a NoGet basis.

Message 3 of 8

MarryTookMyCoffe
Collaborator
Collaborator
Accepted solution

I was never fan of targeting revit version by TargetFramewor. I find making a new platforms more clear to work on (I'm not doing x86 x64 I add Revit 2020, Revit 2021).

<ItemGroup Condition=" '$(Platform)' == 'Revit2019' ">
    <Reference Include="RevitAPI">
      <HintPath>$(ProgramW6432)\Autodesk\Revit 2019\RevitAPI.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="RevitAPIUI">
      <HintPath>$(ProgramW6432)\Autodesk\Revit 2019\RevitAPIUI.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
  <ItemGroup Condition=" '$(Platform)' == 'Revit2020' ">
    <Reference Include="RevitAPI">
      <HintPath>$(ProgramW6432)\Autodesk\Revit 2020\RevitAPI.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="RevitAPIUI">
      <HintPath>$(ProgramW6432)\Autodesk\Revit 2020\RevitAPIUI.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>
 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Revit2019'">
    <OutputPath>bin\x64\Revit2019\Release\</OutputPath>
    <DefineConstants>TRACE;Revit2019</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|Revit2020'">
    <OutputPath>bin\x64\Revit2020\Release\</OutputPath>
    <DefineConstants>TRACE;Revit2020</DefineConstants>
    <Optimize>true</Optimize>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <ErrorReport>prompt</ErrorReport>
    <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
  </PropertyGroup>

 

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
Message 4 of 8

Maltezc
Advocate
Advocate

@jeremytammik, is there a benefit to targetting by framework vs targeting by Revit version? 

 

I'd have to agree that @MarryTookMyCoffe has a point that it sounds like it is more clear to work on when targeting by Revit Version.

Message 5 of 8

EATREVITPOOPCAD
Collaborator
Collaborator

Thanks for the help everyone, I was able to target multiple versions!

 

However, I ran into an issue when trying to debug... 

I get this error:

A project with an Output Type of Class Library cannot be started directly. 

In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

 

I think I get what this is telling me... I just can't figure out how to go about pleasing the debugger 😅

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes
Message 6 of 8

MarryTookMyCoffe
Collaborator
Collaborator

you can run Revit api only from revit, you need to to add to run from revit.exe, or run it by RevitManager added to devtools

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes
Message 7 of 8

EATREVITPOOPCAD
Collaborator
Collaborator

How do I tell the debugger to debug the plugin from a specific Revit.exe?  (in Visual studio)

 

Before when I created a new plugin from Jeremy's template, I could just press the "debug play button" in visual studio to start debugging. Once I target multiple Revit versions is when I start getting that message.

 

EATREVITPOOPCAD_0-1631636726524.png

 

 

 

The definition of insanity is doing the same thing over and over again and expecting different results
0 Likes
Message 8 of 8

MarryTookMyCoffe
Collaborator
Collaborator

I personally don't run apps like that, I use add-In-Manager.
My suggeston is to add in PropertyGroup(in csproj file) for compilation Condition

<StartProgram>$(ProgramW6432)\Autodesk\Revit 2022\Revit.exe</StartProgram>

 

-------------------------------------------------------------
--------------------------------|\/\/|------------------------
do not worry it only gonna take Autodesk 5 years to fix bug
0 Likes