1 c# powershell cmdlets installutil
我已经看到了一些类似的问题,但仍然无法弄清楚如何解决它:我有一个简单的PowerShell cmdlet(只是添加参数)和一个snapin来注册它.问题是我尝试运行installutil我得到
No public installers with the RunInstallerAttribute.Yes attribute could be found
Run Code Online (Sandbox Code Playgroud)
snapin代码:
using System.ComponentModel;
using System.Management.Automation;
namespace Cmdtlets
{
[RunInstaller(true)]
class BugBoxSnapin : PSSnapIn
{
}
}
Run Code Online (Sandbox Code Playgroud)
我知道有64个32位版本的installutil以及x86和x64 powershells.我的配置是 - 64位机器,平台目标"任何CPU",.NET Framework 4.5.我无法从visual studio引用选择器引用System.Management.Automation,所以我手动更改了csproj文件
<Reference Include="System.Management.Automation" />
Run Code Online (Sandbox Code Playgroud)
我应该在哪个版本的powershell中运行哪个版本的installutil?(我想我尝试了所有组合,但仍然遇到同样的问题).
还有一个问题:在这个工作之后,我将需要与32位COM对象进行交互,我应该如何设置项目?
如果您的目标是PowerShell V1/V2,那么您应该以.NET 2.0为目标.如果您的目标是V3/V4,那么您应该定位到.NET 4.0.如果你没有支持V1,则不要在使用管理单元所有.您的二进制文件可以保持不变,除了您不需要PSSnapin类并且您不需要运行installutil.你只需通过绝对路径加载它:
Import-Module -Path c:\temp\mybinary.dll
Run Code Online (Sandbox Code Playgroud)
或者,如果您将dll放在Modules目录(〜\ Documents\WindowsPowerShell\Modules\MyBinary\MyBinary.dll)中,只需按名称:
Import-Module MyBinary
Run Code Online (Sandbox Code Playgroud)