Microsoft c + + 移植和升级指南Microsoft C++ porting and upgrading guide

本文提供将 Microsoft c + + 代码升级到最新版本的 Visual Studio 的指南。This article provides a guide for upgrading Microsoft C++ code to the latest version of Visual Studio. 对于在 Visual Studio 2010 到2015中创建的项目,只需在 Visual Studio 2019 中打开该项目。For projects created in Visual Studio 2010 through 2015, just open the project in Visual Studio 2019. 可以通过两个步骤升级 Visual Studio 2008 或更早版本的项目。You can upgrade a Visual Studio 2008 or earlier project in two steps. 首先,使用 Visual Studio 2010 将项目转换为 MSBuild 格式。Use Visual Studio 2010 to convert the project to MSBuild format first. 然后在 Visual Studio 2019 中打开该项目。Then open the project in Visual Studio 2019. 有关完整说明,请参阅 从早期版本的 Visual Studio 升级 c + + 项目For complete instructions, see Upgrading C++ projects from earlier versions of Visual Studio.

Visual Studio 2015、Visual Studio 2017 和 Visual Studio 2019 中的工具集与二进制兼容。The toolsets in Visual Studio 2015, Visual Studio 2017, and Visual Studio 2019 are binary-compatible. 现在,你可以升级到较新版本的编译器,而不必升级库依赖项。Now you can upgrade to a more recent version of the compiler without having to upgrade your library dependencies. 有关详细信息,请参阅 c + + 二进制兼容性 2015-2019For more information, see C++ binary compatibility 2015-2019.

升级使用开源库的项目或要在多个平台上运行的项目时,我们建议迁移到基于 CMake 的项目。When upgrading projects that use open-source libraries or are meant to run on multiple platforms, we recommended migrating to a CMake-based project. 有关详细信息,请参阅 Visual Studio 中的 CMake 项目For more information, see CMake projects in Visual Studio

升级 c + + 代码的原因Reasons to upgrade C++ code

如果旧的应用程序运行在安全的环境中,而不是处于活动状态,则可能无需再进行升级。If a legacy application is running satisfactorily, in a secure environment, and isn't under active development, there might not be much incentive to upgrade it. 但在这种情况下,请考虑升级:应用程序需要持续维护。However, consider an upgrade in these cases: Your application requires ongoing maintenance. 或者,您要进行全新的功能开发,或者进行性能或安全性改进。Or, you're doing new feature development, or making performance or security improvements. 升级带来了以下好处:An upgrade brings these benefits:

  • 这一代码可以更快地运行,因为我们已经改进了编译器优化。The same code can run faster, because we've improved compiler optimizations.

  • 新式 c + + 功能和编程做法消除了许多常见的 bug 原因,并生成的代码比旧的 C 样式惯例更易于维护。Modern C++ features and programming practices eliminate many common causes of bugs, and produce code that's far easier to maintain than older C-style idioms.

  • 由于编译器和链接器中的性能改进,生成时间更快。Build times are faster, because of performance improvements in the compiler and linker.

  • 更好的标准一致性。Better standards conformance. /Permissive-编译器选项有助于识别不符合当前 c + + 标准的代码。The /permissive- compiler option helps you identify code that doesn't conform to the current C++ standard. 新的预处理器也支持代码一致性。The new preprocessor supports code conformance, too.

  • 更好的运行时安全性,包括更安全的 C 运行时库 功能。Better run-time security, including more secure C Runtime library features. 此外,在 Visual Studio 2019 版本 16.4) 中 (新增功能,例如, 防护检查 和地址 sanitizers 等编译器功能。And, compiler features such as guard checking and address sanitizers (new in Visual Studio 2019 version 16.4).

多定向与升级Multitargeting vs. upgrading

或许您不能将基本代码升级到新的工具集。Perhaps upgrading your code base to a new toolset isn't an option for you. 你仍可以使用最新的 Visual Studio 来生成和编辑使用较旧工具集和库的项目。You can still use the latest Visual Studio to build and edit projects that use older toolsets and libraries. 在 Visual Studio 2019 中,可以利用如下功能:In Visual Studio 2019, you can take advantage of features such as:

  • 新式静态分析工具,包括 C++ Core Guidelines 跳棋和 Clang,以帮助确定你的源代码中可能存在的问题。modern static analysis tools, including the C++ Core Guidelines checkers and Clang-Tidy, to help identify potential problems in your source code.

  • 根据您选择的新式样式自动设置格式可帮助使旧代码更具可读性。automatic formatting according to your choice of modern styles can help make legacy code much more readable.

有关详细信息,请参阅 使用 Visual Studio 中的本机多重目标生成旧项目For more information, see Use native multi-targeting in Visual Studio to build old projects.

本节内容In this section

TitleTitle 说明Description
从 Visual Studio 的早期版本升级 c + + 项目Upgrading C++ projects from earlier versions of Visual Studio 如何将基本代码升级到 Visual Studio 2019 和编译器的 v142。How to upgrade your code base to Visual Studio 2019 and v142 of the compiler.
用于升级 C++ 代码的 IDE 工具IDE tools for upgrading C++ code 有助于升级过程的有用 IDE 功能。Useful IDE features that help in the upgrade process.
C++ 二进制兼容性 (2015-2019)C++ binary compatibility 2015-2019 从 v142 项目按原样使用 v140 和 v141 库。Consume v140 and v141 libraries as-is from v142 projects.
使用 Visual Studio 中的本机多目标来生成旧项目Use native multi-targeting in Visual Studio to build old projects 将 Visual Studio 2019 与较旧的编译器和库配合使用。Use Visual Studio 2019 with older compilers and libraries.
Visual C++ 更改历史记录(2003 - 2015)Visual C++ change history 2003 - 2015 Microsoft c + + 库中的所有更改的列表,以及 Visual Studio 2003 到2015中的生成工具,可能需要在代码中进行更改。A list of all the changes in the Microsoft C++ libraries and build tools from Visual Studio 2003 through 2015 that might require changes in your code.
Visual C++ 新增功能 (2003 - 2015)Visual C++ What's New 2003 through 2015 Visual Studio 2003 到 Visual Studio 2015 的 Microsoft c + + 的所有 "新增功能" 信息。All the "what's new" information for Microsoft C++ from Visual Studio 2003 through Visual Studio 2015.
移植和升级:示例和案例研究Porting and Upgrading: Examples and Case Studies 本部分中,我们移植和升级了多个示例和应用程序并讨论了体验和结果。For this section, we ported and upgrades several samples and applications and discussed the experiences and results. 通过这些文章可了解移植和升级过程中所涉及的内容。These articles give you a sense of what's involved in the porting and upgrading process. 在整个过程中,我们讨论了升级所用的提示和技巧,并演示如何修复特定错误。Throughout the process, we discuss tips and tricks for upgrading and show how specific errors were fixed.
移植到通用 Windows 平台Porting to the Universal Windows Platform 包含有关移植代码到 Windows 10 的信息Contains information about porting code to Windows 10
Visual C++ 简介(针对 UNIX 用户)Introduction to Visual C++ for UNIX Users 为不熟悉 Visual C++ 并想要有效率的使用它的 UNIX 用户提供信息。Provides information for UNIX users who are new to Visual C++ and want to become productive with it.
在 Windows 上运行 Linux 程序Running Linux programs on Windows 讨论用于将 UNIX 应用程序迁移到 Windows 的选项。Discusses options for migrating UNIX applications to Windows.

另请参阅See also

Visual Studio 中的 C++C++ in Visual Studio
Visual Studio 中 C++ 编译器的新增功能What's New for The C++ compiler in Visual Studio
Visual Studio 中的 C++ 符合性改进C++ conformance improvements in Visual Studio