DeCaf
DeCaf

Reputation: 6086

Bug in Wix? Is ps:SnapIn writing to the wrong registry key with PowerShell 3.0?

We have a PowerShell snapin that requires version 3.0 of PowerShell to function. So we used the following file element in a WiX (3.8) file:

        <File Id="MySnapin.dll" 
              Name="MySnapin.dll" 
              Assembly=".net" 
              KeyPath="yes" 
              Vital="no" 
              Checksum="yes" 
              DiskId="1" 
              Source="$(var.FilesPath)\Bin\MySnapin.dll" 
              AssemblyApplication="MySnapin.dll">
           <ps:SnapIn Id="MySnapin" 
                      Description="This is a PowerShell snap-in" 
                      Vendor="My Company Inc." 
                      RequiredPowerShellVersion="3.0">
                <ps:FormatsFile FileId="MySnapin.format.ps1xml" />
           </ps:SnapIn>
        </File>

However, when installing this the snapin cannot be found in powershell (Get-PSSnapIn -Registered). When examining the registry it turns out that the snapin has been registered in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\3\PowerShellSnapIns\MySnapin. But when running installutil.exe on the DLL, the registration ends up in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\PowerShell\1\PowerShellSnapIns\MySnapin, and powershell finds it properly. Is this a bug in WiX Toolset, or am I doing something wrong here?

Where are the registrations really supposed to go?

Upvotes: 0

Views: 247

Answers (1)

Mike Zboray
Mike Zboray

Reputation: 40808

Yea this sounds like a bug, so you might want to report it to the WiX maintainers, but there is better way.

The recommended way to add cmdlets and functions is through PowerShell Modules. Snap-ins are the older way to extend PowerShell and while still supported are not recommended. If you do not need to support adding your cmdlets to older versions of PowerShell use a module.

Modules are somewhat easier to deploy than snap-ins. Basically you can put them anywhere, however if you want users to be able to load them by name they need to exist on the PSModulePath environment variable. Your installer would add your files and update the PSModulePath variable to include a Modules folder from your install folder. Then users will simply be able to call Import-Module MyModule to load them. Also, see the documentation on PSModulePath.

This blog post contains a detailed walkthrough of how to write a WiX installer to do this. It also has instructions on how to check that the required PowerShell version is installed. Basically, you are going to check the under both those registry keys you mentioned for the PowerShellEngine\PowerShellVersion value.

Upvotes: 2

Related Questions