Skip to content

Commit 3e97bff

Browse files
committed
Fix error when Destination does not exist
1 parent 398a740 commit 3e97bff

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/PSAppDeployToolkit.Tools/Public/Convert-ADTDeployment.ps1

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function Convert-ADTDeployment
139139
try
140140
{
141141
$Path = (Resolve-Path -LiteralPath $Path).Path
142-
$Destination = (Resolve-Path -LiteralPath $Destination).Path
142+
$Destination = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($Destination) # This method resolves relative paths that might not exist and also accepts PSPaths unlike [System.IO.Path]::GetFullPath()
143143
$tempFolderName = "Convert-ADTDeployment_$([System.IO.Path]::GetRandomFileName().Replace('.', ''))"
144144
$tempFolderPath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), $tempFolderName)
145145

@@ -340,6 +340,13 @@ function Convert-ADTDeployment
340340
Write-Verbose -Message "Removing temp script [$inputScriptPath]"
341341
Remove-Item -LiteralPath $inputScriptPath -Force
342342

343+
$DestinationParent = Split-Path -Path $Destination -Parent
344+
if (!(Test-Path -LiteralPath $DestinationParent -PathType Container))
345+
{
346+
Write-Verbose -Message "Creating parent folder [$DestinationParent]"
347+
New-Item -Path $DestinationParent -ItemType Directory -Force | Out-Null
348+
}
349+
343350
if ($Path -like '*.ps1')
344351
{
345352
Write-Verbose -Message "Moving file [$outputScriptPath] to [$Destination]"
@@ -409,7 +416,7 @@ function Convert-ADTDeployment
409416
}
410417
finally
411418
{
412-
if (Test-Path -LiteralPath $tempFolderPath)
419+
if ((Get-Variable -Name 'tempFolderPath' -ErrorAction Ignore) -and (Test-Path -LiteralPath $tempFolderPath))
413420
{
414421
Write-Verbose -Message "Removing temp folder [$tempFolderPath]"
415422
Remove-Item -Path $tempFolderPath -Recurse -Force -ErrorAction SilentlyContinue

0 commit comments

Comments
 (0)