.NET applications can be distributed in two deployable builds: debug and release.
.NET 应用程序可以通过两种编译配置分发:调试和发布.
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.
若要分发你的应用程序就必须选择编译的类型,这些类型是必须可以加载到 AutoCAD 中去的类型。调试版本通用仅用于开发和测试应用程序,而发布版本当你分发应用程序给你公司内部或外部的大量电脑使用时编译。
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.
确定 .NET 程序集的编译类型后,就必须确定它将如何加载到 AutoCAD 中。一个 .NET 程序集文件可以手动加载或按需加载。
手动 - 在命令提示符中或一个 AutoLISP 文件内部使用 NETLOAD 命令。关于使用 NETLOAD 命令加载 .NET 程序集的详细信息,请参见 加载程序集到 AutoCAD中部分。
按需加载 - 给指定的应用程序定义一个键,这个程序是在 AutoCAD 启动时你想加载的。这个键必须放在你想让你的程序被加载的 AutoCAD 指定版本的应用程序键上。
name="WS73099cc142f487551fea285e1221e4f9ff8-5a95">The key for the application can contain the following keys:
应用程序的键可以包含如下子键:
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.
下面的示例在注册表中创建或移除在 AutoCAD 启动时加载 .NET 程序集文件所必需的键。在 RigisterMyApp 命令使用后,AutoCAD 下次启动时自动加载应用程序所必须的注册表键将被创建。UnregisterMyApp 命令将从注册表中移除按需加载的信息,所以应用程序在下次启动 AutoCAD 时不会被加载。
Imports Microsoft.Win32
Imports System.Reflection
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
<CommandMethod("RegisterMyApp")> _
Public Sub RegisterMyApp()
'' 获得 AutoCAD 应用程序注册表键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)
'' 检查“MyApp”键是否存在 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()
'' 获得 AutoCAD 应用程序注册表键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;
[CommandMethod("RegisterMyApp")]
public void RegisterMyApp()
{
// 获得 AutoCAD 应用程序注册表键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);
// 检查“MyApp”键是否存在 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()
{
// 获得 AutoCAD 应用程序注册表键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();
}