.net - MSBuild 错误 : The attribute "Remove" in element <ProjectReference> is unrecognized

标签 .net visual-studio visual-studio-2008 msbuild

我正在尝试将 .csproj 文件设置为具有条件项组,该组将删除 项组中的所有元素。

例如:

<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>

但是,当我将项目加载到 VS 2008 中时,我收到错误消息“元素 中的属性“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)。而且,在 MSDN 文章的底部有关于它的评论,标题为“MSBuild 项目”。

.csproj 文件似乎指向 .NET 3.5;但我无法验证是否正在使用该版本的 msbuild 加载项目(有人知道该怎么做吗?)

.csproj 文件的第一行:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

附注。我得到了使用来自 Build with msbuild and dynamically set project references 的条件的想法

最佳答案

您不能使用 删除 具有静态项目的属性。静态项目是声明的项目 外面的目标。您只能使用此属性 动态项目声明。动态项目声明是在目标内部找到的那些声明。例如,看看下面的构建脚本。

<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>

另请注意,您不应该使用 删除="*"这不会删除所有内容。它将删除当前目录中包含在 中的所有文件。项目引用项组。如果你想清除一个项目,你必须做删除="@(ProjectReference)"其中 ProjectReference 是项目。

关于.net - MSBuild 错误 : The attribute "Remove" in element <ProjectReference> is unrecognized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1174725/

相关文章:

javascript - 无法让 ng-hide 和 ng-show 工作

visual-studio - Xamarin Forms Google 抽屉导航

visual-studio-2008 - 如何在 Visual Studio 2008 中对 F# 代码进行单元测试?

visual-studio - Visual Studio 升级建议 2008/2010

c++ - WaitForSingleObject 不会超时 - C++

c# - 为什么 DataContractJsonSerializer 会跳过某些属性的反序列化?

c# - 关于日期格式的问题 - 16 :15 to 16:00

.net - 关于 Powershell 中的作用域

visual-studio - 为什么我的 Visual Studio 2019 Community 版本的开始菜单下没有“远程计算机”选项

c# - 使用 .NET 反射自克隆可执行文件