CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

分发应用程序 (.NET)

2023-1-1 08:43| 发布者: admin| 查看: 1119| 评论: 0|来自: AutoCAD

.NET 应用程序可以在两个可部署版本中分发:调试和发布。

  • 调试版本 - 包含与调试相关的信息。包含调试信息的 .NET 程序集的大小大于 .NET 程序集的发布版本。
  • 发布版本 - 不包含与调试相关的信息。

您必须选择要在其中分发应用程序的构建类型,这两种构建类型都可以加载到 AutoCAD 中。调试版本通常仅在开发和测试应用程序时使用,而发布版本是在分发应用程序以在公司内部或外部的多台计算机上使用时使用时生成的。

为 .NET 程序集生成发布版本

以下步骤说明如何生成 .NET 程序集的发布版本。

  1. 在 Microsoft Visual Studio 中,打开要为其生成发布版本的项目。
  2. 单击“生成”菜单“配置管理器”。
  3. 在“配置管理器”的“活动解决方案配置”下拉列表中,选择“发布”。
  4. 单击“关闭”。
  5. 在 Microsoft Visual Studio 中,单击“生成”菜单“生成解决方案”。

加载 .NET 程序集

确定 .NET 程序集的生成类型后,必须确定如何将其加载到 AutoCAD 中。.NET 程序集文件可以手动加载,也可以按需加载。

  • 手动 - 在命令提示符下或在 AutoLISP 文件中使用 NETLOAD 命令。
  • 需求加载 - 定义特定于要在 AutoCAD 启动时加载的应用程序的键。该密钥必须放在要加载应用程序的特定版本的 AutoCAD 的应用程序密钥下。

    应用程序的密钥可以包含以下密钥:

    描述

    .NET 程序集的说明,并且是可选的。

    加载控制

    控制加载 .NET 程序集的方式和时间。

    • 1 - 检测到代理对象时加载应用程序
    • 2 - 启动时加载应用程序
    • 4 - 在命令开始时加载应用程序
    • 8 - 应用户或其他应用程序的请求加载应用程序
    • 16 - 不加载应用程序
    • 32 - 透明地加载应用程序
    装载 机

    指定要加载的 .NET 程序集文件。

    管理

    指定应加载的文件是 .NET 程序集或 ObjectARX 文件。对于 .NET 程序集文件,设置为 1。

需求加载 .NET 应用程序

下面的示例在注册表中创建并删除所需的项,以便在 AutoCAD 启动时加载 .NET 程序集文件。使用“注册我的应用程序”命令时,将创建所需的注册表项,这些注册表项将在下次启动 AutoCAD 时自动加载应用程序。“取消注册我的应用程序”命令从注册表中删除需求加载信息,以便在下次启动 AutoCAD 时不会加载应用程序。

VB.NET

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

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();
}

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:57

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部