我有一个非常简单的PowerShell脚本(见下文)。 我在我的个人资料中使用以下内容获得了installutil别名:
set-alias installutil $env:windir\Microsoft.NET\Framework\v2.0.50727\installutil
在powershell中,我只是:
installutil assemplylocation.dll
这会成功返回。 (安装/提交都成功完成)。 然而,当我检查注册表时,或者在使用get-pssnapin -registered的powershell中,它没有显示我的程序集。我前几天做了这个,它工作正常,但我似乎无法复制它...请指教。
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!");
}
}
}
答案 0 :(得分:13)
downatone的回答让我走上正轨,但我的问题恰恰相反。我的项目设置为任何CPU,我在Win7 x64上,所以PowerShell从我的代码启动,然后用snapin安装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
注意Framework路径中的64。
答案 1 :(得分:11)
原来问题是我有一个32位cmdlet - 但只检查了powerhell的64位版本...
答案 2 :(得分:1)
您是否将installutil作为提升用户运行?它将信息写入注册表的受保护部分。如果您在Vista上以非管理员身份执行此操作,则会产生奇怪的结果。
答案 3 :(得分:1)
以管理员身份运行以运行ps
答案 4 :(得分:1)
这里的关键点是记住Visual Studio 2010仍然是32位应用程序,这意味着当我使用命令提示符时,它默认为32位的InstallUtil变体。在这种情况下,注册表项不会立即写入Wow64位节点而不是64位注册表。
答案 5 :(得分:0)
遇到同样的问题 - 我试图使用命令
C:\Windows\Microsoft.net\Framework\V4.0.30319\installutil myDLL.dll
而不是
C:\Windows\Microsoft.net\Framework64\V4.0.30319\installutil myDLL.dll
虽然在操作系统win2k8 x64上有64位cmdlet(项目配置。任何CPU)..
答案 6 :(得分:0)
我不得不使用x86(32位)版本的PowerShell来添加Snapin。正如我发现它不是那么直接,因为它应该是一个有用的链接如何打开PowerShell 32位: