use [System.IO.Path]::GetTempPath()

This commit is contained in:
freddydk 2022-12-09 13:33:51 +01:00
Родитель e90800ef1b
Коммит 254ea29abb
24 изменённых файлов: 44 добавлений и 48 удалений

4
.github/workflows/CI.yaml поставляемый
Просмотреть файл

@ -190,7 +190,7 @@ jobs:
- name: Deploy
run: |
try {
$path = Join-Path $ENV:TEMP "BcContainerHelper"
$path = Join-Path ([System.IO.Path]::GetTempPath()) "BcContainerHelper"
New-Item -path $path -itemType Directory | Out-Null
Copy-Item -path (Join-Path $ENV:GITHUB_WORKSPACE "*") -Destination $path -Recurse -Force
@ -237,7 +237,7 @@ jobs:
-CompanyName "Microsoft" `
-ReleaseNotes $versionReleaseNotes
$certFileName = Join-Path $ENV:TEMP "$([GUID]::NewGuid().ToString()).pfx"
$certFileName = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).pfx"
Download-File -sourceUrl '${{ secrets.CodeSignCertificateUrl }}' -destinationFile $certFileName
Remove-Module BcContainerHelper

4
.github/workflows/Release.yaml поставляемый
Просмотреть файл

@ -22,7 +22,7 @@ jobs:
- name: Deploy
run: |
try {
$path = Join-Path $ENV:TEMP "BcContainerHelper"
$path = Join-Path ([System.IO.Path]::GetTempPath()) "BcContainerHelper"
New-Item -path $path -itemType Directory | Out-Null
Copy-Item -path (Join-Path $ENV:GITHUB_WORKSPACE "*") -Destination $path -Recurse -Force
@ -68,7 +68,7 @@ jobs:
-ReleaseNotes $versionReleaseNotes
$certFileName = Join-Path $ENV:TEMP "$([GUID]::NewGuid().ToString()).pfx"
$certFileName = Join-Path ([System.IO.Path]::GetTempPath()) "$([GUID]::NewGuid().ToString()).pfx"
Download-File -sourceUrl '${{ secrets.CodeSignCertificateUrl }}' -destinationFile $certFileName
Remove-Module BcContainerHelper

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

@ -1,6 +1,6 @@
function New-ALGoRepo {
Param(
$tmpFolder = (Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())),
$tmpFolder = (Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())),
[Parameter(Mandatory=$true)]
$org,
[Parameter(Mandatory=$true)]
@ -83,7 +83,7 @@
$tempdir = $false
if ($path -like "https://*" -or $path -like "http://*") {
$url = $path
$path = Join-Path $env:TEMP "$([Guid]::NewGuid().ToString()).app"
$path = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString()).app"
$tempdir = $true
Download-File -sourceUrl $url -destinationFile $path
if (!(Test-Path -Path $path)) {
@ -112,7 +112,7 @@
}
}
$appFolders | ForEach-Object {
$newFolder = Join-Path $env:TEMP "$([Guid]::NewGuid().ToString())"
$newFolder = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString())"
write-Host "$_ -> $newFolder"
Copy-Item -Path $_ -Destination $newFolder -Force -Recurse
Write-Host "done"
@ -127,7 +127,7 @@
}
elseif ([string]::new([char[]](Get-Content $path @byteEncodingParam -TotalCount 2)) -eq "PK") {
# .zip file
$destinationPath = Join-Path $env:TEMP "$([Guid]::NewGuid().ToString())"
$destinationPath = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString())"
Expand-7zipArchive -path $path -destinationPath $destinationPath
$directoryInfo = Get-ChildItem $destinationPath | Measure-Object
if ($directoryInfo.count -eq 0) {
@ -137,7 +137,7 @@
Remove-Item -Path $destinationPath -Force -Recurse -ErrorAction SilentlyContinue
}
elseif ([string]::new([char[]](Get-Content $path @byteEncodingParam -TotalCount 4)) -eq "NAVX") {
$destinationPath = Join-Path $env:TEMP "$([Guid]::NewGuid().ToString())"
$destinationPath = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString())"
Extract-AppFileToFolder -appFilename $path -appFolder $destinationPath -generateAppJson
$destinationPath
}
@ -211,7 +211,7 @@
Write-Host "Downloading and applying AL-Go-$AppType template"
$templateUrl = "https://github.com/microsoft/AL-Go-$AppType/archive/refs/heads/main.zip"
$tempZip = Join-Path (Get-TempDir) "$([Guid]::NewGuid().ToString()).zip"
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::NewGuid().ToString()).zip"
Download-File -sourceUrl $templateUrl -destinationFile $tempZip
Expand-7zipArchive -Path $tempZip -DestinationPath $folder
Remove-Item -Path $tempZip -Force

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

@ -251,7 +251,7 @@ try {
# unpack compiler
Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock {
if (!(Test-Path "c:\build" -PathType Container)) {
$tempZip = Join-Path $env:temp "alc.zip"
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "alc.zip"
Copy-item -Path (Get-Item -Path "c:\run\*.vsix").FullName -Destination $tempZip
Expand-Archive -Path $tempZip -DestinationPath "c:\build\vsix"
}

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

@ -41,7 +41,7 @@ function Convert-BcAppsToRuntimePackages {
$telemetryScope = InitTelemetryScope -name $MyInvocation.InvocationName -parameterValues $PSBoundParameters -includeParameters @()
try {
$appsFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$appsFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
$apps = @(Sort-AppFilesByDependencies -appFiles (CopyAppFilesToFolder -appFiles $apps -folder $appsFolder) -WarningAction SilentlyContinue)
@ -53,7 +53,7 @@ try {
}
if (!($destinationFolder)) {
$destinationFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$destinationFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
New-Item -Path $destinationFolder -ItemType Directory | Out-Null
}
elseif (Test-Path $destinationFolder) {

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

@ -33,7 +33,7 @@ try {
if ($appFolder -eq "") {
if ($openFolder) {
$generateAppJson = $true
$appFolder = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
$appFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
}
else {
$appFolder = "$($appFilename).source"

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

@ -129,7 +129,7 @@ try {
}
}
else {
$appFolder = Join-Path (Get-TempDir) ([guid]::NewGuid().ToString())
$appFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString())
$appFiles = CopyAppFilesToFolder -appFiles $appFile -folder $appFolder
$force = $true
if ($checkAlreadyInstalled) {

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

@ -102,7 +102,7 @@ try {
$previousApps = Sort-AppFilesByDependencies -containerName $containerName -appFiles $appList -WarningAction SilentlyContinue
$previousApps | ForEach-Object {
$appFile = $_
$tmpFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
Extract-AppFileToFolder -appFilename $appFile -appFolder $tmpFolder -generateAppJson
$xappJsonFile = Join-Path $tmpFolder "app.json"
@ -127,7 +127,7 @@ try {
# unpack compiler
$latestSupportedRuntimeVersion = Invoke-ScriptInBcContainer -containerName $containerName -ScriptBlock { Param([string] $bcversion)
if (!(Test-Path "c:\build" -PathType Container)) {
$tempZip = Join-Path $env:temp "alc.zip"
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "alc.zip"
Copy-item -Path (Get-Item -Path "c:\run\*.vsix").FullName -Destination $tempZip
Expand-Archive -Path $tempZip -DestinationPath "c:\build\vsix"
}

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

@ -953,7 +953,7 @@ Measure-Command {
Write-Host -ForegroundColor Yellow "Installing apps for additional country $testCountry"
}
$tmpAppFolder = Join-Path (Get-TempDir) ([guid]::NewGuid().ToString())
$tmpAppFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString())
$tmpAppFiles = @()
$installApps | ForEach-Object{
$appId = [Guid]::Empty
@ -1951,7 +1951,7 @@ $installTestApps | ForEach-Object {
else {
$appFile = $_
if ($appFile -eq "$_".Trim('()')) {
$tmpFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
$appList = CopyAppFilesToFolder -appFiles $_ -folder $tmpFolder
$appList | ForEach-Object {

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

@ -178,7 +178,7 @@ Write-Host -ForegroundColor Yellow @'
}
function GetApplicationDependency( [string] $appFile, [string] $minVersion = "0.0" ) {
$tmpFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
Extract-AppFileToFolder -appFilename $appFile -appFolder $tmpFolder -generateAppJson
$appJsonFile = Join-Path $tmpFolder "app.json"

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

@ -58,7 +58,7 @@ try {
}
}
else {
$tmpFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
try {
Extract-AppFileToFolder -appFilename $appFile -appFolder $tmpFolder -generateAppJson 6> $null
$appJsonFile = Join-Path $tmpFolder "app.json"

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

@ -96,7 +96,7 @@ try {
$appVersionNumber = ""
if ($appFile) {
try {
$tempFolder = Join-Path $env:TEMP ([Guid]::NewGuid().ToString())
$tempFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
Extract-AppFileToFolder -appFilename $appFile -appFolder $tempFolder -generateAppJson
$appJsonFile = Join-Path $tempFolder 'app.json'
$appJson = Get-Content $appJsonFile -Encoding UTF8 | ConvertFrom-Json
@ -115,7 +115,7 @@ try {
$libraryAppFile = $libraryAppFiles[0]
}
else {
$tempFolder = Join-Path $env:TEMP ([GUID]::NewGuid().ToString())
$tempFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
New-Item -Path $tempFolder -ItemType Directory | Out-Null
$libraryAppFile = Join-Path $tempFolder "$([System.IO.Path]::GetFileNameWithoutExtension($appFile)).libraries.zip"
Compress-Archive -Path $libraryAppFiles -DestinationPath $libraryAppFile -CompressionLevel Fastest

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

@ -435,7 +435,7 @@ function CopyAppFilesToFolder {
$appFile = $_
if ($appFile -like "http://*" -or $appFile -like "https://*") {
$appUrl = $appFile
$appFile = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$appFile = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
Download-File -sourceUrl $appUrl -destinationFile $appFile
CopyAppFilesToFolder -appFile $appFile -folder $folder
Remove-Item -Path $appFile -Force
@ -452,12 +452,12 @@ function CopyAppFilesToFolder {
}
elseif (Test-Path $appFile -PathType Leaf) {
if ([string]::new([char[]](Get-Content $appFile @byteEncodingParam -TotalCount 2)) -eq "PK") {
$tmpFolder = Join-Path (Get-TempDir) ([Guid]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
$copied = $false
try {
if ($appFile -notlike "*.zip") {
$orgAppFile = $appFile
$appFile = Join-Path (Get-TempDir) "$([System.IO.Path]::GetFileName($orgAppFile)).zip"
$appFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([System.IO.Path]::GetFileName($orgAppFile)).zip"
Copy-Item $orgAppFile $appFile
$copied = $true
}
@ -764,10 +764,6 @@ function Get-WWWRootPath {
}
}
function Get-TempDir {
(Get-Item -Path $env:temp).FullName
}
function Parse-JWTtoken([string]$token) {
if ($token.Contains(".") -and $token.StartsWith("eyJ")) {
$tokenPayload = $token.Split(".")[1].Replace('-', '+').Replace('_', '/')

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

@ -82,7 +82,7 @@ Function Get-BcNuGetPackage {
}
}
$tmpFolder = Join-Path $ENV:TEMP ([GUID]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
if (!$silent) {
Write-Host "Downloading Package from $contentUrl"
}

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

@ -67,7 +67,7 @@ Function New-BcNuGetPackage {
}
$appFile = $appfiles | Select-Object -First 1
$tmpFolder = Join-Path $ENV:TEMP ([GUID]::NewGuid().ToString())
$tmpFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
Extract-AppFileToFolder -appFilename $appFile -generateAppJson -appFolder $tmpFolder
$appJsonFile = Join-Path $tmpFolder 'app.json'
$appJson = Get-Content $appJsonFile -Encoding UTF8 | ConvertFrom-Json
@ -75,7 +75,7 @@ Function New-BcNuGetPackage {
$testsFolderName = "Tests"
$dependenciesFolderName = "Dependencies"
$rootFolder = Join-Path $ENV:TEMP ([GUID]::NewGuid().ToString())
$rootFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
New-Item -Path $rootFolder -ItemType Directory | Out-Null
try {
$testsFolder = Join-Path $rootFolder $testsFolderName
@ -172,7 +172,7 @@ Function New-BcNuGetPackage {
$XmlObjectWriter.Close()
$nuPkgFileName = "$($packageId)-$($packageVersion).nupkg"
$nupkgFile = Join-Path $ENV:TEMP $nuPkgFileName
$nupkgFile = Join-Path ([System.IO.Path]::GetTempPath()) $nuPkgFileName
if (Test-Path $nuPkgFile -PathType Leaf) {
Remove-Item $nupkgFile -Force
}

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

@ -46,7 +46,7 @@ Function Push-BcNuGetPackage {
$body += $fileContent
$body += [System.Text.Encoding]::UTF8.GetBytes("$LF--$boundary--$LF")
$tmpFile = Join-Path $ENV:TEMP ([GUID]::NewGuid().ToString())
$tmpFile = Join-Path ([System.IO.Path]::GetTempPath()) ([GUID]::NewGuid().ToString())
[System.IO.File]::WriteAllBytes($tmpFile, $body)
Write-Host "Submitting NuGet package"
try {

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

@ -78,7 +78,7 @@ try {
if (-not (Test-Path (Join-Path ([System.IO.Path]::GetDirectoryName($txt2al)) "Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.dll"))) {
Write-Host "Copying Microsoft.Dynamics.Nav.CodeAnalysis.Workspaces.dll from vsix"
if (!(Test-Path "c:\build" -PathType Container)) {
$tempZip = Join-Path (Get-TempDir) "alc.zip"
$tempZip = Join-Path ([System.IO.Path]::GetTempPath()) "alc.zip"
Copy-item -Path (Get-Item -Path "c:\run\*.vsix").FullName -Destination $tempZip
Expand-Archive -Path $tempZip -DestinationPath "c:\build\vsix"
}

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

@ -38,7 +38,7 @@ try {
Get-Childitem Path (Join-Path $path "\Apps\*.app") | % {
$basename = $_.Basename
$tempAppFolder = Join-Path ((Get-Item -Path $env:temp).FullName) ([Guid]::NewGuid().ToString())
$tempAppFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
$tempAppOutFolder = Join-Path $tempAppFolder "out"
$tempAppSourceFolder = Join-Path $tempAppFolder "source"
try {

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

@ -60,7 +60,7 @@ try {
$subFolder = $_
if (Test-Path (Join-Path $path "$subFolder\*")) {
$tempFile = Join-Path (Get-TempDir) "$([Guid]::newguid().ToString()).zip"
$tempFile = Join-Path ([System.IO.Path]::GetTempPath()) "$([Guid]::newguid().ToString()).zip"
try {
Compress-Archive -path (Get-Item (Join-Path $path $_)).FullName -DestinationPath $tempFile

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

@ -79,7 +79,7 @@ try {
Write-Host "$($spaces)$($_.Name)"
}
# Create temp folders
$tempAppFolder = Join-Path ((Get-Item -Path $env:temp).FullName) ([Guid]::NewGuid().ToString())
$tempAppFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().ToString())
$tempAppDependenciesFolder = Join-Path $tempAppFolder 'dependencies'
try {
New-Item -path $tempAppFolder -ItemType Directory -Force | Out-Null

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

@ -72,7 +72,7 @@ try {
$bcAuthContext = Renew-BcAuthContext -bcAuthContext $bcAuthContext
}
$appFolder = Join-Path (Get-TempDir) ([guid]::NewGuid().ToString())
$appFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString())
try {
$appFiles = CopyAppFilesToFolder -appFiles $appFiles -folder $appFolder
$automationApiUrl = "$($bcContainerHelperConfig.apiBaseUrl.TrimEnd('/'))/v2.0/$environment/api/microsoft/automation/v2.0"
@ -115,7 +115,7 @@ try {
try {
Sort-AppFilesByDependencies -appFiles $appFiles | ForEach-Object {
Write-Host "$([System.IO.Path]::GetFileName($_))"
$tempFolder = Join-Path (Get-TempDir) ([guid]::NewGuid().ToString())
$tempFolder = Join-Path ([System.IO.Path]::GetTempPath()) ([guid]::NewGuid().ToString())
Extract-AppFileToFolder -appFilename $_ -appFolder $tempFolder -generateAppJson 6> $null
$appJsonFile = Join-Path $tempFolder "app.json"
$appJson = [System.IO.File]::ReadAllLines($appJsonFile) | ConvertFrom-Json

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

@ -176,7 +176,7 @@ function InitTelemetryScope {
}
if (($eventId -ne "") -or ($telemetry.CorrelationId -eq "")) {
$CorrelationId = [GUID]::NewGuid().ToString()
Start-Transcript -Path (Join-Path $env:TEMP $CorrelationId) | Out-Null
Start-Transcript -Path (Join-Path ([System.IO.Path]::GetTempPath()) $CorrelationId) | Out-Null
if ($telemetry.Debug) {
Write-Host -ForegroundColor Yellow "Init telemetry scope $name"
}
@ -234,11 +234,11 @@ function TrackTrace {
$telemetryScope.Emitted = $true
try {
Stop-Transcript | Out-Null
$transcript = (@(Get-Content -Path (Join-Path $env:TEMP $telemetryScope.CorrelationId)) | select -skip 18 | select -skiplast 4 | Where-Object { -not "$_".StartsWith("::add-mask::") }) -join "`n"
$transcript = (@(Get-Content -Path (Join-Path ([System.IO.Path]::GetTempPath()) $telemetryScope.CorrelationId)) | select -skip 18 | select -skiplast 4 | Where-Object { -not "$_".StartsWith("::add-mask::") }) -join "`n"
if ($transcript.Length -gt 32000) {
$transcript = "$($transcript.SubString(0,16000))`n`n...`n`n$($transcript.SubString($transcript.Length-16000))"
}
Remove-Item -Path (Join-Path $env:TEMP $telemetryScope.CorrelationId)
Remove-Item -Path (Join-Path ([System.IO.Path]::GetTempPath()) $telemetryScope.CorrelationId)
}
catch {
$transcript = ""
@ -317,11 +317,11 @@ function TrackException {
try {
Stop-Transcript | Out-Null
$transcript = (@(Get-Content -Path (Join-Path $env:TEMP $telemetryScope.CorrelationId)) | select -skip 18 | select -skiplast 4 | Where-Object { -not "$_".StartsWith("::add-mask::") }) -join "`n"
$transcript = (@(Get-Content -Path (Join-Path ([System.IO.Path]::GetTempPath()) $telemetryScope.CorrelationId)) | select -skip 18 | select -skiplast 4 | Where-Object { -not "$_".StartsWith("::add-mask::") }) -join "`n"
if ($transcript.Length -gt 32000) {
$transcript = "$($transcript.SubString(0,16000))`n`n...`n`n$($transcript.SubString($transcript.Length-16000))"
}
Remove-Item -Path (Join-Path $env:TEMP $telemetryScope.CorrelationId)
Remove-Item -Path (Join-Path ([System.IO.Path]::GetTempPath()) $telemetryScope.CorrelationId)
}
catch {
$transcript = ""

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

@ -21,7 +21,7 @@ Describe 'Misc' {
Invoke-ScriptInBCContainer -containerName $bcContainerName -scriptblock { (Get-ChildItem -Path "c:\windows\fonts").Count } | Should -BeGreaterThan $noOfFonts
}
It 'Copy-FileFromBcContainer' {
$filename = Join-Path $env:TEMP ([Guid]::NewGuid().Guid)
$filename = Join-Path ([System.IO.Path]::GetTempPath()) ([Guid]::NewGuid().Guid)
Copy-FileFromBCContainer -containerName $bcContainerName -containerPath "c:\windows\win.ini" -localPath $filename
$filename | Should -Exist
Remove-Item -Path $filename

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

@ -75,7 +75,7 @@ try {
if ($version.Major -ge 13) {
$appfile = Join-Path (Get-TempDir) "CreateTestUsers.app"
$appfile = Join-Path ([System.IO.Path]::GetTempPath()) "CreateTestUsers.app"
if (([System.Version]$version).Major -ge 15) {
Import-TestToolkitToBcContainer -containerName $containerName -tenant $tenant -includeTestFrameworkOnly -replaceDependencies $replaceDependencies -doNotUseRuntimePackages
$systemAppTestLibrary = get-BcContainerappinfo -containername $containerName -tenant $tenant | Where-Object { $_.Name -eq "System Application Test Library" }