C# Powershell 管理单元未使用 installutil 注册

发布于 2024-07-13 14:50:35 字数 1639 浏览 6 评论 0原文

我有一个非常简单的 powershell 脚本(见下文)。 我在我的个人资料中使用以下内容为 installutil 指定了别名:

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

在 powershell 中我只是:

installutil assemplylocation.dll

这会成功返回。 (安装/提交均成功完成)。 然而,当我检查注册表或在 powershell 中使用 get-pssnapin -registered 时,它不会显示我的程序集。 前几天我这样做了,效果很好,但我似乎无法复制它......请告知。

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!");
    }
}

}

I've got a really simple powershell script (see below).
I've got installutil aliased using the following in my profile:

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

In powershell I simply:

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. 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!");
    }
}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

魂牵梦绕锁你心扉 2024-07-20 14:50:35

downatone的回答让我走上了正轨,但我的问题却恰恰相反。 我的项目设置为任何 CPU,并且我使用的是 Win7 x64,因此从我的代码启动 powershell,然后使用管理单元安装 dll 是 64 位。 然而,我使用的安装命令指向 32 位 .net 运行时,即

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

应该

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

注意框架路径中的 64。

downatone's answer put me on the right track but my problem was the opposite way round. 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. However the install command I used was pointing to the 32 bit .net runtime i.e.

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.

幸福%小乖 2024-07-20 14:50:35

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

Turns out the issue was that I had a 32-bit cmdlet - but was only checking the 64-bit version of powershell ...

素罗衫 2024-07-20 14:50:35

您是否以提升用户身份运行 installutil? 它将信息写入注册表的受保护部分。 如果您在 Vista 上以非管理员身份执行此操作,可能会产生奇怪的结果。

Did you run installutil as an elevated user? It writes information to protected portions of the registry. If you do this as a non-admin on Vista it can produce strange results.

情释 2024-07-20 14:50:35

以管理员身份运行 ps

run as administrator to run ps

一生独一 2024-07-20 14:50:35

对我来说,这里的关键点是记住 Visual Studio 2010 仍然是一个 32 位应用程序,这意味着当我使用命令提示符时,它默认为 InstallUtil 的 32 位变体。 在这种情况下,注册表项是否会写入 Wow64 位节点而不是正确的 64 位注册表,这一点并不明显。

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. 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.

聽兲甴掵 2024-07-20 14:50:35

遇到同样的问题——
我试图在操作系统 win2k8 x64 上使用命令

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

而不是

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

使用 64 位 cmdlet(项目配置。任何 CPU)。

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..

尬尬 2024-07-20 14:50:35

我必须使用 x86(32 位)版本的 PowerShell 来添加管理单元。 因为我发现它并不像想象的那么简单,这里有一个有用的链接如何打开 PowerShell 32 位:

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

I had to use the x86 (32bit) version of PowerShell to add the 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:

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文