visual-studio MSBuild 错误:无法识别元素 <ProjectReference> 中的属性“Remove”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1174725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MSBuild Error: The attribute "Remove" in element <ProjectReference> is unrecognized
提问by smaglio81
I'm attempting to setup a .csproj file to have a conditional item group which will remove all of the elements in the <ProjectReference> item group.
我正在尝试将 .csproj 文件设置为具有条件项组,该组将删除 <ProjectReference> 项组中的所有元素。
For example:
例如:
<ItemGroup>
<ProjectReference Include="..\..\..\..\Projects\Registrar\Ucsb.Sa.Registrar.Common\Ucsb.Sa.Registrar.Common\Ucsb.Sa.Registrar.Common.csproj">
<Project>{1EDDDE57-0181-41B4-B2AE-FB76450F85C8}</Project>
<Name>Ucsb.Sa.Registrar.Common</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup Condition="$(OnBuildServer) == 'true'">
<ProjectReference Remove="*" />
</ItemGroup>
<ItemGroup Condition="$(OnBuildServer) == 'true'">
<Reference Include="Ucsb.Sa.Registrar.Common">
<SpecificVersion>False</SpecificVersion>
<HintPath>$(RegCommonDll)</HintPath>
</Reference>
</ItemGroup>
But, when I load the project into VS 2008, I get the error message 'The attribute "Remove" in element <ProjectReference> is unrecognized". The odd thing is that the Remove attribute is in the schema (C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas\1033\MSBuild\Microsoft.Build.Core.xsd). There is MSDN documentation on it (http://msdn.microsoft.com/en-us/library/bb651786.aspx). And, there is a comment about it at the bottom of the MSDN article titled "MSBuild Items".
但是,当我将项目加载到 VS 2008 中时,我收到错误消息“元素 <ProjectReference> 中的属性“Remove”无法识别”。奇怪的是,Remove 属性在架构中 (C:\Program Files\ Microsoft Visual Studio 9.0\Xml\Schemas\1033\MSBuild\Microsoft.Build.Core.xsd 上有 MSDN 文档(http://msdn.microsoft.com/en-us/library/bb651786.aspx)。并且,在题为“MSBuild Items”的 MSDN 文章底部有关于它的评论。
The .csproj file seems to be pointing to .NET 3.5; but I am unable to verify if that version of msbuild is being used to load the project (does anyone know how to do that?)
.csproj 文件似乎指向 .NET 3.5;但我无法验证是否正在使用该版本的 msbuild 加载项目(有人知道该怎么做吗?)
First line of .csproj file:
.csproj 文件的第一行:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
PS. I got the idea to use the conditionals from Build with msbuild and dynamically set project references
附注。我的想法是使用Build with msbuild 中的条件并动态设置项目引用
回答by Sayed Ibrahim Hashimi
You cannot use the Removeattribute with static Items. Static items are those declared outsideof targets. You can only use this attribute insideof dynamic item declarations. Dynamic item declarations are those found inside of a target. For example take a look at the following build script.
您不能对静态项目使用Remove属性。静态项目是在目标之外声明的项目。您只能在动态项目声明中使用此属性。动态项目声明是在目标内部找到的那些声明。例如,看看下面的构建脚本。
<Project ToolsVersion="3.5"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectReference Include="One.dll"/>
</ItemGroup>
<Target Name="Demo">
<ItemGroup>
<ProjectReference Remove="@(ProjectReference)"/>
</ItemGroup>
<Message Text="ProjectReference : @(ProjectReference)"/>
</Target>
</Project>
Also note that you should not use Remove="*"that will not remove everything. It will remove every file in the current directory which is contained in the ProjectReferenceitem group. If you want to clear out an item you have to do Remove="@(ProjectReference)"where ProjectReference is the item.
另请注意,您不应使用不会删除所有内容的Remove="*"。它将删除当前目录中包含在ProjectReference项组中的每个文件。如果您想清除一个项目,您必须执行Remove="@(ProjectReference)"其中 ProjectReference 是该项目。

