Install a solution vs2019 compile node-sass node-gyp not find the compiler

1 New powershell script file

<#
This is a workaround for "node-gyp is unable to find msbuild if VS2019 is installed"
  https://github.com/nodejs/node-gyp/issues/1663
It create a shim EXE as "MSBuild\15.0\Bin\MSBuild.exe" to target "MSBuild\Current\Bin\MSBuild.exe"
By noseratio - MIT license - use at your own risk!
It requires admin mode, I use wsudo/wsudox (https://chocolatey.org/packages/wsudo) for that:
  wsudo powershell -f make-msbuild-shim.ps1 
#>

#Requires -RunAsAdministrator 
#Requires -Version 5.1
$ErrorActionPreference = "Stop"

$vsBasePath = . "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" `
  -latest `
  -requires Microsoft.Component.MSBuild `
  -property installationPath -format value

if (!$vsBasePath) { 
  throw "VS2017+ must be installed" 
}

$msbuildSimPath = [System.IO.Path]::Combine($vsBasePath, "MSBuild\15.0\Bin\MSBuild.exe")
if ([System.IO.File]::Exists($msbuildSimPath)) {
  Write-Host "Already exists: $msbuildSimPath"
  exit 0;
}

# Create the shim .EXE using C#
$code = @"
  using System;
  using System.Diagnostics;
  using System.IO;
  using System.Linq;
  static class MSBuildShim
  {
    static void Main()
    {
      var thisExe = Process.GetCurrentProcess().MainModule.FileName;
      var thisExeDir = Path.GetDirectoryName(thisExe);
      var newExe = Path.GetFullPath(Path.Combine(thisExeDir, "..\\..\\Current\\Bin", "MSBuild.exe"));
      if (!File.Exists(newExe))
        throw new FileNotFoundException(newExe);
      var process = new Process();
      process.StartInfo.FileName = newExe;
      process.StartInfo.Arguments = String.Join("\u0020", Environment.GetCommandLineArgs().Skip(1));
      process.StartInfo.UseShellExecute = false;
      if (!process.Start())
        throw new InvalidOperationException(newExe);
      process.WaitForExit();
      Environment.ExitCode = process.ExitCode;
    }
  }
"@

Add-Type -TypeDefinition $code `
  -OutputType ConsoleApplication `
  -OutputAssembly "$msbuildSimPath" `
  -ReferencedAssemblies "System.Core.dll"

Write-Host "Shim created at: $msbuildSimPath"

2 Open powershell script execution program generation gasket

If prompted prohibits execution of the script is executed set-executionpolicy remotesigned

 

Attached: npm install --global --production windows-build-tools support this not working and only 20,152,017

 

Reference: 1  http://continuousdeveloper.com/2019/04/09/node-gyp-with-visual-studio-2019/

    2 https://blog.csdn.net/ebzxw/article/details/85019887

Guess you like

Origin www.cnblogs.com/wolbo/p/11921126.html