Uncompress a nuspec (Which is just a zip with a different extension), parse the XML, add the URL element for the repository, recreate the ZIP file.
add-mfRepositoryXmlData [-repositoryUri] <String> [-NugetPackagePath] <String> [[-ExtractionPath] <Object>]
[-force] [[-branch] <String>] [[-commit] <String>] [-ProgressAction <ActionPreference>] [<CommonParameters>]
Some Nuget Package Providers (such as Github Package Manager) require a repository element with a URL attribute in order to be published correctly, For Githup Packages, this is so it can tie the package back to the actual repository.
At present (March 2024), new-moduleManifest and publish-psresource do not have parameter options that works for this. This function provides a work-around
add-repositoryXmlData -RepositoryUri 'https://github.com/gituser/example' -NugetPackagePath = 'c:\example\module.1.2.3-beta.4.nupkg -branch 'main' -commit '1234123412341234Y'
Unpack module.1.2.3-beta.4.nupkg to a temp location, open the NUSPEC xml and append a repository element with URL, Type, Branch and Commit attributes, repack the nupkg
RepositoryUri
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 1
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
Path to the actual file in the repository, should be something like C:\Users{UserName}\AppData\Local\Temp\LocalTestRepository{ModuleName}.{ModuleVersion}.nupkg
Type: String
Parameter Sets: (All)
Aliases:
Required: True
Position: 2
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
TempExtractionPath
Type: Object
Parameter Sets: (All)
Aliases:
Required: False
Position: 3
Default value: $(join-path -path ([System.IO.Path]::GetTempPath()) -childpath 'tempUnzip')
Accept pipeline input: False
Accept wildcard characters: False
Use force to ignore remove prompt
Type: SwitchParameter
Parameter Sets: (All)
Aliases:
Required: False
Position: Named
Default value: False
Accept pipeline input: False
Accept wildcard characters: False
What branch to add to NUSPEC (Optional)
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 4
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
What commit to add to NUSPEC (Optional)
Type: String
Parameter Sets: (All)
Aliases:
Required: False
Position: 5
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Type: ActionPreference
Parameter Sets: (All)
Aliases: proga
Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
repositoryUri
and NugetPackagePath
via pipeline input by property name.Author: Adrian Andersson