diff --git a/AppHandling/Get-AppJsonFromAppFile.ps1 b/AppHandling/Get-AppJsonFromAppFile.ps1 index 15133a32d..7405367b4 100644 --- a/AppHandling/Get-AppJsonFromAppFile.ps1 +++ b/AppHandling/Get-AppJsonFromAppFile.ps1 @@ -12,7 +12,7 @@ function Get-AppJsonFromAppFile { [Parameter(Mandatory=$true)] [string] $appFile ) - $appJson = RunAlTool -arguments @('GetPackageManifest', """$appFile""") + $appJson = RunAlTool -arguments @('GetPackageManifest', """$appFile""") | ConvertFrom-Json if (!($appJson.PSObject.Properties.Name -eq "description")) { Add-Member -InputObject $appJson -MemberType NoteProperty -Name "description" -Value "" } if (!($appJson.PSObject.Properties.Name -eq "dependencies")) { Add-Member -InputObject $appJson -MemberType NoteProperty -Name "dependencies" -Value @() } return $appJson diff --git a/HelperFunctions.ps1 b/HelperFunctions.ps1 index 20a81fd15..c63518b3f 100644 --- a/HelperFunctions.ps1 +++ b/HelperFunctions.ps1 @@ -1342,7 +1342,7 @@ function RunAlTool { else { $alToolExe = Join-Path $path 'extension/bin/win32/altool.exe' } - return CmdDo -Command $alToolExe -arguments $arguments -returnValue -silent | ConvertFrom-Json + CmdDo -Command $alToolExe -arguments $arguments -returnValue -silent } function GetApplicationDependency( [string] $appFile, [string] $minVersion = "0.0" ) { diff --git a/NuGet/New-BcNuGetPackage.ps1 b/NuGet/New-BcNuGetPackage.ps1 index 72c998f5f..58db288d7 100644 --- a/NuGet/New-BcNuGetPackage.ps1 +++ b/NuGet/New-BcNuGetPackage.ps1 @@ -81,6 +81,22 @@ 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 @@ -118,7 +134,7 @@ Function New-BcNuGetPackage { } } $appJson = Get-AppJsonFromAppFile -appFile $appFile - $packageId = $packageId.replace('{id}',$appJson.id).replace('{name}',[nuGetFeed]::Normalize($appJson.name)).replace('{publisher}',[nuGetFeed]::Normalize($appJson.publisher)).replace('{version}',$appJson.version.replace('.','-')) + $packageId = CalcPackageId -packageIdTemplate $packageId -publisher $appJson.publisher -name $appJson.name -id $appJson.id -version $appJson.version.replace('.','-') if ($null -eq $packageVersion) { $packageVersion = [System.Version]$appJson.version } @@ -174,7 +190,7 @@ Function New-BcNuGetPackage { $XmlObjectWriter.WriteStartElement("dependencies") if ($appJson.PSObject.Properties.Name -eq 'dependencies') { $appJson.dependencies | ForEach-Object { - $id = $dependencyIdTemplate.replace('{id}',$_.id).replace('{name}',[nuGetFeed]::Normalize($_.name)).replace('{publisher}',[nuGetFeed]::Normalize($_.publisher)) + $id = CalcPackageId -packageIdTemplate $dependencyIdTemplate -publisher $_.publisher -name $_.name -id $_.id -version $_.version.replace('.','-') $XmlObjectWriter.WriteStartElement("dependency") $XmlObjectWriter.WriteAttributeString("id", $id) $XmlObjectWriter.WriteAttributeString("version", $_.Version) @@ -195,7 +211,7 @@ Function New-BcNuGetPackage { } if ($isIndirectPackage.IsPresent) { $XmlObjectWriter.WriteStartElement("dependency") - $id = $runtimeDependencyId.replace('{id}',$appJson.id).replace('{name}',[nuGetFeed]::Normalize($appJson.name)).replace('{publisher}',[nuGetFeed]::Normalize($appJson.publisher)).replace('{version}',$appJson.version.replace('.','-')) + $id = CalcPackageId -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() diff --git a/NuGet/Publish-BcNuGetPackageToContainer.ps1 b/NuGet/Publish-BcNuGetPackageToContainer.ps1 index e6a49f191..5679daec5 100644 --- a/NuGet/Publish-BcNuGetPackageToContainer.ps1 +++ b/NuGet/Publish-BcNuGetPackageToContainer.ps1 @@ -5,7 +5,6 @@ Publish Business Central NuGet Package to container .PARAMETER nuGetServerUrl NuGet Server URL - Default: https://api.nuget.org/v3/index.json .PARAMETER nuGetToken NuGet Token for authenticated access to the NuGet Server If not specified, the NuGet Server is accessed anonymously (and needs to support this) @@ -42,7 +41,7 @@ Function Publish-BcNuGetPackageToContainer { Param( [Parameter(Mandatory=$false)] - [string] $nuGetServerUrl = "https://api.nuget.org/v3/index.json", + [string] $nuGetServerUrl = "", [Parameter(Mandatory=$false)] [string] $nuGetToken = "", [Parameter(Mandatory=$true)]