skip to Main Content

I have a Windows VM on Azure. On startup it runs powershell script:

Start-Process cmd.exe -ArgumentList "/c whoami.exe 1> c:whoami.log 2>&1" -wait

$tempPath = "$env:TEMP"
$exePath = "$tempPathvs_buildtools.exe"

Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath

Start-Process cmd.exe -ArgumentList "/c $exePath --quiet --add Microsoft.VisualStudio.Component.TestTools.BuildTools 1> c:vs_buildtools.log 2>&1" -Wait

After creating the VM:

  1. whoami.exe works fine and writes nt authoritysystem to c:whoami.log file.
  2. vs_buildtools.exe is downloaded to C:WindowsTemp
  3. BuildTools doesn’t install anything. There is no dd_* log files in temp folder.
  4. c:vs_buildtools.log contains this error message:

The application cannot find one of its required files, possibly because it was unable to create it in the folder. Please make sure that the folder in which this application was downloaded is accessible and not read-only.

When I run the script via RDP it works fine and writes dd_* log files to temp folder.

Aslo I tried -Verb runAs. Same issue.

2

Answers


  1. Chosen as BEST ANSWER

    It is my fault I didn't show the whole script. I was sure that different parts of my script did not affect each other. But I was wrong. There was a piece of script which broke system paths including temp path:

    # Optional: For bash.exe, add 'C:Program FilesGitbin' to PATH
    [Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));C:Program FilesGitbin", 'Machine')
    
    # Make new environment variables available in the current PowerShell session:
    foreach($level in "Machine","User") {
       [Environment]::GetEnvironmentVariables($level).GetEnumerator() | % {
          # For Path variables, append the new values, if they're not already in there
          if($_.Name -match 'Path$') { 
             $_.Value = ($((Get-Content "Env:$($_.Name)") + ";$($_.Value)") -split ';' | Select -unique) -join ';'
          }
          $_
       } | Set-Content -Path { "Env:$($_.Name)" }
    }
    

  2. The application cannot find one of its required files, possibly because it was unable to create it in the folder. Please make sure that the folder in which this application was downloaded is accessible and not read-only.

    This may be because the files got corrupted or not downloaded/ installed all the required files properly.

    I have tried with your script and it is working fine in my VM:

    enter image description here

    Try with below script given by Guerlando OCs and check if it helps you to achieve your requirement.

    # Visual Studio build tools
    Write-Host "Installing visual studio build tools..." -ForegroundColor Cyan
    
    cd $env:USERPROFILE
    
    $exePath = "$env:TEMPvs.exe"
    
    Invoke-WebRequest -Uri https://aka.ms/vs/17/release/vs_BuildTools.exe -UseBasicParsing -OutFile $exePath
    
    Write-Host "layout..." -ForegroundColor Cyan
    
    Start-Process $exePath -ArgumentList "--layout .vs_BuildTools --quiet" -Wait
    cd vs_BuildTools
    
    Write-Host "actual installation..." -ForegroundColor Cyan
    
    Start-Process vs_setup.exe -ArgumentList "--installPath $env:USERPROFILEvs_BuildTools2022 --nocache --wait --noUpdateInstaller --noWeb --allWorkloads --includeRecommended --includeOptional --quiet --norestart" -Wait
    
    [Environment]::SetEnvironmentVariable('Path', "$([Environment]::GetEnvironmentVariable('Path', 'Machine'));$env:USERPROFILEvs_BuildTools2022", 'Machine')
    

    dd_* files along with vs and vs_buildtools setup files.:
    enter image description here
    Installation:
    enter image description here
    enter image description here
    enter image description here
    Created sample project:
    enter image description here

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search