Upgrading C++/CLI Wrappers for Custom Entities to .NET 8.0

<?xml encoding=”UTF-8″>By Madhukar Moogala

AutoCAD 2025 started supporting .NET 8.0 platform, if you have managed wrapper or interop API for custom entities,
you need to upgrade them from NET 4.x to NET 8.0

Upgrading managed wrappers is three fold process

    1. First, you need to upgrade arx or dbx project (*.vcxproj) to target new SDK version
      Second, you need to upgrade the wrapper project (C++CLI) to NET 8.0
      Third, you need to upgrade the client side plugin project from NET 4x to NET 8.0
  • Here is the step by step guide to upgrade the managed wrapper project from NET 4.x to NET 8.0

    1. Update the .vcxproj File:

      • Replace <CLRSupport>true</CLRSupport> properties with
        <CLRSupport>NetCore</CLRSupport>.
      • Replace <TargetFrameworkVersion> properties with
        <TargetFramework>net8.0</TargetFramework>.
    2. Remove .NET Framework References:

      • Remove any references to System, System.Core,System.Data,
        System.Windows.Forms, and System.Xml from your project.
    3. Update API Usage:

      • Review your .cpp files and update any APIs that are unavailable in .NET.
    4. WPF and Windows Forms Usage:

      • C++/CLI projects can use Windows Forms and WPF APIs.
      • Add explicit framework references to the UI libraries.

      To use Windows Forms APIs, add this reference to the .vcxproj file:

      <!-- Reference all of Windows Forms -->
      <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
      

      To use WPF APIs, add this reference to the .vcxproj file:

      <!-- Reference all of WPF -->
      <FrameworkReference Include="Microsoft.WindowsDesktop.App.WPF" />
      

      To use both Windows Forms and WPF APIs, add this reference to the .vcxproj file:

      <!-- Reference the entirety of the Windows desktop framework:     Windows Forms, WPF, and the types that provide integration between them -->
      <FrameworkReference Include="Microsoft.WindowsDesktop.App" />
      

    Remember that there are some limitations when migrating C++/CLI projects to .NET Core, such as not being able to
    compile to an executable directly and Windows-only support for C++/CLI. Make sure to check the documentation for more
    details

    1. Upgrading a .NET 4.x Project to .NET 8.0

      1. Open the Project File:

        • In Visual Studio, navigate to Solution Explorer.
        • Right-click on the ManagedTest project and select “Upgrade”

          Refer: How to use upgrade
          assistant
          )

      2. Update the Project Configuration:

        • Locate the <TargetFramework> property and change its value to
          net8.0-windows. This specifies that the project targets the latest .NET 8.0 framework for
          Windows.
        • Find the <Platforms> property and set it to x64. This indicates that the
          project is built for the 64-bit architecture.
      3. Configure Assembly Search Paths:

        • Locate the <AssemblySearchPaths> property (it might not exist yet).
        • Add the path to your ObjectARX SDK directory within the property’s value. This ensures that .NET
          references from the SDK are found during compilation. Here’s an example structure:

        XML

                    <AssemblySearchPaths>$(OutDir);$(ReferencePath);C:PathToYourObjectARXSDK</AssemblySearchPaths>
        
        
        • Replace C:PathToYourObjectARXSDK with the actual path to your ObjectARX SDK
          installation.
    2. Optional: Update Root Namespace (if necessary):

      • If your project uses a specific root namespace to organize its files, locate the
        <RootNamespace> property and ensure it matches your project directory name.
    3. Save the Project File:

      • Save the changes made to the project file (ManagedTest.csproj).

    Here is the sample project file for your reference

        <span><?</span><span>xml</span><span> </span><span>version</span><span>=</span><span>"</span><span>1.0</span><span>"</span><span> </span><span>encoding</span><span>=</span><span>"</span><span>utf-8</span><span>"</span><span>?></span>
    <span><</span><span>Project</span> Sdk<span>=</span><span>"</span><span>Microsoft.NET.Sdk</span><span>"</span><span>></span>
    <span><</span><span>PropertyGroup</span><span>></span>
    <span><</span><span>OutputType</span><span>></span>Library<span></</span><span>OutputType</span><span>></span>
    <span><</span><span>RootNamespace</span><span>></span>ManagedTest<span></</span><span>RootNamespace</span><span>></span>
    <span><</span><span>TargetFramework</span><span>></span>net8.0-windows<span></</span><span>TargetFramework</span><span>></span>
    <span><</span><span>GenerateAssemblyInfo</span><span>></span>false<span></</span><span>GenerateAssemblyInfo</span><span>></span>
    <span><</span><span>ObjectARXPATH</span> Condition<span>=</span><span>"</span><span>'$(ObjectARXPATH)' == ''</span><span>"</span><span>></span>D:ArxSdksarx2025<span></</span><span>ObjectARXPATH</span><span>></span>
    <span><</span><span>AssemblySearchPaths</span><span>></span>$(ObjectARXPATH)inc;$(AssemblySearchPaths)<span></</span><span>AssemblySearchPaths</span><span>></span>
    <span><</span><span>Platforms</span><span>></span>x64<span></</span><span>Platforms</span><span>></span>
    <span></</span><span>PropertyGroup</span><span>></span>
    <span><</span><span>ItemGroup</span><span>></span>
    <span><</span><span>FrameworkReference</span> Include<span>=</span><span>"</span><span>Microsoft.WindowsDesktop.App</span><span>"</span><span>/></span>
    <span></</span><span>ItemGroup</span><span>></span>
    <span><</span><span>ItemGroup</span><span>></span>
    <span><</span><span>ProjectReference</span> Include<span>=</span><span>"</span><span>..ManagedWrapperManagedWrapper.vcxproj</span><span>"</span> <span>/></span>
    <span></</span><span>ItemGroup</span><span>></span>
    <span><</span><span>ItemGroup</span><span>></span>
    <span><</span><span>Reference</span> Include<span>=</span><span>"</span><span>AcDbMgd</span><span>"</span><span>></span>
    <span><</span><span>Private</span><span>></span>False<span></</span><span>Private</span><span>></span>
    <span></</span><span>Reference</span><span>></span>
    <span><</span><span>Reference</span> Include<span>=</span><span>"</span><span>AcMgd</span><span>"</span><span>></span>
    <span><</span><span>Private</span><span>></span>False<span></</span><span>Private</span><span>></span>
    <span></</span><span>Reference</span><span>></span>
    <span><</span><span>Reference</span> Include<span>=</span><span>"</span><span>AcCoreMgd</span><span>"</span><span>></span>
    <span><</span><span>Private</span><span>></span>False<span></</span><span>Private</span><span>></span>
    <span></</span><span>Reference</span><span>></span>
    <span></</span><span>ItemGroup</span><span>></span>
    <span></</span><span>Project</span><span>></span>
    

    The Github project is available at ManagedCircle


    Comments

    Leave a Reply

    Discover more from Autodesk Developer Blog

    Subscribe now to keep reading and get access to the full archive.

    Continue reading