Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
mazhelez committed Nov 30, 2023
2 parents de464c7 + 9cf2f23 commit d831a3d
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 15 deletions.
17 changes: 14 additions & 3 deletions AppHandling/Replace-DependenciesInAppFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
An Array of hashtable, containing id, name and publisher of an app, which should be added to internals Visible to
.Parameter showMyCode
With this parameter you can change or check ShowMyCode in the app file. Check will throw an error if ShowMyCode is False.
.Parameter replacePackageId
Add this switch to replace the package id of the app file with a new GUID
.Parameter replaceVersionNumber
Add this parameter to replace the version number of the app file with this version number
.Example
Replace-DependenciesInAppFile -containerName test -Path c:\temp\myapp.app -replaceDependencies @{ "437dbf0e-84ff-417a-965d-ed2bb9650972" = @{ "id" = "88b7902e-1655-4e7b-812e-ee9f0667b01b"; "name" = "MyBaseApp"; "publisher" = "Freddy Kristiansen"; "minversion" = "1.0.0.0" }}
.Example
Expand All @@ -28,6 +32,7 @@ Function Replace-DependenciesInAppFile {
[ValidateSet('Ignore','True','False','Check')]
[string] $ShowMyCode = "Ignore",
[switch] $replacePackageId,
[string] $replaceVersionNumber,
[HashTable[]] $internalsVisibleTo = $null
)

Expand All @@ -39,7 +44,7 @@ try {
$path = $Destination
}

Invoke-ScriptInBCContainer -containerName $containerName -scriptBlock { Param($path, $Destination, $replaceDependencies, $ShowMyCode, $replacePackageId, $internalsVisibleTo)
Invoke-ScriptInBCContainer -containerName $containerName -scriptBlock { Param($path, $Destination, $replaceDependencies, $ShowMyCode, $replacePackageId, $replaceVersionNumber, $internalsVisibleTo)

add-type -path (Get-Item "C:\Program Files\Microsoft Dynamics NAV\*\Service\system.io.packaging.dll").FullName

Expand Down Expand Up @@ -155,13 +160,19 @@ try {
}
}

if ($replaceVersionNumber) {
Write-Host "Replacing Version Number with $replaceVersionNumber"
$manifest.Package.App.Version = $replaceVersionNumber
$manifestChanges = $true
}

if ($replacePackageId) {
Write-Host "Replacing Package ID with new GUID"
$packageId = [Guid]::NewGuid()
$manifestChanges = $true
}

if ($manifestChanges) {

$partStream = $manifestPart.GetStream([System.IO.FileMode]::Create)
$manifest.Save($partStream)
$partStream.Flush()
Expand Down Expand Up @@ -208,7 +219,7 @@ try {
$fs.Close()
}
}
} -argumentList (Get-BCContainerPath -containerName $containerName -path $path -throw), (Get-BCContainerPath -containerName $containerName -path $Destination -throw), $replaceDependencies, $ShowMyCode, $replacePackageId, $internalsVisibleTo
} -argumentList (Get-BCContainerPath -containerName $containerName -path $path -throw), (Get-BCContainerPath -containerName $containerName -path $Destination -throw), $replaceDependencies, $ShowMyCode, $replacePackageId, $replaceVersionNumber, $internalsVisibleTo
}
catch {
TrackException -telemetryScope $telemetryScope -errorRecord $_
Expand Down
2 changes: 1 addition & 1 deletion AppHandling/Run-AlPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ $Parameters = @{
}
if ($useCompilerFolder) {
$existingAppFiles = @(Get-ChildItem -Path (Join-Path $packagesFolder '*.app') | Select-Object -ExpandProperty FullName)
$installedAppIds = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json') | Select-Object -ExpandProperty 'AppId')
$installedAppIds = @(GetAppInfo -AppFiles $existingAppFiles -compilerFolder $compilerFolder -cacheAppinfoPath (Join-Path $packagesFolder 'AppInfoCache.json') | ForEach-Object { $_.AppId } )
}
elseif (!$filesOnly) {
$installedAppIds = @(Invoke-Command -ScriptBlock $GetBcContainerAppInfo -ArgumentList $Parameters | Select-Object -ExpandProperty 'AppId')
Expand Down
22 changes: 18 additions & 4 deletions Bacpac/Restore-BcDatabaseFromArtifacts.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
Include this switch if you want to split the database .bak file into an application database and a tenant template
.Parameter async
Include this parameter if you want to restore the database asynchronous. A file called <databasePrefix>databasescreated.txt will be created in the containerhelper folder when done
.Parameter sqlTimeout
SQL Timeout for database restore operations
#>
function Restore-BcDatabaseFromArtifacts {
Param(
Expand All @@ -36,7 +38,8 @@ function Restore-BcDatabaseFromArtifacts {
[Parameter(Mandatory=$false)]
[string] $bakFile,
[switch] $multitenant,
[switch] $async
[switch] $async,
[int] $sqlTimeout = -1
)

$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
Expand All @@ -54,7 +57,7 @@ try {
$containerHelperPath = (Get-Item (Join-Path $PSScriptRoot "..\Import-BcContainerHelper.ps1")).FullName
Write-Host $containerHelperPath

$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile )
$job = Start-Job -ScriptBlock { Param( $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout )
$ErrorActionPreference = "Stop"
try {
. "$containerHelperPath"
Expand Down Expand Up @@ -139,8 +142,19 @@ try {
}
}

$newNavDBparams = @{
"DatabaseInstance" = $databaseInstance
"DatabaseServer" = $databaseServer
"DatabaseName" = $dbName
"FilePath" = $bakFile
"DestinationPath" = $destinationPath
}
if ($sqlTimeout -ge 0) {
$newNavDBparams += @{ "timeout" = $sqlTimeout }
}

Write-Host "Restoring database $dbName into $destinationPath"
New-NAVDatabase -DatabaseServer $databaseServer -DatabaseInstance $databaseInstance -DatabaseName $dbName -FilePath $bakFile -DestinationPath $destinationPath | Out-Null
New-NAVDatabase @newNavDBparams | Out-Null

if ($multitenant) {
if ($sqlpsModule) {
Expand Down Expand Up @@ -200,7 +214,7 @@ try {
throw
}

} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile
} -ArgumentList $containerHelperPath, $artifactUrl, $databaseServer, $databaseInstance, $databasePrefix, $databaseName, $multitenant, $successFileName, $bakFile, $sqlTimeout

if (!$async) {
While ($job.State -eq "Running") {
Expand Down
2 changes: 1 addition & 1 deletion CompilerFolderHandling/Compile-AppWithBcCompilerFolder.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ try {
Push-Location -Path $alcPath
try {
Write-Host "$alcCmd $([string]::Join(' ', $alcParameters))"
$result = & $alcCmd $alcParameters | Out-String
$result = & $alcCmd $alcParameters
}
finally {
Pop-Location
Expand Down
2 changes: 1 addition & 1 deletion ContainerInfo/Get-NavContainerEventLog.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ try {
$eventLogName
}
else {
[Diagnostics.Process]::Start($eventLogName) | Out-Null
Start-Process -FilePath $eventLogName | Out-Null
}
}
catch {
Expand Down
2 changes: 1 addition & 1 deletion HelperFunctions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -1147,7 +1147,7 @@ function GetAppInfo {
Add-Type -AssemblyName System.Text.Encoding
LoadDLL -Path (Join-Path $alcDllPath Newtonsoft.Json.dll)
LoadDLL -Path (Join-Path $alcDllPath System.Collections.Immutable.dll)
LoadDLL -Path (Join-Path $alcDllPath System.IO.Packaging.dll)
LoadDLL -Path (Join-Path $alcDllPath System.IO.Packaging.dll)
LoadDLL -Path (Join-Path $alcDllPath Microsoft.Dynamics.Nav.CodeAnalysis.dll)
$assembliesAdded = $true
}
Expand Down
5 changes: 4 additions & 1 deletion ReleaseNotes.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
6.0.2

6.0.1
New-AadAppsForBC doesn't work with the newer versions of Microsoft.Graph module (where the type of the accesstoken parameter has changed)
New-AppSourceSubmission has a new parameter -doNotUpdateVersionNumber to support hotfixes in AppSource for earlier versions
New-AppSourceSubmission obsoleted parameter -doNotCheckVersionNumber that was previously used for hotfixes, because of a change in AppSource
Issue 3219 Run-AlValidation cannot validate against Next Major without an insider Sas token
Do not attempt to call Get-BcContainerAppInfo if we are using filesonly containers in Run-AlPipeline
Do not attempt to download unknown symbols from filesonly containers
Add paramater generateErrorLog to Compile-AppInNavContainer
Add parameter generateErrorLog to Compile-AppInNavContainer
Issue 3229 Add parameter replaceVersionNumber to Replace-DependenciesInAppFile

6.0.0
Add parameter -accept_insiderEULA on New-BcContainer, Get-BcArtifactUrl and Run-AlPipeline to accept the insider EULA (https://go.microsoft.com/fwlink/?linkid=2245051) instead of using the insider SAS token.
Expand Down
11 changes: 11 additions & 0 deletions Tests/AppHandling.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,18 @@ Describe 'AppHandling' {
It 'Clean-BcContainerDatabase' {
#TODO
}
It 'Compile-AppInNavContainer generates error log file' {
Copy-Item -Path (Join-Path $PSScriptRoot "bc-app") -Destination $bcContainerPath -Recurse -Force
$appProjectFolder = Join-Path $bcContainerPath "bc-app"
$appOutputFolder = Join-Path $appProjectFolder "output"
$appSymbolsFolder = Join-Path $appProjectFolder "symbols"

$bcAppFile = Compile-AppInBcContainer -containerName $bcContainerName -appProjectFolder $appProjectFolder -appOutputFolder $appOutputFolder -appSymbolsFolder $appSymbolsFolder -UpdateSymbols -credential $credential -generateErrorLog
$bcAppFile | Should -Exist

$errorLogFile = $bcAppFile -replace '.app$', '.errorLog.json'
$errorLogFile | Should -Exist
}
It 'Compile-AppInBcContainer' {
Copy-Item -Path (Join-Path $PSScriptRoot "bc-app") -Destination $bcContainerPath -Recurse -Force
$appProjectFolder = Join-Path $bcContainerPath "bc-app"
Expand Down
6 changes: 4 additions & 2 deletions Tests/_TestRunOne.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
[string] $licenseFile = ($nchLicensefileSecret.secretValue | Get-PlainText),
[string] $buildlicenseFile = ($LicensefileSecret.secretValue | Get-PlainText),
[string] $insiderSasToken = ($InsiderSasTokenSecret.SecretValue | Get-PlainText),
[string] $testScript = "AppHandling.ps1"
[string] $testScript = "AppHandling.Tests.ps1"
)

try {
Write-Host $buildlicenseFile

. (Join-Path $PSScriptRoot '_TestHelperFunctions.ps1')

$modulePath = Join-Path $PSScriptRoot "..\BcContainerHelper.psm1"
Remove-Module BcContainerHelper -ErrorAction Ignore
Import-Module $modulePath -DisableNameChecking

. (Join-Path $PSScriptRoot $testScript)
. (Join-Path $PSScriptRoot $testScript) -licenseFile $licenseFile -buildlicenseFile $buildlicenseFile -insiderSasToken $insiderSasToken
}
catch {
Write-Host "::Error::$($_.Exception.Message)"
Expand Down
2 changes: 1 addition & 1 deletion Version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.1-dev
6.0.2-dev

0 comments on commit d831a3d

Please sign in to comment.