我有一个非常简单的 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!");
}
}
最佳答案
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
注意框架路径中的 64。
关于C# Powershell 管理单元未使用 installutil 注册,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/558577/