Skip to content

Commit dcd0f6c

Browse files
committed
Fix installation of PowerShell extension
The old Snap-In mechanism to register PowerShell extensions has been deprecated and should not be used anymore. Instead use the new Module mechanism which was introduced with PowerShell 2.0 and is much simpler. It allows us to drop a good chunk of code and streamlines the installation (e.g. we don't need to call InstallUtil.exe anymore). We ship the module in our product directory and update PSModulePath in the installer accordingly. For module autoloading to work, we need to ship a module manifest file and and follow certain naming rules which are detailed in: https://docs.microsoft.com/en-us/powershell/scripting/developer/module/installing-a-powershell-module After the installation you can list available modules via: > Get-Module -List-Available which should now show our PHPManager module. You can load it using: > Import-Module PHPManager Fixes: phpmanager#33
1 parent 5bc02bf commit dcd0f6c

File tree

7 files changed

+139
-184
lines changed

7 files changed

+139
-184
lines changed

Powershell/Installer.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

Powershell/PHPManager.psd1

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#
2+
# Module manifest for module 'PHPManager'
3+
#
4+
# Generated by: PHP Manager Project
5+
#
6+
# Generated on: 31.03.2021
7+
#
8+
9+
@{
10+
11+
# Script module or binary module file associated with this manifest.
12+
RootModule = 'Web.Management.PHP.Powershell.dll'
13+
14+
# Version number of this module.
15+
ModuleVersion = '2.5.0.0'
16+
17+
# Supported PSEditions
18+
# CompatiblePSEditions = @()
19+
20+
# ID used to uniquely identify this module
21+
GUID = '3a733bfb-aedc-493a-a431-aaba87873112'
22+
23+
# Author of this module
24+
Author = 'PHP Manager Project'
25+
26+
# Company or vendor of this module
27+
CompanyName = 'PHP Manager Project'
28+
29+
# Copyright statement for this module
30+
Copyright = '(c) 2021 PHP Manager Project. All rights reserved.'
31+
32+
# Description of the functionality provided by this module
33+
# Description = ''
34+
35+
# Minimum version of the Windows PowerShell engine required by this module
36+
# PowerShellVersion = ''
37+
38+
# Name of the Windows PowerShell host required by this module
39+
# PowerShellHostName = ''
40+
41+
# Minimum version of the Windows PowerShell host required by this module
42+
# PowerShellHostVersion = ''
43+
44+
# Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
45+
# DotNetFrameworkVersion = ''
46+
47+
# Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only.
48+
# CLRVersion = ''
49+
50+
# Processor architecture (None, X86, Amd64) required by this module
51+
# ProcessorArchitecture = ''
52+
53+
# Modules that must be imported into the global environment prior to importing this module
54+
# RequiredModules = @()
55+
56+
# Assemblies that must be loaded prior to importing this module
57+
# RequiredAssemblies = @()
58+
59+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
60+
# ScriptsToProcess = @()
61+
62+
# Type files (.ps1xml) to be loaded when importing this module
63+
# TypesToProcess = @()
64+
65+
# Format files (.ps1xml) to be loaded when importing this module
66+
# FormatsToProcess = @()
67+
68+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
69+
# NestedModules = @()
70+
71+
# Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export.
72+
FunctionsToExport = '*'
73+
74+
# Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export.
75+
CmdletsToExport = '*'
76+
77+
# Variables to export from this module
78+
VariablesToExport = '*'
79+
80+
# Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export.
81+
AliasesToExport = '*'
82+
83+
# DSC resources to export from this module
84+
# DscResourcesToExport = @()
85+
86+
# List of all modules packaged with this module
87+
# ModuleList = @()
88+
89+
# List of all files packaged with this module
90+
# FileList = @()
91+
92+
# Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
93+
PrivateData = @{
94+
95+
PSData = @{
96+
97+
# Tags applied to this module. These help with module discovery in online galleries.
98+
# Tags = @()
99+
100+
# A URL to the license for this module.
101+
# LicenseUri = ''
102+
103+
# A URL to the main website for this project.
104+
# ProjectUri = ''
105+
106+
# A URL to an icon representing this module.
107+
# IconUri = ''
108+
109+
# ReleaseNotes of this module
110+
# ReleaseNotes = ''
111+
112+
} # End of PSData hashtable
113+
114+
} # End of PrivateData hashtable
115+
116+
# HelpInfo URI of this module
117+
# HelpInfoURI = ''
118+
119+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
120+
# DefaultCommandPrefix = ''
121+
122+
}
123+

Powershell/PHPManagerPowershell.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@
6161
<Compile Include="GetPHPSettingCmdlet.cs" />
6262
<Compile Include="GetPHPVersionCmdlet.cs" />
6363
<Compile Include="Helper.cs" />
64-
<Compile Include="Installer.cs">
65-
<SubType>Component</SubType>
66-
</Compile>
6764
<Compile Include="NewPHPSettingCmdlet.cs" />
6865
<Compile Include="NewPHPVersionCmdlet.cs" />
6966
<Compile Include="PHPConfigurationItem.cs" />
@@ -86,6 +83,9 @@
8683
<Link>phpmgrpublic.snk</Link>
8784
</None>
8885
<None Include="Documentation\Remove-WarningStuff.ps1" />
86+
<None Include="PHPManager.psd1">
87+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
88+
</None>
8989
</ItemGroup>
9090
<ItemGroup>
9191
<EmbeddedResource Include="Resources.resx">

Setup/PHPManagerSetupHelper/InstallUtil.cs

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ private static void Execute(string name, string type)
4343
iisVersion == 7 ? "v3.5" : "v4.0.30319"))));
4444
var assembly = Assembly.GetExecutingAssembly();
4545
RegisterIIS(framework, assembly, name, type);
46-
RegisterSnapin(framework, assembly, type);
4746
}
4847

4948
private static void RegisterIIS(string framework, Assembly assembly, string name, string type)
@@ -100,54 +99,6 @@ private static void RegisterIIS(string framework, Assembly assembly, string name
10099
File.Delete(program);
101100
}
102101

103-
private static void RegisterSnapin(string framework, Assembly assembly, string type)
104-
{
105-
var compiler = Path.Combine(framework, "csc.exe");
106-
107-
var source = Path.GetTempFileName();
108-
var program = source + ".powershell.exe";
109-
using (var stream = assembly.GetManifestResourceStream("Web.Management.PHP.Setup.Program2.cs"))
110-
using (StreamReader reader = new StreamReader(stream))
111-
{
112-
var content = reader.ReadToEnd();
113-
File.WriteAllText(source, content);
114-
}
115-
116-
using (var process = new Process
117-
{
118-
StartInfo = new ProcessStartInfo
119-
{
120-
FileName = compiler,
121-
Arguments = string.Format("/out:\"{0}\" \"{1}\"", program, source),
122-
WindowStyle = ProcessWindowStyle.Hidden,
123-
CreateNoWindow = true
124-
}
125-
})
126-
{
127-
process.Start();
128-
process.WaitForExit();
129-
}
130-
131-
File.Delete(source);
132-
133-
using (var process = new Process
134-
{
135-
StartInfo = new ProcessStartInfo
136-
{
137-
FileName = program,
138-
Arguments = type == null ? string.Format("/u \"{0}\"", assembly.Location) : string.Format("/i \"{0}\"", assembly.Location),
139-
WindowStyle = ProcessWindowStyle.Hidden,
140-
CreateNoWindow = true
141-
}
142-
})
143-
{
144-
process.Start();
145-
process.WaitForExit();
146-
}
147-
148-
File.Delete(program);
149-
}
150-
151102
/// <summary>
152103
/// Removes the specified UI Module by name
153104
/// </summary>

Setup/PHPManagerSetupHelper/PHPManagerSetupHelper.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
</Compile>
5959
<Compile Include="InstallUtil.cs" />
6060
<EmbeddedResource Include="Program.cs" />
61-
<EmbeddedResource Include="Program2.cs" />
6261
<Compile Include="SetupAction.cs">
6362
<SubType>Component</SubType>
6463
</Compile>

Setup/PHPManagerSetupHelper/Program2.cs

Lines changed: 0 additions & 79 deletions
This file was deleted.

Setup/Product.wxs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@
7474
<ComponentRef Id="Web.Management.PHP.Client.resources.dll.ru_RU.GAC_comp" />
7575

7676
<!-- Files installed -->
77+
<ComponentRef Id="License.rtf" />
7778
<ComponentRef Id="Web.Management.PHP.dll" />
7879
<ComponentRef Id="Web.Management.PHP.Client.dll" />
7980
<ComponentRef Id="Web.Management.PHP.Setup.dll" />
8081
<ComponentRef Id="Web.Management.PHP.PowerShell.dll" />
81-
<ComponentRef Id="Web.Management.PHP.PowerShell.dllHelp.xml" />
8282
<ComponentRef Id="Web.Management.PHP.Client.resources.dll.zh_CN.comp" />
8383
<ComponentRef Id="Web.Management.PHP.Client.resources.dll.zh_TW.comp" />
8484
<ComponentRef Id="Web.Management.PHP.Client.resources.dll.fr_FR.comp" />
@@ -94,9 +94,8 @@
9494
<Directory Id="TARGETDIR" Name="SourceDir">
9595
<Directory Id="$(var.PlatformProgramFilesFolder)">
9696
<Directory Id="INSTALLDIR" Name="$(var.ProductName)">
97-
<Component Id="Web.Management.PHP.PowerShell.dllHelp.xml" Guid="{268F5728-D8FB-4397-BC1B-4922BC8FD7AD}">
98-
<File Id="License.rtf" Name="License.rtf" Vital="no" DiskId="1" Source="License.rtf" />
99-
<File Id="Web.Management.PHP.PowerShell.dllHelp.xml" Name="Web.Management.PHP.PowerShell.dll-Help.xml" KeyPath="yes" Vital="no" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.PowerShell.dll-Help.xml" />
97+
<Component Id="License.rtf" Guid="{268F5728-D8FB-4397-BC1B-4922BC8FD7AD}">
98+
<File Id="License.rtf" Name="License.rtf" KeyPath="yes" Vital="no" DiskId="1" Source="License.rtf" />
10099
</Component>
101100
<Component Id="Web.Management.PHP.Client.dll" Guid="{319C1A86-58E7-45EA-9408-EFB366F2A2F4}">
102101
<File Id="Web.Management.PHP.Client.dll" Name="Web.Management.PHP.Client.dll" KeyPath="yes" Vital="no" Assembly=".net" AssemblyApplication="Web.Management.PHP.Client.dll" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.Client.dll" />
@@ -109,9 +108,16 @@
109108
<Component Id="Web.Management.PHP.dll" Guid="{3D24E10F-5B3F-4796-99CE-3DA5D0E947DA}">
110109
<File Id="Web.Management.PHP.dll" Name="Web.Management.PHP.dll" KeyPath="yes" Vital="no" Assembly=".net" AssemblyApplication="Web.Management.PHP.dll" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.dll" />
111110
</Component>
112-
<Component Id="Web.Management.PHP.PowerShell.dll" Guid="{4F2601CE-2A0F-430A-ADC6-F75F318CD2E7}">
113-
<File Id="Web.Management.PHP.PowerShell.dll" Name="Web.Management.PHP.PowerShell.dll" KeyPath="yes" Vital="no" Assembly=".net" AssemblyApplication="Web.Management.PHP.PowerShell.dll" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.PowerShell.dll" />
114-
</Component>
111+
<Directory Id="Modules_Dir" Name="Modules">
112+
<Directory Id="PHPManager" Name="PHPManager">
113+
<Component Id="Web.Management.PHP.PowerShell.dll" Guid="{4F2601CE-2A0F-430A-ADC6-F75F318CD2E7}">
114+
<File Id="Web.Management.PHP.PowerShell.dll" Name="Web.Management.PHP.PowerShell.dll" KeyPath="yes" Vital="no" Assembly=".net" AssemblyApplication="Web.Management.PHP.PowerShell.dll" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.PowerShell.dll" />
115+
<File Id="Web.Management.PHP.PowerShell.dllHelp.xml" Name="Web.Management.PHP.PowerShell.dll-Help.xml" Vital="no" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.PowerShell.dll-Help.xml" />
116+
<File Id="PHPManager.psd1" Name="PHPManager.psd1" Vital="no" DiskId="1" Source="$(var.SourceDir)\PHPManager.psd1" />
117+
<Environment Id="PSModulePath" Name="PSModulePath" Value="[Modules_Dir]" Permanent="no" Part="last" Action="set" System="yes" />
118+
</Component>
119+
</Directory>
120+
</Directory>
115121
<Directory Id="GACFiles_Dir" Name="GAC">
116122
<Component Id="Web.Management.PHP.Client.dll.GAC_comp" Guid="{F576C18C-A14D-4732-B13F-24E7D80C797C}">
117123
<File Id="Web.Management.PHP.Client.dll.GAC_comp" Name="Web.Management.PHP.Client.dll" KeyPath="yes" Vital="no" Assembly=".net" DiskId="1" Source="$(var.SourceDir)\Web.Management.PHP.Client.dll" />

0 commit comments

Comments
 (0)