0

基本的にコードはmsdn.microsoft.comからのものです

コードをビルドした後、コマンドプロンプトを開き、次のように入力します。Installutil -i%path%/ Mycmdlets.dll

結果は、インストールフェーズが正常に完了し、コミットフェーズも正常に完了したことを示しています。しかし私が行くなら:

Get-PSSnapin -Registered、sqlServerCmdletSnapinのみが表示されますが、コマンドレットがありません。pssnapinの追加も機能しません。

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

namespace Mycmdlets
{

[Cmdlet("hy", "Hello")]
public class GetHelloCommand : Cmdlet
{
    protected override void EndProcessing()
    {
        WriteObject("Hello", true);
    }
}

[RunInstaller(true)]
public class GetProcPSSnapIn01 : PSSnapIn
{
    /// <summary>
    /// Create an instance of the GetProcPSSnapIn01 class.
    /// </summary>
    public GetProcPSSnapIn01()
        : base()
    {
    }

    /// <summary>
    /// Specify the name of the PowerShell snap-in.
    /// </summary>
    public override string Name
    {
        get
        {
            return "GetProcPSSnapIn01";
        }
    }

    /// <summary>
    /// Specify the vendor for the PowerShell snap-in.
    /// </summary>
    public override string Vendor
    {
        get
        {
            return "Microsoft";
        }
    }

    /// <summary>
    /// Specify the localization resource information for the vendor. 
    /// Use the format: resourceBaseName,VendorName. 
    /// </summary>
    public override string VendorResource
    {
        get
        {
            return "GetProcPSSnapIn01,Microsoft";
        }
    }

    /// <summary>
    /// Specify a description of the PowerShell snap-in.
    /// </summary>
    public override string Description
    {
        get
        {
            return "This is a PowerShell snap-in that includes the get-proc cmdlet.";
        }
    }

    /// <summary>
    /// Specify the localization resource information for the description. 
    /// Use the format: resourceBaseName,Description. 
    /// </summary>
    public override string DescriptionResource
    {
        get
        {
            return "GetProcPSSnapIn01,This is a PowerShell snap-in that includes the get-proc cmdlet.";
        }
    }
}
}

編集:

解決策を知りたい人にとって、原因は単にシステムがx64をサポートしていないことです。解決策は、単にc#プロジェクトのプロパティにあり、プラットフォームターゲットをx86またはx64ではなく「任意のCPU」にすることです。

また、Get-PSSnapinはエラーメッセージを表示しませんが、VisualStudioのコマンドプロンプトから実行している場合は正常に機能していると表示されます。ただし、PowerShellコマンドプロンプトで実行すると、失敗したメッセージが表示されます。

4

1 に答える 1

0

Nachtのコメントごとに、答えを貼り付けます:

解決策を知りたい人にとっては、原因は単にシステムが x64 をサポートしていないことです。解決策は単に c# プロジェクトのプロパティにあります。プラットフォーム ターゲットを x86 または x64 ではなく「任意の CPU」にします。

また、Get-PSSnapin はエラー メッセージを表示しませんが、Visual Studio のコマンド プロンプトから実行している場合は正常に動作していると表示されます。ただし、powershell コマンド プロンプトで実行すると、失敗のメッセージが表示されます。

于 2013-12-11T16:11:34.340 に答える