Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Add-Type cmdlet:是否可以指向DLL文件集而不是程序集名称?_C#_Powershell_Powershell 4.0_Powershell Hosting - Fatal编程技术网

C# Add-Type cmdlet:是否可以指向DLL文件集而不是程序集名称?

C# Add-Type cmdlet:是否可以指向DLL文件集而不是程序集名称?,c#,powershell,powershell-4.0,powershell-hosting,C#,Powershell,Powershell 4.0,Powershell Hosting,我需要在承载在AutoCAD内部的PowerShell中启动cmdled。AutoCAD的程序集(它是PowerShell的主机)不在GAC中。如何正确指向AutoCAD的部件?是否可以指向DLL文件集而不是程序集名称?当前AppDomain中已加载所有必需的程序集 $asm = ([System.AppDomain]::CurrentDomain.GetAssemblies()) | where { ` ($_.FullName).StartsWith("acdbmgd") -or (

我需要在承载在AutoCAD内部的PowerShell中启动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”(部件)的命名空间 引用是否通过?)


我怎样才能修复它?

是的,这是可能的。您需要使用
Assembly
对象的
Location
属性:

$asm = @(
    [System.AppDomain]::CurrentDomain.GetAssemblies() |
    Where-Object {
        $_.FullName.StartsWith("acdbmgd") -or
        $_.FullName.StartsWith("acmgd") -or
        $_.FullName.StartsWith("accoremgd")
    } |
    Select-Object -ExpandProperty Location
)