You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -44,17 +44,20 @@ Beyond PowerShell 3.0, keys started being added to a `PSData` subsection of the
44
44
45
45
Fast forward to today, and things have changed enough that we can reconsider how we set up a module manifest. `Import-Module` has been checking the required version of PowerShell before validating key names for several years now, at least since PowerShell 5.1, and earlier versions of Windows PowerShell are no longer on mainstream support.
46
46
47
-
With all of this in mind, this proposal is to flatten the module manifest structure, reading values for keys at the root first, and then if they are not set at the root, looking in the `PSData` section under `PrivateData` for backwards compatibility support. Future keys added to the manifest as part of PowerShell should all be added to the root, leaving `PrivateData` for 3rd party or user information in a manifest, as originally intended.
47
+
With all of this in mind, this proposal is to accomplish two things:
48
+
49
+
1. To flatten the module manifest structure for the current version of PowerShell (whichever version this gets implemented in), reading values for keys at the root first, and then if they are not set at the root, looking in the `PSData` section under `PrivateData` for backwards compatibility support. Future keys added to the manifest as part of PowerShell should all be added to the root, leaving `PrivateData` for 3rd party or user information in a manifest, as originally intended.
50
+
1. To make the current version of PowerShell a default value for `-PowerShellVersion`, and update `New-ModuleManifest` such that it generates an appropriate manifest for the version of PowerShell indicated in the `-PowerShellVersion` parameter, so that scripters can create manifests for modules on newer versions of PowerShell that are properly structured to support older versions of PowerShell as well.
48
51
49
52
## Motivation
50
53
51
54
As a scripter,
52
-
I can generate manifests using `New-ModuleManifest` with all keys stored at the root of the hashtable,
53
-
so that I can work with module manifests more easily.
55
+
I can generate manifests using `New-ModuleManifest` for any supported version of PowerShell,
56
+
so that I can work with module manifests more easily in the current version without letting go of compatibilty support for downlevel versions.
54
57
55
58
## User Experience
56
59
57
-
Here's an example showing how `New-ModuleManifest` would work after this change:
60
+
Here's an example showing how `New-ModuleManifest` would work with the default value of `-PowerShellVersion`after this change:
# Script module or binary module file associated with this manifest.
203
+
# ModuleToProcess = ''
204
+
205
+
# Version number of this module.
206
+
ModuleVersion = '1.0'
207
+
208
+
# ID used to uniquely identify this module
209
+
GUID = '47179120-0bcb-4f14-8d80-f4560107f85c'
210
+
211
+
# Author of this module
212
+
Author = 'kirka'
213
+
214
+
# Company or vendor of this module
215
+
CompanyName = 'Unknown'
216
+
217
+
# Copyright statement for this module
218
+
Copyright = '(c) 2019 kirka. All rights reserved.'
219
+
220
+
# Description of the functionality provided by this module
221
+
# Description = ''
222
+
223
+
# Minimum version of the Windows PowerShell engine required by this module
224
+
PowerShellVersion = '2.0'
225
+
226
+
# Name of the Windows PowerShell host required by this module
227
+
# PowerShellHostName = ''
228
+
229
+
# Minimum version of the Windows PowerShell host required by this module
230
+
# PowerShellHostVersion = ''
231
+
232
+
# Minimum version of the .NET Framework required by this module
233
+
# DotNetFrameworkVersion = ''
234
+
235
+
# Minimum version of the common language runtime (CLR) required by this module
236
+
# CLRVersion = ''
237
+
238
+
# Processor architecture (None, X86, Amd64) required by this module
239
+
# ProcessorArchitecture = ''
240
+
241
+
# Modules that must be imported into the global environment prior to importing this module
242
+
# RequiredModules = @()
243
+
244
+
# Assemblies that must be loaded prior to importing this module
245
+
# RequiredAssemblies = @()
246
+
247
+
# Script files (.ps1) that are run in the caller's environment prior to importing this module.
248
+
# ScriptsToProcess = @()
249
+
250
+
# Type files (.ps1xml) to be loaded when importing this module
251
+
# TypesToProcess = @()
252
+
253
+
# Format files (.ps1xml) to be loaded when importing this module
254
+
# FormatsToProcess = @()
255
+
256
+
# Modules to import as nested modules of the module specified in RootModule/ModuleToProcess
257
+
# NestedModules = @()
258
+
259
+
# Functions to export from this module
260
+
FunctionsToExport = @()
261
+
262
+
# Cmdlets to export from this module
263
+
CmdletsToExport = @()
264
+
265
+
# Variables to export from this module
266
+
VariablesToExport = @()
267
+
268
+
# Aliases to export from this module
269
+
AliasesToExport = @()
270
+
271
+
# List of all modules packaged with this module.
272
+
# ModuleList = @()
273
+
274
+
# List of all files packaged with this module
275
+
# FileList = @()
276
+
277
+
# Private data to pass to the module specified in ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell.
278
+
PrivateData = @{
279
+
280
+
PSData = @{
281
+
282
+
# Tags applied to this module. These help with module discovery in online galleries.
283
+
# Tags = @()
284
+
285
+
# A URL to the license for this module.
286
+
# LicenseUri = ''
287
+
288
+
# A URL to the main website for this project.
289
+
# ProjectUri = ''
290
+
291
+
# A URL to an icon representing this module.
292
+
# IconUri = ''
293
+
294
+
# ReleaseNotes of this module
295
+
# ReleaseNotes = ''
296
+
297
+
# The names of required or nested modules that are not packaged with this module.
298
+
# ExternalModuleDependencies = @()
299
+
300
+
} # End of PSData hashtable
301
+
302
+
} # End of PrivateData hashtable
303
+
304
+
# HelpInfo URI of this module
305
+
# HelpInfoURI = ''
306
+
307
+
# Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix.
308
+
# DefaultCommandPrefix = ''
309
+
310
+
}
311
+
```
312
+
185
313
## Specification
186
314
187
315
The changes required for this RFC are relatively straightforward, and as follows:
188
316
189
-
1.`New-ModuleManifest` would generate a template like what is shown above, omitting any details about the `PSData` section.
190
-
1. Module import logic would read the manifest and pull the values for `Tags`, `LicenseUri`, `ProjectUri`, `IconUri` and `ReleaseNotes` from the top-level keys. If top-level keys were not defined with these values, it would look for values in a `PSData` section for backward compatibility.
317
+
1.`New-ModuleManifest` would generate a template like what is shown above, omitting any details about the `PSData` section for the latest version, but including them for manifests with a downlevel version as the value of `-PowerShellVersion`.
318
+
1. Module import logic would read the manifest and pull the values for `Tags`, `LicenseUri`, `ProjectUri`, `IconUri` and `ReleaseNotes` from the top-level keys in current plus future versions of PowerShell. If top-level keys were not defined with these values, it would look for values in a `PSData` section for backward compatibility (in cases where module versions are upgraded from older modules, we don't want users to be forced to change their manifest structure).
191
319
1. If values are defined in both locations, an error would occur informing the module author that they need to remove one of the two keys.
192
320
1. Add `-ExternalModuleDependencies` parameter to `New-ModuleManifest` (this is the only PowerShell Gallery value that is missing as a parameter).
321
+
1. Update `New-ModuleManifest`'s `-PowerShellVersion` handling, such that it uses a default version of the latest version of PowerShell, with support for structuring a manifest properly for downlevel versions.
193
322
1. Update `New-ModuleManifest` documentation (examples are missing PowerShell Gallery keys).
194
323
1. Update `Test-ModuleManifest` to validate the keys in the new locations.
195
324
1. Update `Update-ModuleManifest` to set the keys in the existing location if it is in use, or in the new location otherwise.
325
+
1. Update `Import-Module` such that it allows import when a top-level key that it does not recognize is discovered. This is important and necessary to allow future versions of PowerShell to add keys to the top level while still allowing modules to be created for downlevel versions that also support the functionality identified by the new keys when loaded in a newer version.
196
326
197
327
## Alternate Proposals and Considerations
198
328
@@ -203,3 +333,15 @@ The changes required for this RFC are relatively straightforward, and as follows
203
333
### Keep `PSData` section in `New-ModuleManifest` output, but commented out with explanation
204
334
205
335
@iSazonov proposed it may be clearer if the `PSData` section in `New-ModuleManifest` output, but commented out with a note indicating the keys have been moved to top level. I'm not convinced that would add clarity: it may confuse users as well. I think it would be better to identify the location change in the remarks section of the documentation for `New-ModuleManifest`, keeping `New-ModuleManifest` output clean, but I wanted to share the thought here for comment.
336
+
337
+
### Isolate version-specific metadata and extension metadata into separate psd1 files
338
+
339
+
If the `psd1` top-level key set is considered complete, when new keys are needed, where do they go? The current answer of placing new keys as subkeys under `PrivateData` in the `PSData` hashtable works, but it's just dealing with the problem by not dealing with the problem right now, and creating manifests that are more complicated than necessary. Instead, modules could have multiple `psd1` files, where files are created with a name in the format _moduleName_._extensionNameOrVersionNumber_.psd1. For example, we could have _moduleName_.PSGallery.psd1 as a manifest that stores PowerShell Gallery information. We could also have _moduleName_.7.psd1 as a manifest that stores new keys added to PowerShell 7.
340
+
341
+
On the plus side, this strategy allows for new metadata to be defined in manifests today without breaking downlevel versions of PowerShell. This enables scenarios where modules can be defined for a minimum downlevel version of PowerShell while having functionality that lights up when those modules are loaded on a newer version.
342
+
343
+
On the down side, it requires the management of additional files when working on manifests, which isn't necessarily simplifying manifest management.
344
+
345
+
### General consideration to keep in mind
346
+
347
+
While some people may find it difficult to justify these changes, at a minimum we need to have a clearly defined strategy for module manifest creation/consumption going forward that isn't held back by downlevel versions of PowerShell. In particular, we need to know where new keys should be stored, ideally in a way that makes sense to end users and is easy to manage. Please keep that in mind while considering the options presented here.
0 commit comments