Module manifest

The module manifest is a PowerShell data file that contains metadata for the module. The manifest includes critical information, such as the version number, the files to import, and the commands, aliases, and classes that it contains. The manifest may include the software license and a project URL if they are applicable.

The use of a manifest is mandatory if a module will be published on the PowerShell Gallery or any other repository.

The New-ModuleManifest command may be used to create the manifest from scratch. The following example assumes the module is a C:workspace path:

$params = @{
Path = 'C:workspaceLocalMachineLocalMachine.psd1'
RootModule = 'LocalMachine.psm1'

ModuleVersion = '1.0.0'
FunctionsToExport = 'Get-ComputerDescription', 'Set-ComputerDescription'
}
New-ModuleManifest @params

This manifest replaces much of the functionality of the Export-ModuleMember command. The manifest can be used to define functions to export; Export-ModuleMember is still required if variables are to be exported.

As with Export-ModuleMember, a wildcard pattern may be used for FunctionsToExport, however, this will make it impossible for the autoloader to do its job consistently.

The New-ModuleManifest command is complemented by Test-ModuleManifest. The Test-ModuleManifest command will import the data file and raise errors if problems are detected with the manifest. The Import-PowerShellDataFile command can also be used to import the content of the manifest.

In theory, in addition to creating a manifest for the first time, New-ModuleManifest can be used to update the content of an existing file. Import-PowerShellDataFile can be used to import the existing content and those values can be passed to New-ModuleManifest:

$path = 'C:workspaceLocalMachineLocalMachine.psd1'
$manifest = Import-PowerShellDataFile -Path 'C:workspaceLocalMachineLocalMachine.psd1'
$manifest.FunctionsToExport = '*'

New-ModuleManifest -Path 'C:workspaceLocalMachineLocalMachine-new.psd1' @manifest

In practice, New-ModuleManifest will not correctly handle the nested PrivateData section. A similar problem applies to the Update-ModuleManifest command that comes with the PowerShellGet module.

The Configuration module on the PowerShell Gallery (https://www.powershellgallery.com/packages/Configuration) provides an alternative. Once installed, the command may be used to tweak content in an existing manifest, as follows:

Install-Module Configuration -Scope CurrentUser

$params = @{
Path = 'C:workspaceLocalMachineLocalMachine.psd1'
Property = 'RootModule'
Value = 'LocalMachine.psm1'
}
Update-Metadata @params

The Update-Metadata command cannot write to commented keys in the manifest, and removing comment characters is beyond the scope of Update-Metadata.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.123.193