VS Code Error

VS Code Error

sragan
Collaborator Collaborator
3,780 Views
4 Replies
Message 1 of 5

VS Code Error

sragan
Collaborator
Collaborator

Trying to update a Macro from Revit 2024 to 2025  with the new VS Code enviroment.   I copied the macro to the 2025 directory, and hit the Macro Edit Button.   When VS Code opens, I type "dotnet build" in the terminal window.  The build is successful, but I get a couple of warnings.  It looks like somewhere I have references to older Windows Forms and System Drawing DLL's.   The Macro won't run (it still has the red symbol on the icon in the Macro Manager, like it hasn't been successfuly built.)

 

How do I fix this?  Here is the error message VS Code gives.

 

 

 

 

There was a conflict between "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Drawing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
"System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was chosen because it was primary and "System.Drawing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" was not.
References which depend on "System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Drawing.dll].
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Drawing.dll
Project file item includes which caused reference "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Drawing.dll".
System.Drawing
References which depend on or have been unified to "System.Drawing, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" [].
C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPI.dll
Project file item includes which caused reference "C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPI.dll".
..\..\..\..\..\RevitAPI.dll
..\..\..\..\..\RevitAPIUI.dll
C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPIUI.dll
Project file item includes which caused reference "C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPIUI.dll".
..\..\..\..\..\RevitAPIUI.dll
C:\Program Files\dotnet\sdk\9.0.100\Microsoft.Common.CurrentVersion.targets(2413,5): warning MSB3277:
Found conflicts between different versions of "System.Windows.Forms" that could not be resolved.
There was a conflict between "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" and "System.Windows.Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
"System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was chosen because it was primary and "System.Windows.Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" was not.
References which depend on "System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" [C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll].
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll
Project file item includes which caused reference "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Windows.Forms.dll".
System.Windows.Forms
References which depend on or have been unified to "System.Windows.Forms, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" [].
C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPIUI.dll
Project file item includes which caused reference "C:\ProgramData\Autodesk\Revit\Macros\2025\RevitAPIUI.dll".
..\..\..\..\..\RevitAPIUI.dll

0 Likes
Accepted solutions (2)
3,781 Views
4 Replies
Replies (4)
Message 2 of 5

Charles.Piro
Advisor
Advisor
Accepted solution

Hi,

 

For Revit 2025, you need to upgrade your solution from NET4.8 to NET CORE 8.0.

You can look this link : https://thebuildingcoder.typepad.com/blog/2024/04/migrating-from-net-48-to-net-core-8.html 

 

😉



PIRO Charles
Developer

PIRO CIE
Linkedin


0 Likes
Message 3 of 5

sragan
Collaborator
Collaborator

There is a whole lot of info. and links in that post, but I don't see anything specific to Revit Macros or the new VS Code Editor Revit 2025 uses.

 

Probably great for professional programmers, but not so great for others who use Macros for the simplicity.

 

0 Likes
Message 4 of 5

ctm_mka
Collaborator
Collaborator
Accepted solution

@sragan having no actual experience with macros, i can only offer this as a workaround:

  • copy the code in 2024 to a text editor.
  • start new macro in 2025.
  • copy code back to 2025.

My thought being that at least this will get around the issue of not being able to upgrade as shown in that link.

0 Likes
Message 5 of 5

sragan
Collaborator
Collaborator

Thats's the only way I got it to work.   I thought it was going to be a real pain to add windows forms, but I only needed to add one line of code to the csproj file.  Like this:

 

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>net8.0-windows</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWindowsForms>true</UseWindowsForms>
    <UseWPF>true</UseWPF>
    <Nullable>enable</Nullable>
  </PropertyGroup>

 

I also had to update the AddParameter methods, like this;

 

//FamilyParameter fp = famMan.AddParameter (eD,BuiltInParameterGroup.PG_ELECTRICAL_LIGHTING,false); 

becomes:

FamilyParameter fp = famMan.AddParameter (eD,GroupTypeId.ElectricalLighting,false);
                            		}

 

And there is the usual frustration that  usually comes with copying and pasting code  - - one "}" always seems to be missing, extra, or just in the wrong place.

 

But it does work.  

 

 

0 Likes