Updating an existing .NET Framework project into a .NET Core one

Updating an existing .NET Framework project into a .NET Core one

Ramoon_Bandeira
Contributor Contributor
6,629 Views
25 Replies
Message 1 of 26

Updating an existing .NET Framework project into a .NET Core one

Ramoon_Bandeira
Contributor
Contributor

Now that Revit 2025 is out, Naturally, most developers will need to upgrade their existent .Net Framework Projects into .NET Core 8.0 project.

Is there a step by step guide to update an existing .NET Framework 4.8 project into a .NET core 8.0 ?
I`ve been attempting to use microsoft upgrade feature but all attempts of my part have failed miserably so far.

Thanks.

6,630 Views
25 Replies
Replies (25)
Message 2 of 26

nice3point
Advocate
Advocate

You can try templates that support writing add-ins for the .Net Framework and .Net Core https://github.com/Nice3point/RevitTemplates

 

For existing projects the correct way is to migrate .csproj to DotNet SDK style, to avoid errors it is better to do it manually.

SDK style csproj sample: https://github.com/Nice3point/RevitTemplates/blob/develop/samples/SingleProjectApplication/RevitAddI...

Message 3 of 26

ricaun
Advisor
Advisor

If the microsoft upgrade fails you need to unload the project and update the csproj manually.


Most of the time is remove alot of things in the csproj to update to SDK style. If you need help just send me a message.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 4 of 26

j0hnp
Advocate
Advocate

I've just been starting a new visual studio file from the template that @nice3point linked above and bringing in all my code files. I've found that it has been easier for my code base(s) for my tools. I also get access to all the cool features built into those new templates.

john.pierson

expert elite / design technologist / dynamo package creator

designtechunraveled.com



Message 5 of 26

CLindballe
Explorer
Explorer

What about shared projects? How do I handle the migration to .net 8.0? I have problems with the assembly reference.

Update:

I fixed it and it now works for Revit 2025 with with SharedProject. 

<Project Sdk="Microsoft.NET.Sdk">
 
  <PropertyGroup>
    <TargetFrameworks>net8.0-windows</TargetFrameworks>
<UseWPF>true</UseWPF>
    <RootNamespace>LindballeTools.Revit</RootNamespace>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <Platforms>AnyCPU;x64</Platforms>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0-windows'">
<PackageReference Include="Revit_All_Main_Versions_API_x64" Version="2025.0.0" />
</ItemGroup>
0 Likes
Message 7 of 26

ricaun
Advisor
Advisor

I tried to update an old version of RevitLookup to see.

 

Update old version of RevitLookup to Sdk Style.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

Message 8 of 26

harrymattison
Advocate
Advocate

One thing I've found is that the old-style PostBuildEvent doesn't work in the new-style CSPROJ

This used to work

 

 

 

    <PostBuildEvent>"C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool.exe" sign /f "C:\Users\harry\Documents\Boost Your BIM\BoostYourBIM.pfx" /fd SHA256 /p $(CodeSignPassword) /v $(TargetPath)

mkdir "C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)"
copy /Y $(ProjectDir)$(TargetName).addin "C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\"
copy /Y $(TargetPath) "C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)"
copy /Y $(TargetDir)$(TargetName).pdb "C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)"

"C:\Program Files\Autodesk\Revit $(Configuration)\Revit.exe" "C:\Users\harry\Documents\rvt\2023.rvt"</PostBuildEvent>

 

 

 

 

When updating this project, delete that section from the CSPROJ and enter the code in here

harrymattison_0-1712241152079.png

The result will be this entry in the CSPROJ

 

 

 

  <Target Name="PostBuild" AfterTargets="PostBuildEvent">
    <Exec Command="&quot;C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\signtool.exe&quot; sign /f &quot;C:\Users\harry\Documents\Boost Your BIM\BoostYourBIM.pfx&quot; /fd SHA256 /p $(CodeSignPassword) /v $(TargetPath)&#xD;&#xA;mkdir &quot;C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)&quot;&#xD;&#xA;copy /Y $(SolutionDir)$(TargetName).addin &quot;C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\&quot;&#xD;&#xA;copy /Y $(TargetPath) &quot;C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)&quot;&#xD;&#xA;copy /Y $(TargetDir)$(TargetName).pdb &quot;C:\ProgramData\Autodesk\Revit\Addins\$(Configuration)\$(TargetName)&quot;&#xD;&#xA;&#xD;&#xA;&quot;C:\Program Files\Autodesk\Revit $(Configuration)\Revit.exe&quot;" />
  </Target>

 

 

 

 

Message 9 of 26

nice3point
Advocate
Advocate

One thing I've found is that the old-style PostBuildEvent doesn't work in the new-style CSPROJ

try to use this package https://github.com/Nice3point/Revit.Build.Tasks and add these lines if you just want to copy files:

 

 

<PropertyGroup>
    <PublishAddinFiles>true</PublishAddinFiles>
</PropertyGroup>

 

 

 

or copy target directly in your .csproj file:

https://github.com/Nice3point/Revit.Build.Tasks/blob/main/source/Nice3point.Revit.Build.Tasks/target...

 

I recommend to always use Target instead of PostBuildEvent

0 Likes
Message 10 of 26

harrymattison
Advocate
Advocate

If you are seeing a lot of these warnings

Warning CA1416 This call site is reachable on all platforms. 'FormPrintSuppression' is only supported on: 'windows'. 

 

You can make it go away by adding 

[SupportedOSPlatform("windows")]

 

before the definition of the class like

    [SupportedOSPlatform("windows")]
    class Ribbon : IExternalApplication
    {
Message 11 of 26

nice3point
Advocate
Advocate

@harrymattison   dont use [SupportedOSPlatform("windows")], use TargetFramework net8.0-window instead of net8.0

 

Sample:

https://github.com/Nice3point/RevitTemplates/blob/develop/samples/SingleProjectApplication/RevitAddI...

0 Likes
Message 12 of 26

harrymattison
Advocate
Advocate
I already am using net8.0-windows but I
still get the warnings
This suggested it could be due to GenerateAssemblyInfo = false, but I
changed that to true and still get the warnings
https://github.com/dotnet/roslyn-analyzers/issues/4983#issuecomment-852738069
0 Likes
Message 13 of 26

Ramoon_Bandeira
Contributor
Contributor

After starting a new .net 8.0 class library project. i had it all working perfectly, building the project from revit 19 to 25 seamlessly. Up till i decided to set the Assembly Neutral Language.

After that, i could still build to 2025 version, but versions prior to that all fail resulting on the following error:

Severity Code Description Project File Line Suppression State
Error MC1000 Unknown build error, 'Could not find type 'System.Resources.NeutralResourcesLanguageAttribute' in assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\System.Runtime.dll'.' MyAssembly_Core C:\Program Files\dotnet\sdk\8.0.202\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 211

Any guide?

I cant roll it back, even if i set it back to None. the solution wont rebuild for prior versions to 25

0 Likes
Message 14 of 26

kevinaugustino
Contributor
Contributor

I just upgraded one of my plugins and here are the bulk of the steps I followed:

 

1. Install the .NET upgrade assistant as a Visual Studio extension: https://learn.microsoft.com/en-us/dotnet/core/porting/upgrade-assistant-install#install-the-visual-s...

2. Open my .sln, right-click the sln in the solution explorer, choose 'Upgrade'

3. Follow the steps in the upgrade wizard ("Upgrade project to a newer .net version" --> "Side by side project upgrade" --> "New project" --> name it something like "{projectname}-netCore" or whatever)

4. Close the sln, then open the new .csproj it created in any text editor and make the following edits:

5. Remove this line: <GenerateAssemblyInfo>false</GenerateAssemblyInfo>

6. Added these 3 lines to the first PropertyGroup:

 

<AssemblyName>PUT_PROJECT_NAME_HERE</AssemblyName>
<RootNamespace>PUT_PROJECT_NAME_HERE</RootNamespace>
<NoWarn>CA1416;</NoWarn>

 

You probably don't need to do this but I wanted to keep my .dlls named the same for consistency with my pre-2025 plugins

 

7. If your project has a post-build command, you'll need to switch it over to the new format. It'll look something like this:

 

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command='
PUT COMMAND HERE
' />
</Target>

 

Rather than:

 

<PropertyGroup>
<PostBuildEvent>PUT COMMAND HERE</PostBuildEvent>
</PropertyGroup>

 

Obviously this also applies to pre-build events. Don't ask me why the .net upgrade assistant didn't handle this for you.

 

8. If your build configurations have spaces in their names, switch them to underscores because apparently newer .nets have problems with spaces. EX: "Debug 2025" --> "Debug_2025"

9. Open the .sln

10. In the Solution Explorer, right-click the Properties folder for the new netCore project --> Add new item --> choose "Assembly Info File" and name it AssemblyInfo.cs. Then open that file and add this line to the bottom: [assembly: SupportedOSPlatform("windows")] . This way you won't get spammed with warnings about '...this call site is reachable on all platforms...' 

0 Likes
Message 15 of 26

Ramoon_Bandeira
Contributor
Contributor

Well... i`ve done that, this time i didnt touch the code for the Assembly Neutral Language, however, i keep getting the same error:

Severity Code Description Project File Line Suppression State
Error MC1000 Unknown build error, 'Could not find type 'System.Resources.NeutralResourcesLanguageAttribute' in assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\System.Runtime.dll'.' MyProject_Core C:\Program Files\dotnet\sdk\8.0.202\Sdks\Microsoft.NET.Sdk.WindowsDesktop\targets\Microsoft.WinFX.targets 211

0 Likes
Message 16 of 26

kevinaugustino
Contributor
Contributor

I've never messed with any Assembly Neutral Language. I just have 2 separate projects in my solution, one for Revit 2021-2024 targeting .net framework 4.8.1, and the other for Revit 2025 targeting .net8.0-windows.

 

You're getting that error while trying to the build your .net8.0-windows project that is referencing the Revit 2025 .dlls? It's weird that the error refers to .net framework 4.8, since nothing in your project should be referencing .net framework after upgrading. Do you have any .net framework nuget packages being referenced from your .net8.0-windows project? Or maybe you accidentally referenced older Revit .dlls built against .net framework? In the Solution Explorer, do you have any warnings in the Dependencies?

0 Likes
Message 17 of 26

Ramoon_Bandeira
Contributor
Contributor

I`m trying to keep both my .Net Framework, and my .NET Core project into a single project of visual Studio.
The redirections could be made automatically based on the configuration i`m running.

I even managed to make it work for a little while. For a moment i could run the same project for both revit 2025 and its prior versions. 

However, suddenly, this issue come to light, and nothing that i did solved it.

I`ve seen @ricaun incredible guide on updating the RevitLookup, i got a couple ideas from it.

I guess that the issue i have is due to having multiple resource files (i.e multiple resource files for localizing texts based on the language that the user is using on revit at the moment), on this case, the .NET Compiler may be getting crazy abouth wich language to choose as the default one, hence the error message.

Anyway, i`ll keep looking for solutions, and i`ll keep you informed about it.

Thanks.



Message 18 of 26

mhannonQ65N2
Collaborator
Collaborator

You can apply that attribute to your whole class library by doing:

[assembly: SupportedOSPlatform("windows")]
0 Likes
Message 19 of 26

nice3point
Advocate
Advocate

You can apply that attribute to your whole class library by doing: [assembly: SupportedOSPlatform("windows")]

Please don't. Just use TargetFramework net8.0-window. Your problem is probably in something else, you can better send your .csproj

0 Likes
Message 20 of 26

Extraneous
Advisor
Advisor

Hi guys, please look at how I managed to change my project to a sdk-style: https://github.com/Tereami/ArchParametrisation/blob/master/ArchParametrisation/ArchParametrisation.c...

Everything works ok, but with one exception: Batch build didn't work now, catches an error 
NETSDK1005 Assets file 'project.assets.json' doesn't have a target for 'net47'. 

In the same time, every configuration separately builds ok! I've tried to delete .vs and obj folders, restart my computer, upgrade msbuild and nuget, doesn't help.

Extraneous_0-1714149919473.png

 

Alexander Zuev
In BIM we trust
Facebook | Linkedin | Telegram

0 Likes