介绍
在我们的项目中,Visual Studio C++ 被用作代码编辑器,而构建被委托给支持多个目标平台的基于 GNU make 的构建系统。从 Visual Studio 到构建系统的构建委托由通用 MSBuild 属性表实现,该属性表包含在每个 VS 项目文件中。(集成基本上是通过设置一些特定于 NMake 的属性来实现的,例如NMakeBuildCommandLine
等)。通用集成属性表的附加工作是将特定于项目的资源文件动态添加到解决方案资源管理器中的项目子树。
多年来,在 Visual Studio 2010 和 Visual Studio 2012 中,动态添加特定于项目的资源文件一直运行良好。不幸的是,该功能在 Visual Studio 2013 中已停止工作。
最初设定
以下精简示例演示了该问题。我们的最小设置包含以下 5 个文件:
minimal_sample.sln
:解决方案文件,由 VS 2010 创建,Release|Win32
删除了对项目配置的引用(单击此处查看代码清单)minimal_sample.vcxproj
: 项目文件,详细说明见下文(点击这里查看代码清单)statically_included_header.h
: 最小示例 C++ 头文件(内容无关)statically_included_impl.cpp
: 最小示例 C++ impl 文件(内容无关)text_file.txt
: 最小示例资源文件(内容无关)
项目minimal_sample.vcxproj
文件被创建为一个空的 VS C++ 2010 项目,之后对其应用了以下修改:
- 配置
Release|Win32
已删除 Start of static file inclusion code
静态包含的文件是使用 VS 2010 添加的(由和End of static file inclusion code
XML 注释分隔的部分 )- 添加了负责添加动态资源文件的 MSBuild 代码部分(由
Start of dynamic file inclusion code
和End of dynamic file inclusion code
XML 注释分隔的部分)
以下代码清单显示了minimal_sample.vcxproj
文件的相关部分:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Project file parts left out for brevity -->
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
<!-- Start of dynamic file inclusion code -->
<PropertyGroup>
<TxtFile Condition="'$(TxtFile)'==''">text_file.txt</TxtFile>
</PropertyGroup>
<ItemGroup Condition="'$(TxtFile)'!='' and exists('$(TxtFile)')">
<None Include="$(TxtFile)"/>
</ItemGroup>
<!-- End of dynamic file inclusion code -->
<PropertyGroup Label="UserMacros" />
<!-- Project file parts left out for brevity -->
<!-- Start of static file inclusion code -->
<ItemGroup>
<ClCompile Include="statically_included_header.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="statically_included_impl.cpp" />
</ItemGroup>
<!-- End of static file inclusion code -->
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
手动复制步骤
只要不使用过滤器,上述最小示例在本文中提到的任何 Visual Studio 版本中都可以正常工作,即:VS 2010、VS 2012 和 VS 2013。
一旦添加了过滤器minimal_sample.vcxproj
- 无论是空过滤器、静态包含文件的过滤器还是动态包含的资源文件text_file.txt
- 重新启动后(或之后),动态包含的资源文件都会隐藏在 Visual Studio 2013 中卸载项目/重新加载项目序列)。但是,该文件在 Visual Studio 2010 和 Visual Studio 2012 中仍然可见。
一旦minimal_sample.vcxproj.filters
文件被删除,过滤器就会被删除,但动态包含的资源文件text_file.txt
会再次可见。
问题
- 观察到的 VS 2010/2012 和 VS 2013 的行为差异是错误还是“功能”?甚至是执行不力的错误修复?
- 对于动态包含的文件,是否有让 VS 2013 表现为 VS 2010/2012 的解决方法?