.NET アプリケーションは、デバッグ ビルドとリリース ビルドの 2 つの展開可能なビルドで配布できます。
アプリケーションを配布するビルドの種類を選択する必要があります。どちらの種類のビルドも AutoCAD にロードすることができます。通常、デバッグ ビルドはアプリケーションの開発およびテスト時にのみ使用し、リリース ビルドは社内外の多数のコンピュータで使用するアプリケーションの配布時に構築します。
次の手順では、.NET アセンブリのリリース ビルドを生成する方法について説明します。
[構成マネージャ]の順にクリックします。
[ソリューションのビルド]の順にクリックします。 .NET アセンブリのビルドの種類を決定したら、AutoCAD にロードする方法を決定する必要があります。.NET アセンブリ ファイルは、手動でロードまたはディマンド ロードすることができます。
アプリケーションのキーには、以下が含まれます。
.NET アセンブリの説明です(省略可能)。
.NET アセンブリをロードする方法とタイミングをコントロールします。
ロードする .NET アセンブリ ファイルを指定します。
ロードする必要のあるファイルが .NET アセンブリ ファイルまたは ObjectARX ファイルのどちらかを指定します。.NET アセンブリ ファイルの場合は、1 に設定します。
次の例では、AutoCAD の起動時に .NET アセンブリ ファイルをロードするために、必要なキーをレジストリに作成して削除します。RegisterMyApp コマンドを使用すると、AutoCAD の次回起動時にアプリケーションを自動的にロードするために必要なレジストリ キーが作成されます。UnregisterMyApp コマンドを使用すると、AutoCAD の次回起動時にアプリケーションをロードしないように、ディマンド ロード情報がレジストリから削除されます。
Imports Microsoft.Win32
Imports System.Reflection
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
<CommandMethod("RegisterMyApp")> _
Public Sub RegisterMyApp()
'' Get the AutoCAD Applications key
Dim sProdKey As String = HostApplicationServices.Current.RegistryProductRootKey
Dim sAppName As String = "MyApp"
Dim regAcadProdKey As RegistryKey = Registry.CurrentUser.OpenSubKey(sProdKey)
Dim regAcadAppKey As RegistryKey = regAcadProdKey.OpenSubKey("Applications", True)
'' Check to see if the "MyApp" key exists
Dim subKeys() As String = regAcadAppKey.GetSubKeyNames()
For Each sSubKey As String In subKeys
'' If the application is already registered, exit
If (sSubKey.Equals(sAppName)) Then
regAcadAppKey.Close()
Exit Sub
End If
Next
'' Get the location of this module
Dim sAssemblyPath As String = Assembly.GetExecutingAssembly().Location
'' Register the application
Dim regAppAddInKey As RegistryKey = 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()
End Sub
<CommandMethod("UnregisterMyApp")> _
Public Sub UnregisterMyApp()
'' Get the AutoCAD Applications key
Dim sProdKey As String = HostApplicationServices.Current.RegistryProductRootKey
Dim sAppName As String = "MyApp"
Dim regAcadProdKey As RegistryKey = Registry.CurrentUser.OpenSubKey(sProdKey)
Dim regAcadAppKey As RegistryKey = regAcadProdKey.OpenSubKey("Applications", True)
'' Delete the key for the application
regAcadAppKey.DeleteSubKeyTree(sAppName)
regAcadAppKey.Close()
End Sub
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();
}