.vcxproj 和 .props 文件结构

MSBuild 是 Visual Studio 中默认的项目系统;在 Visual C++ 中选择“文件”>“新建项目”会创建一个 MSBuild 项目,其设置存储于扩展名为 .vcxproj 的 XML 项目文件中。 项目文件还可以导入 .props 文件和 .targets 文件,这两种文件能存储设置。

如果打算在 IDE 中维护项目属性,建议仅在 IDE 中创建和修改 .vcxproj 项目,并避免手动编辑文件。 在大多数情况下,完全不需要手动编辑项目文件。 手动编辑可能会中断在 Visual Studio 属性页中修改项目设置所需的项目连接,并可能导致难以调试和修复的生成错误。

大规模地,在 IDE 中管理许多单独的项目会变得繁琐且容易出错。 很难跨数十个或数百个项目保持一致性或强制实施标准化。 在这些情况下,最好编辑项目文件,以便将自定义 .props 或 .targets 文件用于多个项目中的通用属性。 如果需要在 IDE 中无法实现的自定义项,也可以使用这些文件。 Directory.Build.props 和 Directory.Build.targets 文件是插入自定义项的好位置,这些文件会自动导入到所有基于 MSBuild 的项目中。

.vcxproj 和 .props 文件结构

.targets 文件

MSBuild 包括多个 .targets 文件,文件内容包含常见方案的项、属性、目标和任务。 这些文件将自动导入到大多数 Visual Studio 项目文件中,以便简化维护,增强可读性。

MSBuild doesn’t care about the extension–with explicit imports, you can import from any extension at any point. But there’s a widely-used convention:

  • props files are imported early in the import order.
  • targets files are imported late in the build order.

vcxproj.filters

筛选器 文件 (*.vcxproj.filters) 是位于根项目文件夹中的 MSBuild 格式的 XML 文件。 它指定哪些文件类型进入解决方案资源管理器中的逻辑文件夹。如果手动删除该过滤设置,将会使所有的头文件和代码文件在根级目录下。

日志文件夹

Common MSBuild project properties

properties

OutDir

All Indicates the final output location for the project or solution. When building a solution, OutDir can be used to gather multiple project outputs in one location. In addition, OutDir is included in AssemblySearchPaths used for resolving references. For example, bin\Debug.

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutDir>C:\Users\CNMIZHU7</OutDir>
</PropertyGroup>