sdk: 'ProjectReference' not working properly in a multi-target project

Hi all, I’m working on a test project that has multiple targets netcoreapp3.1, net5.0, and net6.0.

  • For the targets netcoreapp3.1 and net5.0, the test project needs to reference to NuGet packages Microsoft.PowerShell.SDK version 7.0.6 (targeting 3.1) and 7.1.3 (targeting 5.0) respectively.
  • For the target net6.0, the test project needs to reference the library project Microsoft.PowerShell.SDK.csproj, which lives in the same repo.

So the .csproj file for the test project looks like this (see the the complete version of this file here, in my temp branch):

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>
  <PropertyGroup>
    <!-- other properties -->
    <OutputType>Exe</OutputType>
    <TargetFrameworks>netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
    <ProjectReference Include="../../../src/Microsoft.PowerShell.SDK/Microsoft.PowerShell.SDK.csproj" />
    <ProjectReference Include="../../../src/Microsoft.PowerShell.Commands.Diagnostics/Microsoft.PowerShell.Commands.Diagnostics.csproj" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.1.3" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.6" />
  </ItemGroup>
</Project>

It looks simple, but dotnet restore fails with the following errors:

error NU1201: Project Microsoft.PowerShell.Commands.Diagnostics is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).
    Project Microsoft.PowerShell.Commands.Diagnostics supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project Microsoft.PowerShell.Commands.Management is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1)
    Project Microsoft.PowerShell.Commands.Management supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project Microsoft.PowerShell.Commands.Utility is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).
    Project Microsoft.PowerShell.Commands.Utility supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project Microsoft.PowerShell.ConsoleHost is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).
    Project Microsoft.PowerShell.ConsoleHost supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project Microsoft.PowerShell.Security is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).
    Project Microsoft.PowerShell.Security supports: net6.0 (.NETCoreApp,Version=v6.0)
error NU1201: Project System.Management.Automation is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1).
    Project System.Management.Automation supports: net6.0 (.NETCoreApp,Version=v6.0)

======= Same errors repeated for net5.0 ========

(NOTE: the projects Microsoft.PowerShell.Commands.Management, Microsoft.PowerShell.Commands.Utility, and etc are dependencies of Microsoft.PowerShell.SDK.csproj, and they are all targeting net6.0 currently)

The ProjectReference to Microsoft.PowerShell.SDK.csproj and Microsoft.PowerShell.Commands.Diagnostics.csproj are grouped in a ItemGroup with the condition "'$(TargetFramework)' == 'net6.0'", so why was dotnet restore checking compatibility for those project references with netcoreapp3.1 and net5.0? Can someone please suggest how to make this work?

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 1
  • Comments: 15 (4 by maintainers)

Most upvoted comments

Here’s my scenario: Class library is targeting:

<TargetFrameworks>netstandard2.0;xamarinios10;monoandroid6.0;net6.0;net6.0-ios13.0;net6.0-android31.0;net461;uap10.0.18362;$net6.0-windows10.0.19041</TargetFrameworks>

I have a UWP class library project with a project reference to the above, and I’ll get warnings like this:

NU1201: Project MyUWPClassLibraryProject is not compatible with monoandroid10.0 (MonoAndroid,Version=v10.0). Project MyUWPClassLibraryProject supports uap10.0.18362 (UAP,Version=v10.0.18362)
NU1201: Project MyUWPClassLibraryProject is not compatible with xamarinios10 (Xamarin.iOS,Version=1.0) / win. Project MyUWPClassLibraryProject supports uap10.0.18362 (UAP,Version=v10.0.18362)
NU1201: Project MyUWPClassLibraryProject is not compatible with xamarinios10 (Xamarin.iOS,Version=1.0) / win-x64. Project MyUWPClassLibraryProject supports uap10.0.18362 (UAP,Version=v10.0.18362)
NU1201: Project MyUWPClassLibraryProject is not compatible with xamarinios10 (Xamarin.iOS,Version=1.0) / win-x86. Project MyUWPClassLibraryProject supports uap10.0.18362 (UAP,Version=v10.0.18362)

All projects use the SDK-style project types.