1

i have a simple .vcxproj File which looks like this:

...
<PropertyGroup>
  <MyProjectName>sample_project</MyProjectName>
</PropertyGroup>
...
<ItemGroup>
  <ClCompile Include="..\$(MyProjectName)\*.cpp" />
</ItemGroup>
...

Visual Studio 2012 is unable to load this project and states "...vcxproj : error : Object reference not set to an instance of an object.". Running MSBuild on the command line will build the project just fine as expected, i.e. it will compile all .cpp files in ..\sample_project.

These two variants will work in Visual Studio:

<ClCompile Include="..\sample_project\*.cpp" />

<ClCompile Include="..\$(MyProjectName)\main.cpp" />

Just the combination of a wildcard and a property fails.

Is this a bug in Visual Studio, and if is there a workaround for this? I found some stuff on SO regarding getting advanced wildcards to work in MSBuild, but nothing about that a simple construct such as this - which works in MSBuild without a problem - doesn't work in Visual Studio.

Thanks in advance.

4

2 回答 2

1

在丢弃整个项目文件目录并从头开始手动重建后,结果发现 Visual Studio 有问题的文件不是 MSBuild 项目文件本身,而是 .filters 文件。似乎 Visual Studio 中的过滤无法使用这种项目列表。没有 .filters 文件将允许 Visual Studio 打开项目并且一切正常。但是提供任何类型的 .filters 文件,甚至尝试在 IDE 本身中添加过滤器都会导致错误消息,并且 Visual Studio 将拒绝使用该项目,直到过滤器文件被删除并重新启动 IDE。

这个错误有点烦人,我希望我的努力能帮助遇到同样问题的任何人。

于 2013-01-22T23:32:30.553 回答
1

尝试这个。

<PropertyGroup>
    <Sources>*.c</Sources>
</PropertyGroup>
<ItemGroup>
    <!-- This doesn't work... -->
    <!-- <ClCompile Include="$(Sources)" /> -->
    <!-- ...but this does. -->
    <ClCompile Include="$(Sources);Dummy" Exclude="Dummy" />
</ItemGroup>
于 2013-02-28T16:57:14.347 回答