【问题标题】:Load csproj The attribute "ExcludeAssets" in element <PackageReference> is unrecognized加载 csproj 元素 <PackageReference> 中的属性“ExcludeAssets”无法识别
【发布时间】:2020-07-09 15:46:24
【问题描述】:

使用 Microsoft.Build 组件通过 ProjectCollection.GlobalProjectCollection.LoadProject 方法加载 csproj。文档here

在其中一个引用中加载具有 PackageReference 和 ExcludeAsset 属性的 csproj,例如:

 <PackageReference Include="SomePackage" ExcludeAssets="Compile">
      <Version>1.0.0</Version>
  </PackageReference>

抛出以下异常:

元素中的“ExcludeAssets”属性无法识别。

已经尝试过不同的 ToolVersions (2.0 | 4.0 |12.0),并且两个项目都是在 .net472 中编译的

我该如何解决这个问题?

谢谢

【问题讨论】:

  • 我相信只支持 dotnet core:docs.microsoft.com/en-us/dotnet/core/tools/csproj
  • csproj 有效且编译正确。 (带有 PackageReferences 的旧 csproj 格式)所以,根据我的理解,使用 ProjectCollection.GlobalProjectCollection.LoadProject 加载它不应该抛出任何类型的异常 thks

标签: c# msbuild csproj packagereference


【解决方案1】:

我找到了与@AluanHaddad 响应相关的解决方案。正在调用 ProjectCollection.GlobalProjectCollection.LoadProject 的项目。如果它使用新的 SDK 样式,则能够加载具有 packagereferences 和 ExcludeAssets 属性的旧 csproj。

【讨论】:

    猜你喜欢
    • 2019-08-10
    • 2014-01-21
    • 1970-01-01
    • 1970-01-01
    • 2021-11-19
    • 2018-11-01
    • 2019-01-11
    • 2019-03-25
    • 2019-05-02
    相关资源
    最近更新 更多