在 Visual Studio 中安装 C++ 支持Install C++ support in Visual Studio

如果尚未下载并安装 Visual Studio 和 Visual C++ tools,请参阅下面的入门指南。If you haven't downloaded and installed Visual Studio and the Visual C++ tools yet, here's how to get started.

Visual Studio 2019 安装Visual Studio 2019 Installation

欢迎使用 Visual Studio 2019!Welcome to Visual Studio 2019! 在此版本中,可轻松选择并仅安装所需功能。In this version, it's easy to choose and install just the features you need. 并且由于其最小占用减小,因此其安装速度快且对系统的影响极小。And because of its reduced minimum footprint, it installs quickly and with less system impact.

备注

本主题适用于在 Windows 上安装 Visual Studio。This topic applies to installation of Visual Studio on Windows. Visual Studio Code是一种轻型的跨平台开发环境,在 Windows、Mac 和 Linux 系统上运行。Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. Microsoft C/C++ for Visual Studio Code扩展支持 IntelliSense、调试、代码格式设置、自动完成。The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac 不支持 Microsoft C++,但支持 .net 语言和跨平台开发。Visual Studio for Mac doesn't support Microsoft C++, but does support .NET languages and cross-platform development. 有关安装说明,请参阅安装 Visual Studio for MacFor installation instructions, see Install Visual Studio for Mac.

想要详细了解此版本的其他新增功能?Want to know more about what else is new in this version? 请参阅 Visual Studio发行说明See the Visual Studio release notes.

准备安装?Ready to install? 我们将逐步引导你完成安装。We'll walk you through it, step-by-step.

第 1 步 - 确保计算机支持 Visual StudioStep 1 - Make sure your computer is ready for Visual Studio

开始安装 Visual Studio 前:Before you begin installing Visual Studio:

  1. 查看系统要求Check the system requirements. 这些要求有助于了解计算机是否支持 Visual Studio 2019。These requirements help you know whether your computer supports Visual Studio 2019.

  2. 应用最新的 Windows 更新。Apply the latest Windows updates. 这些更新可确保计算机包含最新的安全更新程序和 Visual Studio 所需的系统组件。These updates ensure that your computer has both the latest security updates and the required system components for Visual Studio.

  3. 重新启动。Reboot. 重新启动可确保挂起的任何安装或更新都不会影响 Visual Studio 安装。The reboot ensures that any pending installs or updates don't hinder the Visual Studio install.

  4. 释放空间。Free up space. 通过运行磁盘清理应用程序等方式,从 %SystemDrive% 删除不需要的文件和应用程序。Remove unneeded files and applications from your %SystemDrive% by, for example, running the Disk Cleanup app.

有关使用 Visual Studio 2019 并排运行 Visual Studio 先前版本的问题,请参阅 Visual Studio 2019 平台目标和兼容性页面。For questions about running previous versions of Visual Studio side by side with Visual Studio 2019, see the Visual Studio 2019 Platform Targeting and Compatibility page.

第 2 步 - 下载 Visual StudioStep 2 - Download Visual Studio

接下来,下载 Visual Studio 引导程序文件。Next, download the Visual Studio bootstrapper file. 为此,请选择下面的按钮,选择所需的 Visual Studio 版本,选择“保存”,然后选择“打开文件夹”。To do so, choose the following button, choose the edition of Visual Studio that you want, choose Save, and then choose Open folder.

第 3 步 - 打开 Visual Studio 安装程序Step 3 - Install the Visual Studio installer

运行引导程序文件以安装 Visual Studio 安装程序。Run the bootstrapper file to install the Visual Studio Installer. 这个新的轻型安装程序包括安装和自定义 Visual Studio 所需的一切。This new lightweight installer includes everything you need to both install and customize Visual Studio.

  1. 在“下载”文件夹中,双击与下列文件之一匹配或类似的引导程序文件:From your Downloads folder, double-click the bootstrapper that matches or is similar to one of the following files:

    • 对于 Visual Studio Community,请运行 vs_community.exevs_community.exe for Visual Studio Community
    • 对于 Visual Studio Professional,请运行 vs_professional.exevs_professional.exe for Visual Studio Professional
    • 对于 Visual Studio Enterprise,请运行 vs_enterprise.exevs_enterprise.exe for Visual Studio Enterprise

    如果收到用户帐户控制通知,请选择“是”。If you receive a User Account Control notice, choose Yes.

  2. 我们会要求确认 Microsoft 许可条款和 Microsoft 隐私声明We'll ask you to acknowledge the Microsoft License Terms and the Microsoft Privacy Statement. 选择“继续”。Choose Continue.

第 4 步 - 选择工作负载Step 4 - Choose workloads

安装安装程序后,可以通过选择所需的工作负荷或功能集来使用它来自定义安装。After the installer is installed, you can use it to customize your installation by selecting the workloads, or feature sets, that you want. 操作方法如下。Here's how.

  1. 在“安装 Visual Studio”屏幕中找到所需的工作负载。Find the workload you want in the Installing Visual Studio screen.

    Visual Studio 2019:安装工作负荷

    对于核心C++支持,请选择 "桌面开发C++" 工作负载。For core C++ support, choose the "Desktop development with C++" workload. 它附带默认核心编辑器,该编辑器针对超过 20 种语言提供基本代码编辑支持,能够打开和编辑任意文件夹中的代码(而无需使用项目),还提供集成的源代码管理。It comes with the default core editor, which includes basic code editing support for over 20 languages, the ability to open and edit code from any folder without requiring a project, and integrated source code control.

    其他工作负荷支持其他类型C++的开发。Additional workloads support other kinds of C++ development. 例如,选择 "通用 Windows 平台开发" 工作负荷,以创建使用 Microsoft Store 的 Windows 运行时的应用。For example, choose the "Universal Windows Platform development" workload to create apps that use the Windows Runtime for the Microsoft Store. 选择 "使用C++游戏开发" 创建使用 DirectX、Unreal 和 cocos2d 为后盾的游戏。Choose "Game development with C++" to create games that use DirectX, Unreal, and Cocos2d. 选择 "通过C++linux 开发" 来面向 linux 平台,包括 IoT 开发。Choose "Linux development with C++" to target Linux platforms, including IoT development.

    "安装详细信息" 窗格列出了每个工作负荷安装的包含组件和可选组件。The Installation details pane lists the included and optional components installed by each workload. 您可以选择或取消选择此列表中的可选组件。You can select or deselect optional components in this list. 例如,若要使用 Visual Studio 2017 或2015编译器工具集来支持开发,请选择 MSVC v141 或 MSVC v140 可选组件。For example, to support development by using the Visual Studio 2017 or 2015 compiler toolsets, choose the MSVC v141 or MSVC v140 optional components. 可以添加对 MFC、实验性模块语言扩展、IncrediBuild 等的支持。You can add support for MFC, the experimental Modules language extension, IncrediBuild, and more.

  2. 选择所需的工作负荷和可选组件后,请选择 "安装"。After you choose the workload(s) and optional components you want, choose Install.

    接下来,会出现多个显示 Visual Studio 安装进度的状态屏幕。Next, status screens appear that show the progress of your Visual Studio installation.

提示

在安装之后,可以随时安装最初未安装的工作负荷或组件。At any time after installation, you can install workloads or components that you didn't install initially. 如果已打开 Visual Studio,请转到“工具” > “获取工具和功能...”,这会打开 Visual Studio 安装程序。If you have Visual Studio open, go to Tools > Get Tools and Features... which opens the Visual Studio Installer. 或者,从“开始”菜单打开“Visual Studio 安装程序”。Or, open Visual Studio Installer from the Start menu. 在此处可以选择要安装的工作负载或组件。From there, you can choose the workloads or components that you wish to install. 然后,选择“修改”。Then, choose Modify.

第 5 步 - 选择各个组件(可选)Step 5 - Choose individual components (Optional)

如果不想使用工作负载功能来自定义 Visual Studio 安装,或者要添加比工作负荷安装更多的组件,则可以通过从 "单个组件" 选项卡中安装或添加单个组件来实现此目的。选择所需内容,然后按照提示进行操作。If you don't want to use the Workloads feature to customize your Visual Studio installation, or you want to add more components than a workload installs, you can do so by installing or adding individual components from the Individual components tab. Choose what you want, and then follow the prompts.

Visual Studio 2019-安装单个组件Visual Studio 2019 - Install individual components

第 6 步 - 安装语言包(可选)Step 6 - Install language packs (Optional)

默认情况下,安装程序首次运行时会尝试匹配操作系统语言。By default, the installer program tries to match the language of the operating system when it runs for the first time. 若要以所选语言安装 Visual Studio,请从 Visual Studio 安装程序中选择“语言包”选项卡,然后按照提示进行操作。To install Visual Studio in a language of your choosing, choose the Language packs tab from the Visual Studio Installer, and then follow the prompts.

Visual Studio 2019-安装语言包Visual Studio 2019 - Install language packs

从命令行更改安装程序语言Change the installer language from the command line

更改默认语言的另一种方法是从命令行运行安装程序。Another way that you can change the default language is by running the installer from the command line. 例如,可以通过运行以下命令来强制安装程序用英语运行:vs_installer.exe --locale en-USFor example, you can force the installer to run in English by using the following command: vs_installer.exe --locale en-US. 安装程序将在下一次运行时记住此设置。The installer will remember this setting when it's run the next time. 安装程序支持以下语言标记:zh-cn、zh-tw、cs-cz、en-us、es-es、fr-fr、de-de、it-it、ja-jp、ko-kr、pl-pl、pt-br、ru-ru 和 tr-tr。The installer supports the following language tokens: zh-cn, zh-tw, cs-cz, en-us, es-es, fr-fr, de-de, it-it, ja-jp, ko-kr, pl-pl, pt-br, ru-ru, and tr-tr.

第 7 步 - 更改安装位置(可选)Step 7 - Change the installation location (Optional)

可减少系统驱动器上 Visual Studio 的安装占用。You can reduce the installation footprint of Visual Studio on your system drive. 可以选择将下载缓存、共享组件、SDK 和工具移动到不同驱动器,并将 Visual Studio 安装在其运行速度最快的驱动器上。You can choose to move the download cache, shared components, SDKs, and tools to different drives, and keep Visual Studio on the drive that runs it the fastest.

Visual Studio 2019-更改安装位置Visual Studio 2019 - Change installation locations

重要

仅当首次安装 Visual Studio 时,才可选择其他驱动器。You can select a different drive only when you first install Visual Studio. 如果已安装 Visual Studio 并要更改驱动器,则必须先将其卸载然后再重新安装。If you've already installed it and want to change drives, you must uninstall Visual Studio and then reinstall it.

第 8 步 - 开始开发Step 8 - Start developing

  1. 在 Visual Studio 安装完成后,选择“启动”按钮,开始使用 Visual Studio 进行开发。After Visual Studio installation is complete, choose the Launch button to get started developing with Visual Studio.

  2. 在“开始”窗口上,选择“创建新项目”。On the start window, choose Create a new project.

  3. 在搜索框中,输入要创建的应用类型,查看可用模板列表。In the search box, enter the type of app you want to create to see a list of available templates. 模板列表取决于在安装期间选择的工作负载。The list of templates depends on the workload(s) that you chose during installation. 若要查看其他模板,请选择其他工作负载。To see different templates, choose different workloads.

    此外,还可使用“语言”下拉列表筛选搜索特定编程语言。You can also filter your search for a specific programming language by using the Language drop-down list. 也可使用“平台”列表和“项目类型”列表进行筛选。You can filter by using the Platform list and the Project type list, too.

  4. Visual Studio 会打开新的项目,然后便可开始编码!Visual Studio opens your new project, and you're ready to code!

Visual Studio 2017 安装Visual Studio 2017 Installation

在 Visual Studio 2017 中,可以轻松地选择并仅安装所需的功能。In Visual Studio 2017, it's easy to choose and install just the features you need. 并且由于其最小占用减小,因此其安装速度快且对系统的影响极小。And because of its reduced minimum footprint, it installs quickly and with less system impact.

先决条件Prerequisites

  • 宽带 Internet 连接。A broadband internet connection. Visual Studio 安装程序可以下载几千兆字节的数据。The Visual Studio installer can download several gigabytes of data.

  • 运行 Microsoft Windows 7 或更高版本的计算机。A computer that runs Microsoft Windows 7 or later versions. 建议使用 Windows 10 以实现最佳开发体验。We recommend Windows 10 for the best development experience. 安装 Visual Studio 前,请确保向系统应用最新更新。Make sure that the latest updates are applied to your system before you install Visual Studio.

  • 足够的可用磁盘空间。Enough free disk space. Visual Studio 至少需要 7 GB 磁盘空间,如果安装了很多常见选项,可能需要 50 GB 或更大的空间。Visual Studio requires at least 7 GB of disk space, and can take 50 GB or more if many common options are installed. 建议将其安装在 C: 驱动器上。We recommend you install it on your C: drive.

有关磁盘空间和操作系统要求的详细信息,请参阅 Visual Studio 产品系列系统要求For details on the disk space and operating system requirements, see Visual Studio Product Family System Requirements. 安装程序会报告所选选项需要多少磁盘空间。The installer reports how much disk space is required for the options you select.

Download and install

  1. 下载最新的适用于 Windows 的 Visual Studio 2017 安装程序。Download the latest Visual Studio 2017 installer for Windows.

    提示

    Community Edition 适用于个体开发者、课堂学习、学术研究和开放源代码开发。The Community edition is for individual developers, classroom learning, academic research, and open source development. 对于其他用途,请安装 Visual Studio 2017 ProfessionalVisual Studio 2017 EnterpriseFor other uses, install Visual Studio 2017 Professional or Visual Studio 2017 Enterprise.

  2. 找到你下载的安装程序文件并运行。Find the installer file you downloaded and run it. 它可能会在浏览器中显示,或者,可以在“下载”文件夹中找到它。It may be displayed in your browser, or you may find it in your Downloads folder. 安装程序需要管理员权限才能运行。The installer needs Administrator privileges to run. 可能会看到用户帐户控制对话框,要求授予安装程序对系统进行更改的权限; 请选择You may see a User Account Control dialog asking you to give permission to let the installer make changes to your system; choose Yes. 如果遇到问题,请在文件资源管理器中找到下载的文件,右键单击 "安装程序" 图标,然后从上下文菜单中选择 "以管理员身份运行"。If you're having trouble, find the downloaded file in File Explorer, right-click on the installer icon, and choose Run as Administrator from the context menu.

    下载并安装 Visual Studio 安装程序Download and install the Visual Studio Installer

  3. 安装程序提供工作负载列表,即一组用于特定开发领域的相关选项。The installer presents you with a list of workloads, which are groups of related options for specific development areas. 现在,对 C++ 的支持是可选工作负荷(默认情况下不会安装)的一部分。Support for C++ is now part of optional workloads that aren't installed by default.

    桌面开发与C++工作负荷Desktop development with C++ workload

    对于C++"",请选择 "带有C++ 工作负荷的桌面开发",然后选择 "安装"。For C++, select the Desktop development with C++ workload and then choose Install.

    安装具有C++工作负载的桌面开发Install the Desktop development with C++ workload

  4. 安装完成后,选择 "启动" 按钮以启动 Visual Studio。When the installation completes, choose the Launch button to start Visual Studio.

    首次运行 Visual Studio 时,系统会要求使用 Microsoft 帐户进行登录。The first time you run Visual Studio, you're asked to sign in with a Microsoft Account. 如果没有此类帐户,则可以免费创建一个。If you don't have one, you can create one for free. 还必须选择一个主题。You must also choose a theme. 别担心,后期可以根据需要进行更改。Don't worry, you can change it later if you want to.

    第一次运行时,Visual Studio 可能需要几分钟才能使用。It may take Visual Studio several minutes to get ready for use the first time you run it. 下面是快速延时的演示:Here's what it looks like in a quick time-lapse:

    Visual Studio 2017 登录Visual Studio 2017 sign in

    再次运行 Visual Studio 时,Visual Studio 的启动速度要快得多。Visual Studio starts much faster when you run it again.

  5. Visual Studio 打开时,检查标题栏中的标志图标是否突出显示:When Visual Studio opens, check to see if the flag icon in the title bar is highlighted:

    Visual Studio 2017 通知标志Visual Studio 2017 notification flag

    如果突出显示,请选择它以打开 "通知" 窗口。If it's highlighted, select it to open the Notifications window. 如果有任何适用于 Visual Studio 的更新,建议立即安装。If there are any updates available for Visual Studio, we recommend you install them now. 安装完成后,请重启 Visual Studio。Once the installation is complete, restart Visual Studio.

Visual Studio 2015 安装Visual Studio 2015 Installation

若要安装 Visual Studio 2015,请转到下载较旧版本的 Visual StudioTo install Visual Studio 2015, go to Download older versions of Visual Studio. 运行安装程序并选择“自定义安装”,然后选择 C++ 组件。Run the setup program and choose Custom installation and then choose the C++ component. 要向现有 Visual Studio 2015 安装添加 C++ 支持,请单击 Windows 开始按钮,然后键入添加或删除程序To add C++ support to an existing Visual Studio 2015 installation, click on the Windows Start button and type Add Remove Programs. 从结果列表中打开该程序,然后在已安装的程序列表中找到你的 Visual Studio 2015 安装。Open the program from the results list and then find your Visual Studio 2015 installation in the list of installed programs. 双击它,然后选择修改并选择要安装的 Visual C++ 组件。Double-click it, then choose Modify and select the Visual C++ components to install.

一般情况下,强烈建议使用 Visual Studio 2017,即使需要使用 Visual Studio 2015 编译器编译代码。In general, we highly recommend that you use Visual Studio 2017 even if you need to compile your code using the Visual Studio 2015 compiler. 有关详细信息,请参阅 使用 Visual Studio 中的本机多重目标生成旧项目For more information, see Use native multi-targeting in Visual Studio to build old projects.

当 Visual Studio 正在运行时,您可以继续进行下一步。When Visual Studio is running, you're ready to continue to the next step.

后续步骤Next Steps