简体   繁体   中英

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. However, when I added gacutil and installutil to deploy the snapin using post-built, I got this error:

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.

I checked and the framework used was correct 4.5.1, VS 2013, system is 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.

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. I would recommend using a module . There is no registration/installation required. You just xcopy the module to the target system ($home\\Documents\\WindowsPowerShell\\Modules) and use it. I would recommend that you create a PSD1 manifest file for your module. The RootModule will be the name of your dll: Tools.Powershell.Printscreen.dll. Check out the New-ModuleManifest command for help creating the PSD1 file. 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. 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):

Import-Module -assembly c:\temp\Tools.Powershell.Printscreen.dll

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM