【发布时间】:2016-05-12 21:09:56
【问题描述】:
我需要在 PowerShell 中启动托管在 AutoCAD 中的 cmdled。 AutoCAD 的程序集(它是 PowerShell 的宿主)不在 GAC 中。如何正确指向 AutoCAD 的程序集?是否可以指向 DLL 文件集而不是程序集名称?当前 AppDomain 中已加载所有必需的程序集。
$asm = ([System.AppDomain]::CurrentDomain.GetAssemblies()) | where { `
($_.FullName).StartsWith("acdbmgd") -or ($_.FullName).StartsWith("acmgd") `
-or ($_.FullName).StartsWith("accoremgd")}
$src =[Io.File]::ReadAllText(($PSScriptRoot + "../Resources/example.cs"))
Add-Type -ReferencedAssemblies $asm -TypeDefinition $src -Language CSharp
# Launch our static `Bushman.CAD.PowerShellUtils.Example.WriteMsg()` method:
[Bushman.CAD.PowerShellUtils.Example]::WriteMsg("`nHello from CS-file!`n")
这是../Resources/example.cs文件的代码:
using System;
using Autodesk.AutoCAD.Runtime;
using cad = Autodesk.AutoCAD.ApplicationServices.Application;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
namespace Bushman.CAD.PowerShellUtils {
public class Example {
public static void WriteMsg(String msg) {
Document doc = cad.DocumentManager.MdiActiveDocument;
if (null == doc || String.IsNullOrEmpty(msg)) {
return;
}
Editor ed = doc.Editor;
ed.WriteMessage(msg);
}
}
}
但我得到错误:
“DatabaseServices”的类型或命名空间的名称在 “Autodesk.AutoCAD”的命名空间(通过了程序集引用?)。
“应用程序”的类型或命名空间的名称在 “Autodesk.AutoCAD.ApplicationServices”的命名空间(程序集 引用通过了?)
我该如何解决?
【问题讨论】:
标签: c# powershell powershell-4.0 powershell-hosting