[英]Post-build Error when using gacutil and installutil to deploy powershell snapin
I am trying to learn about writing snapin for powershell 4.0 using VS 2013. The script is very simple and compiled with no error. 我正在尝试学习有关使用VS 2013为powershell 4.0编写管理单元的知识。该脚本非常简单且编译无误。 However, when I added gacutil and installutil to deploy the snapin using post-built, I got this error:
但是,当我添加gacutil和installutil使用后构建来部署管理单元时,出现此错误:
Error 1
The command ""C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\gacutil.exe" -if "Tools.Powershell.Printscreen.dll"
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" "Tools.Powershell.Printscreen.dll"" exited with code -1.
However, if I copied the commands and ran it from command prompt, both commands ran successfully and the installation was successfully deployed. 但是,如果我复制命令并从命令提示符处运行它,则两个命令均成功运行并且安装已成功部署。 I can then add the snapin to powershell, the snapin ran successfully as well.
然后,我可以添加到PowerShell中的管理单元,该管理单元成功运行为好。
I checked and the framework used was correct 4.5.1, VS 2013, system is windows 8.1 我被检查和使用该框架是正确的4.5.1,VS 2013,系统是Windows 8.1中
The post-build commands are: 生成后命令为:
"C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\x64\gacutil.exe" -if "$(TargetPath)"
"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\InstallUtil.exe" "$(TargetPath)"
I think at this point the code for the snapin is irrelevant but if you want me to include, please let me know. 我认为这时该管理单元的代码无关紧要,但是如果您要包含我的代码,请告诉我。 I do not believe it is going to affect the solution at this point bc it is simple at best and it worked after I deployed it manually using command prompt.
我不认为这会影响到在这一点上解决BC它是简单充其量,它的工作后,我部署它使用命令提示符手动。
Please advise. 请指教。
Thanks! 谢谢!
Why build a snapin unless you need to target V1 which you can't if you're compiling against .NET 4.5.1. 为什么要构建一个管理单元,除非您需要针对V1,而如果要针对.NET 4.5.1进行编译则无法实现。 I would recommend using a
module
. 我建议使用
module
。 There is no registration/installation required. 无需注册/安装。 You just xcopy the module to the target system ($home\\Documents\\WindowsPowerShell\\Modules) and use it.
您只需将模块复制到目标系统($ home \\ Documents \\ WindowsPowerShell \\ Modules)并使用它。 I would recommend that you create a PSD1 manifest file for your module.
我建议您为模块创建一个PSD1清单文件。 The
RootModule
will be the name of your dll: Tools.Powershell.Printscreen.dll. RootModule
将是您的dll的名称:Tools.Powershell.Printscreen.dll。 Check out the New-ModuleManifest
command for help creating the PSD1
file. PSD1
出New-ModuleManifest
命令以获取有关创建PSD1
文件的帮助。 It is basic stuff like author name, version, GUID to uniquely identify the module, etc. I also recommend that you list your exported cmdlets in the CmdletsToExport
field. 它是基本的东西,例如作者名称,版本,唯一标识模块的GUID等。我还建议您在
CmdletsToExport
字段中列出导出的cmdlet。 This will speed processing for automatic module loading. 这将加快自动模块加载的处理速度。
And in a pinch, for testing purposes, you can just import the dll directly (without having to create a PSD1 file): 而且,出于测试目的,您可以直接导入dll(而无需创建PSD1文件):
Import-Module -assembly c:\temp\Tools.Powershell.Printscreen.dll
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.