372372 $VCVarsAllArch = ' x64_arm64'
373373 }
374374
375- # Only configure build environment once
376- if ($env: CEFSHARP_BUILD_IS_BOOTSTRAPPED -ne " $Toolchain$Platform " )
377- {
375+ # Store the current environment variables so that we can reset them after running the build.
376+ # This is because vcvarsall.bat appends e.g. to the PATH variable every time it is called,
377+ # which can eventually lead to an error like "The input line is too long." when the PATH
378+ # gets too long.
379+ $PreviousEnvPath = $Env: Path
380+ $PreviousEnvLib = $Env: Lib
381+ $PreviousEnvLibPath = $Env: LibPath
382+ $PreviousEnvInclude = $Env: Include
383+
384+ try
385+ {
386+ # Configure build environment
378387 Invoke-BatchFile $VCVarsAll $VCVarsAllArch
379388 Write-Diagnostic " pushd $CefDir "
380389 pushd $CefDir
@@ -390,53 +399,60 @@ try
390399 Write-Diagnostic " Running cmake: $cmake_path -LAH -G '$CmakeGenerator ' -A $Arch -DUSE_SANDBOX=Off -DCEF_RUNTIME_LIBRARY_FLAG=/MD ."
391400 & " $cmake_path " - LAH - G " $CmakeGenerator " - A $Arch - DUSE_SANDBOX= Off - DCEF_RUNTIME_LIBRARY_FLAG=/ MD .
392401 popd
393- $env: CEFSHARP_BUILD_IS_BOOTSTRAPPED = " $Toolchain$Platform "
394- }
395-
396- $Arguments = @ (
397- " $CefProject " ,
398- " /t:rebuild" ,
399- " /p:VisualStudioVersion=$VisualStudioVersion " ,
400- " /p:Configuration=$Configuration " ,
401- " /p:PlatformToolset=$Toolchain " ,
402- " /p:Platform=$Arch " ,
403- " /p:PreferredToolArchitecture=$Arch " ,
404- " /p:ConfigurationType=StaticLibrary"
405- )
406402
407- $StartInfo = New-Object System.Diagnostics.ProcessStartInfo
408- $StartInfo.FileName = " msbuild.exe"
409- $StartInfo.Arguments = $Arguments
403+ $Arguments = @ (
404+ " $CefProject " ,
405+ " /t:rebuild" ,
406+ " /p:VisualStudioVersion=$VisualStudioVersion " ,
407+ " /p:Configuration=$Configuration " ,
408+ " /p:PlatformToolset=$Toolchain " ,
409+ " /p:Platform=$Arch " ,
410+ " /p:PreferredToolArchitecture=$Arch " ,
411+ " /p:ConfigurationType=StaticLibrary"
412+ )
413+
414+ $StartInfo = New-Object System.Diagnostics.ProcessStartInfo
415+ $StartInfo.FileName = " msbuild.exe"
416+ $StartInfo.Arguments = $Arguments
417+
418+ $StartInfo.EnvironmentVariables.Clear ()
419+
420+ # Brace must be on same line for foreach-object to work
421+ Get-ChildItem - Path env:* | ForEach-Object {
422+ $StartInfo.EnvironmentVariables.Add ($_.Name , $_.Value )
423+ }
410424
411- $StartInfo.EnvironmentVariables.Clear ()
425+ $StartInfo.UseShellExecute = $false
426+ $StartInfo.CreateNoWindow = $false
427+ $StartInfo.RedirectStandardError = $true
428+ $StartInfo.RedirectStandardOutput = $true
412429
413- # Brace must be on same line for foreach-object to work
414- Get-ChildItem - Path env:* | ForEach-Object {
415- $StartInfo.EnvironmentVariables.Add ($_.Name , $_.Value )
416- }
430+ $Process = New-Object System.Diagnostics.Process
431+ $Process.StartInfo = $startInfo
432+ $Process.Start ()
417433
418- $StartInfo.UseShellExecute = $false
419- $StartInfo.CreateNoWindow = $false
420- $StartInfo.RedirectStandardError = $true
421- $StartInfo.RedirectStandardOutput = $true
434+ $stdout = $Process.StandardOutput.ReadToEnd ()
435+ $stderr = $Process.StandardError.ReadToEnd ()
422436
423- $Process = New-Object System.Diagnostics.Process
424- $Process.StartInfo = $startInfo
425- $Process.Start ()
426-
427- $stdout = $Process.StandardOutput.ReadToEnd ()
428- $stderr = $Process.StandardError.ReadToEnd ()
429-
430- $Process.WaitForExit ()
437+ $Process.WaitForExit ()
431438
432- if ($Process.ExitCode -ne 0 )
439+ if ($Process.ExitCode -ne 0 )
440+ {
441+ Write-Host " stdout: $stdout "
442+ Write-Host " stderr: $stderr "
443+ Die " Build failed"
444+ }
445+
446+ CreateCefSdk $Toolchain $Configuration $Platform
447+ }
448+ finally
433449 {
434- Write-Host " stdout: $stdout "
435- Write-Host " stderr: $stderr "
436- Die " Build failed"
450+ # Reset the environment variables to their previous values.
451+ $Env: Path = $PreviousEnvPath
452+ $Env: Lib = $PreviousEnvLib
453+ $Env: LibPath = $PreviousEnvLibPath
454+ $Env: Include = $PreviousEnvInclude
437455 }
438-
439- CreateCefSdk $Toolchain $Configuration $Platform
440456 }
441457
442458 function VSX
0 commit comments