question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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?

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
dotMortencommented, Feb 9, 2022

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.

0reactions
troygeigercommented, Nov 9, 2022

I’m having a similar issue with referencing a multi-target project. The work around mentioned above worked for me.

It might be possible to work around the check by adding SetTargetFramework="TargetFramework=net6.0" metadata to the ProjectReference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

.net - Target Framework Resolution Behavior for Multi- ...
NU1702 | ProjectReference 'C:\source\SolutionDir\MultiTargetProject\MultiTargetProject.csproj' was resolved using '.NETFramework,Version=v4.8' ...
Read more >
Multi-target project won't load the right packages
Hi, I have a multi-targeting project with the following csproj content: <Project Sdk="Microsoft.NET.
Read more >
Multitargeted project reference not working correctly in ...
I have a .NET Core 2.0 class library which references another class library, that is multitargeted .net 4.5 and .net standard 2.0.
Read more >
Multi-targetting .Net Framework and .Net Core in a single project
Put a <PackageReference /> for each target in the respective conditional section. It's possible that you have a dependency on something that isn...
Read more >
Non-Trivial Multi-Targeting with .NET | by Brad Robinson
The first thing you'll quickly realise about setting up a project like this is you'll be working directly with the csproj files. Forget...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found