简体   繁体   English

C#Powershell snapin没有使用installutil进行注册

[英]C# Powershell snapin not registering using installutil

I've got a really simple powershell script (see below). 我有一个非常简单的PowerShell脚本(见下文)。 I've got installutil aliased using the following in my profile: 我在我的个人资料中使用以下内容获得了installutil别名:

set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil

In powershell I simply: 在powershell中我简单地说:

installutil assemplylocation.dll

This returns successfully. 这成功返回。 (Install/Commit both complete successfully). (安装/提交都成功完成)。 Yet when I check the registry, or in powershell using get-pssnapin -registered it doesn't show my assembly. 然而,当我检查注册表时,或者在使用get-pssnapin -registered的powershell中,它没有显示我的程序集。 I did this the other day and it worked fine, but I don't seem to be able to duplicate it ... please advise. 我前几天做了这个,它工作正常,但我似乎无法复制它...请指教。

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

namespace PSBook_2_1
{
    [RunInstaller(true)]
    public class PSBookChapter2MySnapIn : PSSnapIn
    {
        public PSBookChapter2MySnapIn()
            : base()
        { }

    // Name for the PowerShell snap-in.
    public override string Name
    {
        get
        {
            return "Wiley.PSProfessional.Chapter2";
        }
    }

    // Vendor information for the PowerShell snap-in.
    public override string Vendor
    {
        get
        {
            return "Wiley";
        }
    }

    // Description of the PowerShell snap-in
    public override string Description
    {
        get
        {
            return "This is a sample PowerShell snap-in";
        }
    }
}

// Code to implement cmdlet Write-Hi
[Cmdlet(VerbsCommunications.Write, "Hi")]
public class SayHi : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hi, World!");
    }
}

// Code to implement cmdlet Write-Hello
[Cmdlet(VerbsCommunications.Write, "Hello")]
public class SayHello : Cmdlet
{
    protected override void ProcessRecord()
    {
        WriteObject("Hello, World!");
    }
}

} }

downatone's answer put me on the right track but my problem was the opposite way round. downatone的回答让我走上正轨,但我的问题恰恰相反。 My project is set to any CPU and I am on Win7 x64 so the powershell being launched from my code and then installing the dll with the snapin was 64 bit. 我的项目设置为任何CPU,我在Win7 x64上,所以PowerShell从我的代码启动,然后用snapin安装dll是64位。 However the install command I used was pointing to the 32 bit .net runtime ie 但是我使用的安装命令指向32位.net运行时ie

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll

when it should have been 什么时候应该

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll

Note the 64 in the Framework path. 请注意Framework路径中的64。

原来问题是我有一个32位cmdlet - 但只是检查了64位版本的powershell ...

以管理员身份运行以运行ps

Did you run installutil as an elevated user? 您是否将installutil作为提升用户运行? It writes information to protected portions of the registry. 它将信息写入注册表的受保护部分。 If you do this as a non-admin on Vista it can produce strange results. 如果您在Vista上以非管理员身份执行此操作,则会产生奇怪的结果。

The key point for me here was remembering that Visual Studio 2010 is still a 32 bit application meaning that when I used the Command Prompt it defaulted to the 32-bit variant of InstallUtil. 这里的关键点是记住Visual Studio 2010仍然是一个32位应用程序,这意味着当我使用命令提示符时,它默认为32位的InstallUtil变体。 Its not immediately obvious in this case that the registry keys are therefore written to the Wow64-bit node instead of the 64-bit registry proper. 在这种情况下,并不是很明显,因此注册表键被写入Wow64位节点而不是64位注册表。

I had to use the x86 (32bit) version of PowerShell to add the Snapin. 我不得不使用x86(32位)版本的PowerShell来添加Snapin。 As I found it not as straight forward as it's supposed to be here's a helpful link how to open PowerShell 32bit: 正如我发现它不是那么直接,因为它应该是一个有用的链接如何打开PowerShell 32位:

http://technet.microsoft.com/en-us/library/hh847733.aspx http://technet.microsoft.com/en-us/library/hh847733.aspx

Experienced the same issue - I was trying to use command 遇到同样的问题 - 我试图使用命令

C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll 

instead of 代替

C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll 

while having 64 bit cmdlet (project config. Any CPU) on OS win2k8 x64.. 在操作系统win2k8 x64上有64位cmdlet(项目配置。任何CPU)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM