从VS 2013升级到VS 2015后,我最初在构建应用程序时出现问题,但是通过设置msvs_version 2015
解决了这个问题。虽然这适用于npm install
(及其节点编译),但它在electron-rebuild
阶段被忽略了。
具体来说,我的构建过程曾经遇到过这个问题(我第一次升级时):
22:07:39 c:\work-projects\my-application>c:\CM\elevated_cmd.exe /C "npm install > npm_install.log"
22:22:38
22:22:38 c:\work-projects\my-application>type npm_install.log
22:22:38
22:22:38 > libxmljs-mt@0.16.1 install c:\work-projects\my-application\node_modules\libxmljs-mt
22:22:38 > node-gyp rebuild
22:22:38
22:22:38
22:22:38 c:\work-projects\my-application\node_modules\libxmljs-mt>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "" rebuild )
22:22:38 Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
22:22:38 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [c:\work-projects\my-application\node_modules\libxmljs-mt\build\xmljs.vcxproj]
但是这个命令设置可以很快解决这个问题:
npm config set msvs_version 2015 --global
一旦我设置了上面的命令,事情似乎工作正常。 (npm install
期间发生的初始编译开始正常工作)。但是一旦我到达使用electron-rebuild
的构建部分,我发现返回相同的错误,但仅在电子重建编译期间,如下所示:
13:15:32 c:\work-projects\my-application>c:\CM\elevated_cmd.exe /C "gulp erebuild > erebuild.log"
13:16:05
13:16:05 c:\work-projects\my-application>type erebuild.log
13:16:05 [13:15:41] Using gulpfile c:\work-projects\my-application\gulpfile.js
13:16:05 [13:15:41] Starting 'erebuild'...
13:16:05 [13:15:41] Finished 'erebuild' after 394 ms
13:16:05 [13:16:04] Rebuilding modules against Electron didn't work: Error: gyp info it worked if it ends with ok
13:16:05 gyp info using node-gyp@3.6.2
13:16:05 gyp info using node@7.10.1 | win32 | x64
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/iojs-v1.8.2-beta.4.tar.gz
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/iojs-v1.8.2-beta.4.tar.gz
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/SHASUMS256.txt
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/win-x64/iojs.lib
13:16:05 gyp http GET https://atom.io/download/electron/v1.8.2-beta.4/win-x86/iojs.lib
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/win-x64/iojs.lib
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/SHASUMS256.txt
13:16:05 gyp http 200 https://atom.io/download/electron/v1.8.2-beta.4/win-x86/iojs.lib
13:16:05 gyp info spawn C:\Python27\python.exe
13:16:05 gyp info spawn args [ 'c:\\work-projects\\my-application\\node_modules\\node-gyp\\gyp\\gyp_main.py',
13:16:05 gyp info spawn args 'binding.gyp',
13:16:05 gyp info spawn args '-f',
13:16:05 gyp info spawn args 'msvs',
13:16:05 gyp info spawn args '-G',
13:16:05 gyp info spawn args 'msvs_version=auto',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\build\\config.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\common.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\node-gyp\\addon.gypi',
13:16:05 gyp info spawn args '-I',
13:16:05 gyp info spawn args 'C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4\\common.gypi',
13:16:05 gyp info spawn args '-Dlibrary=shared_library',
13:16:05 gyp info spawn args '-Dvisibility=default',
13:16:05 gyp info spawn args '-Dnode_root_dir=C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4',
13:16:05 gyp info spawn args '-Dnode_gyp_dir=c:\\work-projects\\my-application\\node_modules\\node-gyp',
13:16:05 gyp info spawn args '-Dnode_lib_file=C:\\Users\\MyBuilderUser\\.electron-gyp\\.node-gyp\\iojs-1.8.2-beta.4\\<(target_arch)\\iojs.lib',
13:16:05 gyp info spawn args '-Dmodule_root_dir=c:\\work-projects\\my-application\\node_modules\\libxml-xsd',
13:16:05 gyp info spawn args '-Dnode_engine=v8',
13:16:05 gyp info spawn args '--depth=.',
13:16:05 gyp info spawn args '--no-parallel',
13:16:05 gyp info spawn args '--generator-output',
13:16:05 gyp info spawn args 'c:\\work-projects\\my-application\\node_modules\\libxml-xsd\\build',
13:16:05 gyp info spawn args '-Goutput_dir=.' ]
13:16:05 gyp info spawn C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe
13:16:05 gyp info spawn args [ 'build/binding.sln',
13:16:05 gyp info spawn args '/clp:Verbosity=minimal',
13:16:05 gyp info spawn args '/nologo',
13:16:05 gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
13:16:05 Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
13:16:05 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.Cpp.Platform.targets(57,5): error MSB8020: The build tools for v120 (Platform Toolset = 'v120') cannot be found. To build using the v120 build tools, please install v120 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution". [c:\work-projects\my-application\node_modules\libxml-xsd\build\node-libxml-xsd.vcxproj]
13:16:05 gyp ERR! build error
13:16:05 gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
13:16:05 gyp ERR! stack at ChildProcess.onExit (c:\work-projects\my-application\node_modules\node-gyp\lib\build.js:258:23)
13:16:05 gyp ERR! stack at emitTwo (events.js:106:13)
13:16:05 gyp ERR! stack at ChildProcess.emit (events.js:194:7)
13:16:05 gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
13:16:05 gyp ERR! System Windows_NT 6.3.9600
13:16:05 gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "c:\\work-projects\\my-application\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=1.8.2-beta.4" "--arch=x64" "--dist-url=https://atom.io/download/electron" "--build-from-source"
13:16:05 gyp ERR! cwd c:\work-projects\my-application\node_modules\libxml-xsd
13:16:05 gyp ERR! node -v v7.10.1
13:16:05 gyp ERR! node-gyp -v v3.6.2
13:16:05 gyp ERR! not ok
13:16:05
13:16:05 Failed with exit code: 1
我对电子重建的大肆宣传非常简单明了,所以我怀疑它会揭示多少,但这里是:
```
gulp.task('erebuild', , function () {
var eRebuild = require('electron-rebuild').rebuild;
var arch = process.arch;
eRebuild(
{buildPath: __dirname,
electronVersion: electronVersion,
arch: arch
})
.then(function () {
log('electron version: ' + electronVersion + ' arch version: ' + arch);
log('Electron Rebuild Successful');
return true;
}).catch(function (e) {
log('Rebuilding modules against Electron didn\'t work: ' + e);
});
});
```
我应该在我的electron-rebuild
调用中添加一个选项来强制使用msvs_version值吗?
electron-rebuild
不应该npm install
自动使用此值吗?
我注意到electron-rebuild
显示的gyp配置参数msvs_version=auto
显示为其设置而非2015
(请参阅“当前问题”部分中约1/3的方式以上)。如何指定auto
/或指向2015
的值(或如何让electron-rebuild
明确使用2015而不是auto
)?我不完全确定应如何处理这个问题。这是electron-rebuild
中的错误吗? electron-rebuild
是否可以选择指定msvs_version
?或者auto
应该是我在配置中设置的值?如果是这样的话?
答案 0 :(得分:0)
最后,尝试让electron-rebuild
以某种方式查看npm msvs_version
设置所设置的配置,无法解决此问题。在我的情况下,MS Visual Studio 2015和2017的工具集都在此过程中安装,似乎这些安装/卸载过程中的一些导致了问题。
我为解决此问题所做的是:
首先,我卸载了所有版本的MSBuild工具,MS Visual Studio (2015年和2017年,在我的情况下)甚至是Python。
然后我按照“Windows”特定说明的“选项1”进行操作
https://www.npmjs.com/package/node-gyp#installation通过做
npm install --global --production windows-build-tools
因为所有VS,MSBuild工具和Python都重新安装了
windows-build-tools
包安装,Python设置似乎
稍微不完整。为了解决这个问题,我做了以下事情:
a)配置Node以查看Python(运行npm config set python
"C:\Users\MyUser\.windows-build-tools\python27\python.exe"
)
b)设置PYTHON环境变量。您可以通过使用控制面板或在可以运行的高架CMD上执行此操作
set PYTHON "C:\Users\MyUser\.windows-build-tools\python27\python.exe"
之后,一切正常。