Distribute Your Application (.NET)

.NET applications can be distributed in two deployable builds: debug and release.

You must choose the type of build to distribute your application in, both build types can be loaded into AutoCAD. Debug builds are usually only used when developing and testing an application, while a Release build is built when you are distributing an application for use on many computers inside or outside of your company.

To generate a Release build for a .NET assembly

The following steps explain how to generate a Release build of a .NET assembly.

  1. In Microsoft Visual Studio, open the project you want to generate a Release build for.
  2. Click Build menu Configuration Manager.
  3. In the Configuration Manager, Active Solution Configuration drop-down list, select Release.
  4. Click Close.
  5. In Microsoft Visual Studio, click Build menu Build Solution.

Load a .NET assembly

After you have determined the build type of your .NET assembly, you must determine how it will be loaded into AutoCAD. A .NET assembly file can be loaded manually or with demand loading.

Demand load a .NET application

The following examples create and remove the required keys in the registry to load a .NET assembly file at the startup of AutoCAD. When the RegisterMyApp command is used, the required registry keys are created that will automatically load the application the next time AutoCAD starts. The UnregisterMyApp command removes the demand loading information from the registry so the application is not loaded the next time AutoCAD starts.

C# Example

using Microsoft.Win32;
using System.Reflection;

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;

[CommandMethod("RegisterMyApp")]
public void RegisterMyApp()
{
  // Get the AutoCAD Applications key
  string sProdKey = HostApplicationServices.Current.RegistryProductRootKey;
  string sAppName = "MyApp";

  RegistryKey regAcadProdKey = Registry.CurrentUser.OpenSubKey(sProdKey);
  RegistryKey regAcadAppKey = regAcadProdKey.OpenSubKey("Applications", true);

  // Check to see if the "MyApp" key exists
  string[] subKeys = regAcadAppKey.GetSubKeyNames();
  foreach (string subKey in subKeys)
  {
      // If the application is already registered, exit
      if (subKey.Equals(sAppName))
      {
          regAcadAppKey.Close();
          return;
      }
  }

  // Get the location of this module
  string sAssemblyPath = Assembly.GetExecutingAssembly().Location;

  // Register the application
  RegistryKey regAppAddInKey = regAcadAppKey.CreateSubKey(sAppName);
  regAppAddInKey.SetValue("DESCRIPTION", sAppName, RegistryValueKind.String);
  regAppAddInKey.SetValue("LOADCTRLS", 14, RegistryValueKind.DWord);
  regAppAddInKey.SetValue("LOADER", sAssemblyPath, RegistryValueKind.String);
  regAppAddInKey.SetValue("MANAGED", 1, RegistryValueKind.DWord);

  regAcadAppKey.Close();
}

[CommandMethod("UnregisterMyApp")]
public void UnregisterMyApp()
{
  // Get the AutoCAD Applications key
  string sProdKey = HostApplicationServices.Current.RegistryProductRootKey;
  string sAppName = "MyApp";

  RegistryKey regAcadProdKey = Registry.CurrentUser.OpenSubKey(sProdKey);
  RegistryKey regAcadAppKey = regAcadProdKey.OpenSubKey("Applications", true);

  // Delete the key for the application
  regAcadAppKey.DeleteSubKeyTree(sAppName);
  regAcadAppKey.Close();
}