.NET 应用程序可以在两个可部署版本中分发:调试和发布。
您必须选择要在其中分发应用程序的构建类型,这两种构建类型都可以加载到 AutoCAD 中。调试版本通常仅在开发和测试应用程序时使用,而发布版本是在分发应用程序以在公司内部或外部的多台计算机上使用时使用时生成的。 为 .NET 程序集生成发布版本以下步骤说明如何生成 .NET 程序集的发布版本。
加载 .NET 程序集确定 .NET 程序集的生成类型后,必须确定如何将其加载到 AutoCAD 中。.NET 程序集文件可以手动加载,也可以按需加载。
需求加载 .NET 应用程序下面的示例在注册表中创建并删除所需的项,以便在 AutoCAD 启动时加载 .NET 程序集文件。使用“注册我的应用程序”命令时,将创建所需的注册表项,这些注册表项将在下次启动 AutoCAD 时自动加载应用程序。“取消注册我的应用程序”命令从注册表中删除需求加载信息,以便在下次启动 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 )
GMT+8, 2024-5-19 14:30
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.