处理使用node-gpy时遇到的Can't find "msbuild.exe"错误



在Windows中使用node-gpy编译Node.js C++原生扩展时,需要使用Visual Studio C++的"msbuild.exe"。有时尽管Visual Studio安装运行正常,在调用node-gyp时仍会遇到找不到"msbuild.exe"的错误提示:

Error: Can't find "msbuild.exe". Do you have Mircrosoft Visual Studio C++ 2008+ instlled?

node-gpy在搜索"msbuild.exe"时,是通过查询Windows注册表,提取Visual Studio C++版本号来获取"msbuild.exe"安装路径。出现上述运行错误的原因之一就是node-gpy查询Windows注册表出现差错。node-gpy查询Windows注册表的脚本代码在
C:\Users\abc\AppData\Roaming\npm\node_modules\node-gyp\lib\build.js

其中"abc"为当前用户名。 具体代码如下:
  function findMsbuild () {
    log.verbose('could not find "msbuild.exe" in PATH - finding location in registry')
    var notfoundErr = new Error('Can\'t find "msbuild.exe". Do you have Microsoft Visual Studio C++ 2008+ installed?')
    var cmd = 'reg  query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'

其中最后一行语句即为运行出错代码。如代码所示,node-gpy通过调用"reg.exe"查询Windows注册表。node-gpy的脚本代码中没有设置"reg.exe"路径。 "reg.exe"一般保存在'C:\\Windows\\System32\\'文件夹中,将这行代码做如下修改:
var cmd = 'C:\\Windows\\System32\\reg.exe query "HKLM\\Software\\Microsoft\\MSBuild\\ToolsVersions" /s'
node-gpy就能获取"msbuild.exe"的安装路径。




  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值