Skip to content

Commit

Permalink
Bugfix (#3295)
Browse files Browse the repository at this point in the history
Move json conversion as not all altool commands return json

---------

Co-authored-by: freddydk <[email protected]>
  • Loading branch information
freddydk and freddydk authored Jan 19, 2024
1 parent d5dad93 commit 43027b9
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion AppHandling/Get-AppJsonFromAppFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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" ) {
Expand Down
22 changes: 19 additions & 3 deletions NuGet/New-BcNuGetPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions NuGet/Publish-BcNuGetPackageToContainer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)]
Expand Down

0 comments on commit 43027b9

Please sign in to comment.