簡體   English   中英

無法注冊C#Powershell管理單元

[英]Cannot register C# Powershell snapin

我已經看到了許多類似的問題,但是仍然無法弄清楚如何解決它:我有一個簡單的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對象進行交互,該如何設置項目?

如果您以PowerShell V1 / V2為目標,則應以.NET 2.0為目標。 如果您以V3 / V4為目標,則應該以.NET 4.0為目標。 如果你沒有支持V1,那么就不要在所有使用管理單元。 您的二進制文件可以保持相同,除了不需要PSSnapin類並且不需要運行installutil。 您可以通過絕對路徑加載它:

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

或者,如果您將dll放在模塊目錄(〜\\ Documents \\ WindowsPowerShell \\ Modules \\ MyBinary \\ MyBinary.dll)中,只需按名稱即可:

Import-Module MyBinary

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM