构建说明(Windows)
¥Build Instructions (Windows)
请遵循以下指南在 Windows 上构建 Electron 本身,以创建自定义 Electron 二进制文件。要使用预构建的 Electron 二进制文件打包和分发应用代码,请参阅 应用分发 指南。
¥Follow the guidelines below for building Electron itself on Windows, for the purposes of creating custom Electron binaries. For bundling and distributing your app code with the prebuilt Electron binaries, see the application distribution guide.
先决条件
¥Prerequisites
-
Windows 10 / Server 2012 R2 或更高版本
¥Windows 10 / Server 2012 R2 or higher
-
构建 Visual Studio 2019 (>=16.0.0),但首选 Visual Studio 2022 (>=17.0.0) - 免费下载 VS 2022 社区版
¥Visual Studio 2019 (>=16.0.0) to build, but Visual Studio 2022 (>=17.0.0) is preferred - download VS 2022 Community Edition for free
-
有关需要哪些 Visual Studio 组件的更多详细信息,请参阅 Chromium 构建文档。
¥See the Chromium build documentation for more details on which Visual Studio components are required.
-
如果你的 Visual Studio 安装在默认目录以外的目录中,则需要设置一些环境变量以将工具链指向你的安装路径。
¥If your Visual Studio is installed in a directory other than the default, you'll need to set a few environment variables to point the toolchains to your installation path.
-
vs2022_install = DRIVE:\path\to\Microsoft Visual Studio\2022\Community
,将2022
和Community
替换为你安装的版本,并将DRIVE:
替换为 Visual Studio 所在的驱动器。通常,这将是C:
。¥
vs2022_install = DRIVE:\path\to\Microsoft Visual Studio\2022\Community
, replacing2022
andCommunity
with your installed versions and replacingDRIVE:
with the drive that Visual Studio is on. Often, this will beC:
. -
WINDOWSSDKDIR = DRIVE:\path\to\Windows Kits\10
,将DRIVE:
替换为 Windows 套件所在的驱动器。通常,这将是C:
。¥
WINDOWSSDKDIR = DRIVE:\path\to\Windows Kits\10
, replacingDRIVE:
with the drive that Windows Kits is on. Often, this will beC:
.
-
-
-
如果你打算创建完整的发行版,请使用 Windows SDK 10.0.15063.468 的 Windows 调试工具,因为
symstore.exe
用于从.pdb
文件创建符号存储。¥Debugging Tools for Windows of Windows SDK 10.0.15063.468 if you plan on creating a full distribution since
symstore.exe
is used for creating a symbol store from.pdb
files.-
不同版本的 SDK 可以并行安装。要安装 SDK,请打开 Visual Studio 安装程序,选择
Modify
→Individual Components
,向下滚动并选择要安装的相应 Windows SDK。另一种选择是查看 Windows SDK 和模拟器存档 并分别下载 SDK 的独立版本。¥Different versions of the SDK can be installed side by side. To install the SDK, open Visual Studio Installer, select
Modify
→Individual Components
, scroll down and select the appropriate Windows SDK to install. Another option would be to look at the Windows SDK and emulator archive and download the standalone version of the SDK respectively. -
还必须安装 SDK 调试工具。如果 Windows 10 SDK 是通过 Visual Studio 安装程序安装的,则可以通过以下方式安装它们:
Control Panel
→Programs
→Programs and Features
→选择 "Windows 软件开发套件"→Change
→Change
→勾选 "Windows 调试工具"→Change
。或者,你可以下载独立的 SDK 安装程序并使用它来安装调试工具。¥The SDK Debugging Tools must also be installed. If the Windows 10 SDK was installed via the Visual Studio installer, then they can be installed by going to:
Control Panel
→Programs
→Programs and Features
→ Select the "Windows Software Development Kit" →Change
→Change
→ Check "Debugging Tools For Windows" →Change
. Or, you can download the standalone SDK installer and use it to install the Debugging Tools.
-
如果你当前没有安装 Windows,developer.microsoft.com 有定时炸弹版本的 Windows,你可以使用它来构建 Electron。
¥If you don't currently have a Windows installation, developer.microsoft.com has timebombed versions of Windows that you can use to build Electron.
构建 Electron 完全使用命令行脚本完成,无法使用 Visual Studio 完成。你可以使用任何编辑器开发 Electron,但未来将支持使用 Visual Studio 进行构建。
¥Building Electron is done entirely with command-line scripts and cannot be done with Visual Studio. You can develop Electron with any editor but support for building with Visual Studio will come in the future.
注意:尽管 Visual Studio 不用于构建,但它仍然是必需的,因为我们需要它提供的构建工具链。
¥Note: Even though Visual Studio is not used for building, it's still required because we need the build toolchains it provides.
从 Windows 安全性中排除源树
¥Exclude source tree from Windows Security
Windows Security 不喜欢 Chromium 源代码中的某个文件(参见 https://crbug.com/441184),因此它会不断删除它,从而导致 gclient sync
问题。你可以通过 遵循这些说明 将源树排除在 Windows 安全性的监视之外。
¥Windows Security doesn't like one of the files in the Chromium source code
(see https://crbug.com/441184), so it will constantly delete it, causing gclient sync
issues.
You can exclude the source tree from being monitored by Windows Security by
following these instructions.
架构
¥Building
见 构建说明:GN
32 位构建
¥32bit Build
要构建 32 位目标,你需要将 target_cpu = "x86"
作为 GN arg 传递。你可以通过使用不同的 GN 输出目录(例如,在 64 位目标的同时构建 32 位目标) out/Release-x86
,有不同的参数。
¥To build for the 32bit target, you need to pass target_cpu = "x86"
as a GN
arg. You can build the 32bit target alongside the 64bit target by using a
different output directory for GN, e.g. out/Release-x86
, with different
arguments.
$ gn gen out/Release-x86 --args="import(\"//electron/build/args/release.gn\") target_cpu=\"x86\""
其他的搭建步骤完全一样。
¥The other building steps are exactly the same.
视觉工作室项目
¥Visual Studio project
要生成 Visual Studio 项目,可以将 --ide=vs2017
参数传递给 gn gen
:
¥To generate a Visual Studio project, you can pass the --ide=vs2017
parameter
to gn gen
:
$ gn gen out/Testing --ide=vs2017
故障排除
¥Troubleshooting
未找到命令 xxxx
¥Command xxxx not found
如果你遇到类似 Command xxxx not found
的错误,你可以尝试使用 VS2015 Command Prompt
控制台来执行构建脚本。
¥If you encountered an error like Command xxxx not found
, you may try to use
the VS2015 Command Prompt
console to execute the build scripts.
致命的内部编译器错误:C1001
¥Fatal internal compiler error: C1001
确保你安装了最新的 Visual Studio 更新。
¥Make sure you have the latest Visual Studio update installed.
LNK1181:无法打开输入文件 'kernel32.lib'
¥LNK1181: cannot open input file 'kernel32.lib'
尝试重新安装 32 位 Node.js。
¥Try reinstalling 32bit Node.js.
错误:ENOENT,统计 'C:\Users\USERNAME\AppData\Roaming\npm'
¥Error: ENOENT, stat 'C:\Users\USERNAME\AppData\Roaming\npm'
创建该目录 应该解决问题:
¥Creating that directory should fix the problem:
$ mkdir ~\AppData\Roaming\npm
node-gyp 未被识别为内部或外部命令
¥node-gyp is not recognized as an internal or external command
如果你使用 Git Bash 进行构建,你可能会收到此错误,你应该使用 PowerShell 或 VS2015 命令提示符。
¥You may get this error if you are using Git Bash for building, you should use PowerShell or VS2015 Command Prompt instead.
无法在 '...' 创建目录:文件名太长
¥cannot create directory at '...': Filename too long
node.js 有一些 极长的路径名,默认情况下 Windows 上的 git 不能正确处理长路径名(即使 Windows 支持它们)。这应该可以修复它:
¥node.js has some extremely long pathnames, and by default git on windows doesn't handle long pathnames correctly (even though windows supports them). This should fix it:
$ git config --system core.longpaths true
错误:使用未声明的标识符 'DefaultDelegateCheckMode'
¥error: use of undeclared identifier 'DefaultDelegateCheckMode'
当 Windows 调试工具与 Windows 驱动程序工具包一起安装时,这种情况可能会在构建过程中发生。按照上述步骤卸载 Windows 驱动程序工具包并安装调试工具。
¥This can happen during build, when Debugging Tools for Windows has been installed with Windows Driver Kit. Uninstall Windows Driver Kit and install Debugging Tools with steps described above.
构建脚本挂起直至按键
¥Build Scripts Hang Until Keypress
此错误是 Windows 命令提示符的 "feature"。当在启用 QuickEdit
的情况下单击提示窗口内时会发生这种情况,旨在允许轻松选择和复制输出文本。由于每次意外单击都会暂停构建过程,因此你可能需要在命令提示符属性中禁用此功能。
¥This bug is a "feature" of Windows' command prompt. It happens when clicking inside the prompt window with
QuickEdit
enabled and is intended to allow selecting and copying output text easily.
Since each accidental click will pause the build process, you might want to disable this
feature in the command prompt properties.