.NET 应用程序可以分布在两个可部署的版本中:debug 和 release。
您必须选择要在其中分发应用程序的构建类型,这两种构建类型都可以加载到 AutoCAD 中。调试版本通常仅在开发和测试应用程序时使用,而发布版本是在分发应用程序以在公司内部或外部的许多计算机上使用时生成的。 为 .NET 程序集生成 Release 版本以下步骤说明如何生成 .NET 程序集的 Release 版本。
加载 .NET 程序集确定 .NET 部件的构建类型后,必须确定如何将其加载到 AutoCAD 中。可以手动加载 .NET 程序集文件,也可以按需加载。
要求加载 .NET 应用程序以下示例在注册表中创建并删除在启动 AutoCAD 时加载 .NET 部件文件所需的项。使用 RegisterMyApp 命令时,将创建所需的注册表项,这些注册表项将在下次启动 AutoCAD 时自动加载应用程序。UnregisterMyApp命令从注册表中删除需求加载信息,以便下次启动AutoCAD时不会加载应用程序。 VB.NETImports 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 C#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(); } |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:06
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.