配置 Linux 项目Configure a Linux Project

本主题介绍如何配置 Visual Studio Linux 项目。This topic describes how to configure a Visual Studio Linux project. 有关 CMake Linux 项目的信息,请参阅配置 Linux CMake 项目For information about CMake Linux Projects, see Configure a Linux CMake Project .

常规设置General settings

可以使用 Visual Studio 为 Linux 项目配置各种选项。A variety of options can be configured for a Linux project with Visual Studio. 若要查看这些选项,请选择“项目”>“属性”菜单,或在“解决方案资源管理器”中右键单击相应项目,然后从上下文菜单中选择“属性”。To view these options, select the Project > Properties menu, or right click on the project in Solution Explorer and select Properties from the context menu. 显示“常规”设置。The General settings appear.


默认情况下,可执行文件 (.out) 是使用该工具生成的。By default, an executable (.out) is built with the tool. 若要生成静态或动态库,或使用现有生成文件,请使用“配置类型”选项。To build a static or dynamic library, or to use an existing Makefile, use the Configuration Type selection.

远程设置Remote settings

要更改有关远程 Linux 计算机的设置,请配置“常规”设置中出现的远程选项:To change settings pertaining to the remote Linux computer, configure the remote options that appear in the General settings:

  • 要更改目标 Linux 计算机,请使用“远程生成计算机”这一项。To change the target Linux computer, use the Remote Build Machine entry. 这可以让你选择之前创建的连接之一。This will allow you to select one of the connections created previously. 若要创建新条目,请参阅连接到远程 Linux 计算机部分。To create a new entry, please see the Connecting to Your Remote Linux Computer section.

  • “远程生成根目录”确定在远程 Linux 计算机上生成项目的根位置。The Remote Build Root Directory determines the root location of where the project is built on the remote Linux computer. 除非更改,否则该位置默认为 ~/projectsThis will default to ~/projects unless changed.

  • “远程生成项目目录”是在远程 Linux 计算机上生成此特定项目的位置。The Remote Build Project Directory is where this specific project will be built on the remote Linux computer. 该位置默认为 $(RemoteRootDir)/$(ProjectName),它将扩展到以当前项目命名的目录,在上面设置的根目录下。This will default to $(RemoteRootDir)/$(ProjectName), which will expand to a directory named after the current project, under the root directory set above.


要更改默认的 C 和 C++ 编译器,或者用于生成项目的链接器和存档程序,请使用“C/C++”>“常规”部分和“链接器”>“常规”部分中的相应条目。To change the default C and C++ compilers, or the Linker and Archiver used to build the project, use the appropriate entries in the C/C++ > General section and the Linker > General section. 可以将这些条目设置为使用 GCC 的某个版本,例如甚至是使用 Clang 编译器。These could be set to use a certain version of GCC, or even the Clang compiler, for example.

VC++ 目录VC++ directories

默认情况下,Visual Studio 不包括来自 Linux 计算机的任何系统级包含文件。By default, Visual Studio does not include any system-level include files from the Linux computer. 例如,Visual Studio 中不存在 /usr/include 目录中的项。For example, items in the /usr/include directory are not present in Visual Studio. 如需完整的 IntelliSense 支持,你需要将这些文件复制到开发计算机上的某个位置,并将 Visual Studio 指向此位置。For full IntelliSense support, you will need to copy those files to some location on your development computer and point Visual Studio to this location. 一种选择是使用 scp(安全复制)来复制这些文件。One option is to use scp (Secure Copy) to copy the files. 在 Windows 10 上,你可以使用 Windows 上的 Bash 来运行 scp。On Windows 10, you can use Bash on Windows to run scp. 对于之前版本的 Windows,你可以使用类似 PSCP(PuTTY 安全复制)来操作。For previous versions of Windows, you could use something like PSCP (PuTTY Secure Copy).

可以使用类似如下命令复制文件:You can copy the files by using a command similar to the following:

scp -r linux_username@remote_host:/usr/include .

当然,也可以使用使用适合自己环境的值替换 linux_usernameremote_host 值。Of course, replace the linux_username and remote_host values above for what's appropriate in your own environment.

复制文件后,使用项目属性中的“VC++ 目录”项告诉 Visual Studio 在哪里可以找到刚复制的其他包含文件。Once the files are copied, use the VC++ Directories item in Project properties to tell Visual Studio where to find the additional include files that were just copied.

VC++ 目录

复制源Copy sources

进行生成时,将开发 PC 上的源文件复制到 Linux 计算机并在那里进行编译。When building, the source files on your development PC are copied to the Linux computer and compiled there. 默认情况下,Visual Studio 项目中的所有源文件都将复制到上述设置中设置的位置。By default, all sources in the Visual Studio project are copied to the locations set in the settings above. 但是,也可以将其他源文件添加到此列表,或完全关闭复制源文件,这是生成文件项目的默认值。However, additional sources can also be added to the list, or copying sources can be turned off entirely, which is the default for a Makefile project.

  • 要复制的源”确定将哪些源文件复制到远程计算机。Sources to copy determines which sources are copied to the remote computer. 在默认情况下,@(SourcesToCopyRemotely) 默认为项目中的所有源代码文件,但不包含任何资产/资源文件,如映像。By default, the @(SourcesToCopyRemotely) defaults to all source code files in the project, but does not include any asset/resource files, such as images.

  • 可以打开和关闭“复制源”,以启用和禁用将源文件复制到远程计算机操作。Copy sources can be turned on and off to enable and disable the copying of source files to the remote computer.

  • 要复制的其他源”允许添加将复制到远程系统的其他源文件。Additional sources to copy allows you to add additional source files which will be copied to the remote system. 可以指定以分号分隔的列表,也可以使用 := 语法指定要使用的本地和远程名称:You can specify a semi-colon delimited list, or you can use the := syntax to specify a local and remote name to use:


生成事件Build events

由于所有编译都是在远程计算机上进行的,因此,已将数个其他生成事件添加到“项目属性”中的“生成事件”部分。Since all compilation is happening on a remote computer, several additional Build Events have been added to the Build Events section in Project Properties. 它们是“远程预生成事件”、“远程预链接事件”和“远程后期生成事件”,将在此过程中的各个步骤之前或之后在远程计算机上发生。These are Remote Pre-Build Event, Remote Pre-Link Event, and Remote Post-Build Event, and will occur on the remote computer before or after the individual steps in the process.


另请参阅See Also

使用项目属性Working with Project Properties
C++ 常规属性 (Linux C++)C++ General Properties (Linux C++)
VC++ 目录 (Linux C++)VC++ Directories (Linux C++)
复制源项目属性 (Linux C++)Copy Sources Project Properties (Linux C++)
生成事件属性 (Linux C++)Build Event Properties (Linux C++)