Skip to content

Module GUID should be reused when psd1 file already exists #981

@peombwa

Description

@peombwa

We should reuse existing GUID in a module's manifest when regenerating a module after it has been modified using Update-ModuleManifest. According to https://docs.microsoft.com/en-us/powershell/scripting/developer/module/how-to-write-a-powershell-module-manifest?view=powershell-7.2#module-manifest-elements, GUID is used:

ID used to uniquely identify this module. If a value isn't specified, New-ModuleManifest autogenerates the value. You can't currently import a module by GUID.

Repro Steps

  1. Generate and build a module. Use https://github.com/Azure/autorest.powershell/tree/main/samples/Xkcd sample:
autorest --powershell --input-file:https://raw.githubusercontent.com/Azure/autorest.powershell/main/samples/Xkcd/xkcd.yaml
.\generated\build-module.ps1
  1. Inspect the GUID in the module manifest:
@{
  GUID = '015d674a-6f59-4d6c-bdfd-da7e61d3ea5c'
  RootModule = './Xkcd.psm1'
  ModuleVersion = '0.1.0'
  CompatiblePSEditions = 'Core', 'Desktop'
  Author = ''
  CompanyName = ''
  Copyright = ''
  Description = ''
  PowerShellVersion = '5.1'
  DotNetFrameworkVersion = '4.7.2'
  RequiredAssemblies = './bin/Xkcd.private.dll'
  FormatsToProcess = './Xkcd.format.ps1xml'
  FunctionsToExport = 'Get-XkcdComic', '*'
  AliasesToExport = '*'
  PrivateData = @{
    PSData = @{
      Tags = ''
      LicenseUri = ''
      ProjectUri = ''
      ReleaseNotes = ''
    }
  }
}
  1. Update the module manifest using Update-ModuleManifest.
Update-ModuleManifest -Path "C:\Dev\temp\generated\Xkcd.psd1" -IconUri "URI_TO_MY_ICON"
  1. Regenerate and build the module with the manifest present in the output directory.
autorest --powershell --input-file:https://raw.githubusercontent.com/Azure/autorest.powershell/main/samples/Xkcd/xkcd.yaml
.\generated\build-module.ps1
  1. Inspect the GUID in the module manifest. You'll see that the GUID changes on every build.
@{
- GUID = '015d674a-6f59-4d6c-bdfd-da7e61d3ea5c'
+ GUID = '52692275-94fc-4deb-8b48-1e825dfaada3'
  RootModule = './Xkcd.psm1'
  ModuleVersion = '0.1.0'
  CompatiblePSEditions = 'Core', 'Desktop'
  Author = ''
  CompanyName = ''
  Copyright = ''
  Description = ''
  PowerShellVersion = '5.1'
  DotNetFrameworkVersion = '4.7.2'
  RequiredAssemblies = './bin/Xkcd.private.dll'
  FormatsToProcess = './Xkcd.format.ps1xml'
  FunctionsToExport = 'Get-XkcdComic', '*'
  AliasesToExport = '*'
  PrivateData = @{
    PSData = @{
      Tags = ''
      LicenseUri = ''
      ProjectUri = ''
      ReleaseNotes = ''
    }
  }
}

Metadata

Metadata

Assignees

Labels

P1feature-requestv4Need to be done in autorest.powershell V4

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions