1

我已经看到了一堆类似的问题,但仍然无法弄清楚如何解决它:我有一个简单的 powershell cmdlet(它只是添加到参数)和一个用于注册它的管理单元。问题是然后我尝试运行我得到的 installutil

No public installers with the RunInstallerAttribute.Yes attribute could be found

管理单元代码:

using System.ComponentModel;
using System.Management.Automation;

namespace Cmdtlets
{
    [RunInstaller(true)]
    class BugBoxSnapin : PSSnapIn
    {

    }
}

我知道存在 64 个 32 位版本的 installutil 以及 x86 和 x64 powershell。我的配置是 - 64 位机器,平台目标“任何 CPU”,.NET Framework 4.5。我无法从 Visual Studio 引用选择器中引用 System.Management.Automation,所以我手动更改了 csproj 文件

<Reference Include="System.Management.Automation" />

我应该在哪个版本的 powershell 中运行哪个版本的 installutil?(我想我尝试了每一种组合,但仍然遇到同样的问题)。

还有一个问题:完成这项工作后,我需要与 32 位 COM 对象进行交互,我应该如何设置项目?

4

1 回答 1

5

如果您的目标是 PowerShell V1/V2,那么您应该以 .NET 2.0 为目标。如果您的目标是 V3/V4,那么您应该以 .NET 4.0 为目标。如果您不必支持 V1,则根本不要使用管理单元。除了不需要 PSSnapin 类并且不需要运行 installutil 之外,您的二进制文件可以保持不变。您只需通过绝对路径加载它:

Import-Module -Path c:\temp\mybinary.dll

或者,如果您将 dll 放入 Modules 目录 (~\Documents\WindowsPowerShell\Modules\MyBinary\MyBinary.dll),只需按名称:

Import-Module MyBinary
于 2013-11-14T13:56:50.487 回答