Version: 2022.3
Develop for Windows
Windows debugging

Visual Studio project generation for Windows

The Create Visual Studio Solution Build Setting makes Unity generate a Visual Studio Solution instead of build a Player. Generating a Visual Studio Solution enables you to change your build process. For example, you can:

  • 修改应用程序的清单。
  • 添加 C++ 代码。
  • 修改嵌入式资源。
  • 附带调试器启动应用程序。

Note: This option is only available when you are using the Windows build target.

Create a Visual Studio Solution

警告:在重建 Unity 项目之前,请务必保存并备份在 Visual Studio 中所做的任何更改。如果不备份更改,Unity 会在构建过程中覆盖这些更改。

  1. Go to File > Build Settings > Target Platform.
  2. Select the Windows build target.
  3. Enable the Create Visual Studio Solution build setting.
  4. Select Build to generate the solution.
选择了 Create Visual Studio Solution 的 Build Settings 面板
选择了 Create Visual Studio Solution 的 Build Settings 面板

By default, Unity stores the Visual Studio Solution you generate in the same directory as your built project.

Scripting backends

Depending on which scripting backend your Unity project uses, the Visual Studio Solution that Unity generates includes a different number of projects. For the Mono scripting backend, the solution includes three projects. For the IL2CPP scripting backend, the solution includes four projects.

注意:只能在 Windows 计算机上构建 Windows IL2CPP。

项目重定向向导

Unity generates a Visual Studio Solution that targets Visual Studio 2015. If you are using a newer version of Visual Studio, you might see the Retarget Projects dialog box when you open your Visual Studio Solution.

The Retarget Projects dialog prompts you to upgrade your Visual Studio Solution to match the Visual Studio version you have installed. Select OK to accept this suggestion.

解决方案内容

Below is a list of the projects Unity generates for your Visual Studio Solution.

项目 描述
projectName
(表示您的项目名称)
这是您的主项目。Visual Studio 将此项目构建到最终的应用程序可执行文件中。您最有可能在此处进行更改。
UnityData
(存储在 projectName 项目内)
此项目包含构建项目所需的所有 Unity 特定文件(如资源)。
UnityPlayerStub 这是一个 UnityPlayer.dll 存根库。Unity 使用它将可执行文件链接到 UnityPlayer.dll 并公开可用的 UnityPlayer.dll API。
Il2CppOutputProject
(仅限 IL2CPP 脚本后端)
This project contains:
• The generated C++ code which Unity converts from managed assemblies.
• The source code for IL2CPP runtime.
• The IL2CPP garbage collector.
You can debug this code from inside Visual Studio.

Visual Studio 中的构建配置选项

Visual Studio provides a variety of build configuration options. All optimization and debug references in this section refer to the Visual Studio Solution only. To select your options, click on Release and choose from the drop-down menu.

构建配置的类型

Configuration 用法 描述
Debug 调试 C++ 代码时使用 Debug 配置。
• Disables all optimization.
• Preserves all debugging information in the code.
• Results in code that runs slowly.
Release 使用 Release 配置来分析游戏。 • Enables code optimizations.
Master 使用 Master 配置进行游戏提交和最终测试。 • Disables the profiler.
• Results in the same build time as the Release configuration.
MasterWithLTCG .Only available with the IL2CPP scripting backend is enabled. 如果使用的是 IL2CPP 脚本后端,可以选择 MasterMasterWithLTCG 进行游戏提交和最终测试。 • Enables link time code generation for generated C++ code, IL2CPP runtime and IL2CPP garbage collection.
• Results in much longer build times compared to the Master configuration.
• Resulting application executes faster.
Develop for Windows
Windows debugging