1

Using Microsoft.Build component to load a csproj using method ProjectCollection.GlobalProjectCollection.LoadProject. Documentation here.

Loading a csproj with PackageReference and ExcludeAsset attribute in one of the references, example:

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

The following exception is thrown:

The attribute "ExcludeAssets" in element is unrecognized.

Already tried different ToolVersions (2.0 | 4.0 |12.0), and both of the projects are compiled in .net472

How can I fix this?

Thanks

  • 1
    I believe that is only supported for dotnet core: https://learn.microsoft.com/en-us/dotnet/core/tools/csproj – Aluan Haddad Jul 09 '20 at 16:00
  • the csproj is valid and compiles properly. (old csproj format with PackageReferences) so, on my understanding using ProjectCollection.GlobalProjectCollection.LoadProject to load it should not throw any kind of exception thks – Ricardo Rocha Jul 10 '20 at 10:53

1 Answers1

1

I found a solution that is related to @AluanHaddad response. The project that is calling ProjectCollection.GlobalProjectCollection.LoadProject. if it uses the new SDK style, is able to load an older csproj with packagereferences and ExcludeAssets attribute.