Add new function to get package id from publisher, name and id

---------

Co-authored-by: freddydk <freddydk@users.noreply.github.com>
Co-authored-by: Maria Zhelezova <43066499+mazhelez@users.noreply.github.com>
This commit is contained in:
Freddy Kristiansen 2024-01-26 22:35:50 +01:00 коммит произвёл GitHub
Родитель 40f7c4a535
Коммит 8a8f866167
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
7 изменённых файлов: 71 добавлений и 21 удалений

Просмотреть файл

@ -5,6 +5,7 @@ if (-not (([System.Management.Automation.PSTypeName]"NuGetFeed").Type)) {
. (Join-Path $PSScriptRoot "NuGet\New-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Find-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Get-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Get-BcNuGetPackageId.ps1")
. (Join-Path $PSScriptRoot "NuGet\Push-BcNuGetPackage.ps1")
. (Join-Path $PSScriptRoot "NuGet\Publish-BcNuGetPackageToContainer.ps1")
. (Join-Path $PSScriptRoot "NuGet\Download-BcNuGetPackageToFolder.ps1")

Двоичные данные
BC.NuGetHelper.psd1

Двоичный файл не отображается.

Просмотреть файл

@ -116,7 +116,8 @@ FunctionsToExport = 'Add-FontsToBcContainer', 'Add-GitToAlProjectFolder',
'Get-BcEnvironmentOperations', 'Get-BcEnvironmentPublishedApps',
'Get-BcEnvironments', 'Get-BcEnvironmentScheduledUpgrade',
'Get-BcEnvironmentUpdateWindow', 'Get-BcEnvironmentUsedStorage',
'Get-BcNotificationRecipients', 'Find-BcNuGetPackage', 'Get-BcNuGetPackage',
'Get-BcNotificationRecipients', 'Find-BcNuGetPackage',
'Get-BcNuGetPackage', 'Get-BcNuGetPackageId',
'Get-BestBcContainerImageName', 'Get-BestGenericImageName',
'Get-CloudBcContainerEventLog',
'Get-CloudBcContainerServerConfiguration',

Просмотреть файл

@ -211,7 +211,7 @@ Function Download-BcNuGetPackageToFolder {
Remove-Item -Path $package -Recurse -Force
continue
}
if (Test-Path (Join-Path $package $installedCountry) -PathType Container) {
if ($installedCountry -and (Test-Path (Join-Path $package $installedCountry) -PathType Container)) {
# NuGet packages of Runtime packages might exist in different versions for different countries
# The runtime package might contain C# invoke calls with different methodis for different countries
# if the installedCountry doesn't have a special version, then the w1 version is used (= empty string)

Просмотреть файл

@ -0,0 +1,62 @@
<#
.Synopsis
PROOF OF CONCEPT PREVIEW: Get Business Central NuGet Package Id from Publisher, Name and Id
.Description
Get Business Central NuGet Package Id from Publisher, Name and Id
.OUTPUTS
string
Package Id
.PARAMETER packageIdTemplate
Template for package id with placeholders for publisher, name, id and version
.PARAMETER publisher
App Publisher (will be normalized)
.PARAMETER name
App name (will be normalized)
.PARAMETER id
App Id (must be a GUID if present)
.PARAMETER tag
Tag to add to the package id
.PARAMETER version
App Version
.EXAMPLE
Get-BcNuGetPackageId -publisher 'Freddy Kristiansen' -name 'Bing Maps PTE' -id '165d73c1-39a4-4fb6-85a5-925edc1684fb'
#>
function Get-BcNuGetPackageId {
Param(
[Parameter(Mandatory=$false)]
[string] $packageIdTemplate = '{publisher}.{name}.{tag}.{id}',
[Parameter(Mandatory=$true)]
[string] $publisher,
[Parameter(Mandatory=$true)]
[string] $name,
[Parameter(Mandatory=$false)]
[string] $id = '',
[Parameter(Mandatory=$false)]
[string] $tag = '',
[Parameter(Mandatory=$false)]
[string] $version = ''
)
if ($id) {
try { $id = ([GUID]::Parse($id)).Guid } catch { throw "App id must be a valid GUID: $id" }
}
$nname = [nuGetFeed]::Normalize($name)
$npublisher = [nuGetFeed]::Normalize($publisher)
if ($nname -eq '') { throw "App name is invalid: '$name'" }
if ($npublisher -eq '') { throw "App publisher is invalid: '$publisher'" }
$packageIdTemplate = $packageIdTemplate.replace('{id}',$id).replace('{publisher}',$npublisher).replace('{tag}',$tag).replace('{version}',$version).replace('..','.').TrimEnd('.')
# Max. Length of NuGet Package Id is 100 - we shorten the name part of the id if it is too long
$packageId = $packageIdTemplate.replace('{name}',$nname)
if ($packageId.Length -ge 100) {
if ($nname.Length -gt ($packageId.Length - 99)) {
$nname = $nname.Substring(0, $nname.Length - ($packageId.Length - 99))
}
else {
throw "Package id is too long: $packageId, unable to shorten it"
}
$packageId = $packageIdTemplate.replace('{name}',$nname)
}
return $packageId
}
Export-ModuleMember -Function Get-BcNuGetPackageId

Просмотреть файл

@ -81,22 +81,6 @@ Function New-BcNuGetPackage {
$stream.Write($bytes,0,$bytes.Length)
}
function CalcPackageId([string] $packageIdTemplate, [string] $publisher, [string] $name, [string] $id, [string] $version) {
$name = [nuGetFeed]::Normalize($name)
$publisher = [nuGetFeed]::Normalize($publisher)
$packageId = $packageIdTemplate.replace('{id}',$id).replace('{name}',$name).replace('{publisher}',$publisher).replace('{version}',$version)
if ($packageId.Length -ge 100) {
if ($name.Length -gt ($packageId.Length - 99)) {
$name = $name.Substring(0, $name.Length - ($packageId.Length - 99))
}
else {
throw "Package id is too long: $packageId, unable to shorten it"
}
$packageId = $packageIdTemplate.replace('{id}',$id).replace('{name}',$name).replace('{publisher}',$publisher).replace('{version}',$version)
}
return $packageId
}
Write-Host "Create NuGet package"
Write-Host "AppFile:"
Write-Host $appFile
@ -134,7 +118,7 @@ Function New-BcNuGetPackage {
}
}
$appJson = Get-AppJsonFromAppFile -appFile $appFile
$packageId = CalcPackageId -packageIdTemplate $packageId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
$packageId = Get-BcNuGetPackageId -packageIdTemplate $packageId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
if ($null -eq $packageVersion) {
$packageVersion = [System.Version]$appJson.version
}
@ -195,7 +179,7 @@ Function New-BcNuGetPackage {
} else {
$dependencyId = $_.appId
}
$id = CalcPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $dependencyId -version $_.version.replace('.','-')
$id = Get-BcNuGetPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $dependencyId -version $_.version.replace('.','-')
$XmlObjectWriter.WriteStartElement("dependency")
$XmlObjectWriter.WriteAttributeString("id", $id)
$XmlObjectWriter.WriteAttributeString("version", $_.version)
@ -216,7 +200,7 @@ Function New-BcNuGetPackage {
}
if ($isIndirectPackage.IsPresent) {
$XmlObjectWriter.WriteStartElement("dependency")
$id = CalcPackageId -packageIdTemplate $runtimeDependencyId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
$id = Get-BcNuGetPackageId -packageIdTemplate $runtimeDependencyId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-')
$XmlObjectWriter.WriteAttributeString("id", $id)
$XmlObjectWriter.WriteAttributeString("version", '1.0.0.0')
$XmlObjectWriter.WriteEndElement()

Просмотреть файл

@ -1,4 +1,6 @@
6.0.5
Add new function Get-BcNuGetPackageId to get a NuGet Package Id based on publisher, name, id and version
Issue 3301 Run-AlValidation fails running AppsourceCop "Could not load type 'System.Object' from assembly 'System.Private.CoreLib'
Give better error message if GitHub CLI, GIT or dotnet is not installed
Issue 3301 Run-AlValidation fails running AppsourceCop "Could not load type 'System.Object' from assembly 'System.Private.CoreLib' (Regression in 6.0.4)
Issue 3313 Strange error in Copy-BcEnvironment