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.

Unable to reference Net5.0 C# project from Net5.0 C++ project

See original GitHub issue

I have C# library which is targeting net5.0. This is referenced by a C++ project where the TargetFrameworkVersion property is set to "5.0*. Unfortunately this results in this error

2>C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1806,5): error : Project '..\cslib\cslib.csproj' targets 'net5.0'. It cannot be referenced by a project that targets '.NETFramework,Version=v5.0'.

This occurs regardless of whether PlatformToolset is at v142 or v143 (VS2020 preview)

Is there a workaround for this or do we just have to wait for the tools to catch up?

(I appreciate this may be considered an issue with the C++ build chain rather than the dotnet sdk - happy to raise elsewhere if you can point me to somewhere more appropriate.)

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
KalleOlaviNiemitalocommented, Aug 24, 2021

If you want to target .NET 5 and set <TargetFrameworkVersion>5.0</TargetFrameworkVersion>, I think you need to set <TargetFrameworkIdentifier>.NETCoreApp</TargetFrameworkIdentifier> as well. This is what Microsoft.NET.TargetFrameworkInference.targets would infer from <TargetFramework>net5.0</TargetFramework>. I don’t know whether the C++/CLI or C++/CX build system supports that, though.

0reactions
NeilMacMullencommented, Aug 26, 2021

Closing this because I think the capability is supported albeit not very discoverable. Have raised a VS issue suggesting some discoverability improvements at https://developercommunity.visualstudio.com/t/net50-c-project-cannot-reference-net50-c-project/1511480

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot add .NET 5 source code as a project reference
It seems as though the current version of ASP.NET Core source code in Github is version net6.0, and the current version available in...
Read more >
Unable to reference project in test project: net5.0-windows / ...
Unable to reference project in test project: net5.0-windows / .NETCoreApp,Version=v5.0 conflict. I create a new project UnitTestingPractice ...
Read more >
Troubleshoot .NET Framework targeting errors
This article provides resolutions for MSBuild errors that might occur because of reference issues.
Read more >
MSB3644: The reference assemblies for 'version' were not ...
This error occurs when the .NET reference assemblies aren't found for the version of .NET that a project requests. Check that your project...
Read more >
Test Explorer fails to execute any tests under netcore3.1 ...
I have a unit test project that is multi-targeted (net461;netcoreapp3.1;net5.0-windows). This project references Microsoft.NET.Test.Sdk version 16.5.0 for ...
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