Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
368 views
in Technique[技术] by (71.8m points)

c# - How can a .Net 5 Visual Studio Project / Solution that reference a .Net Core 3.1 NuGet package compile successfuly?

Right to the point:

How can my Visual Studio Solution / Project written in .Net 5 successfully compile and run when it references a .Net Core 3.1 NuGet Package?

More Detail

I had a Visual Studio solution with multiple projects. All written in .Net Core 3.1 with the target framework of netcoreapp3.1. See below.

<TargetFramework>netcoreapp3.1</TargetFramework>

I upgraded all of the project to .Net 5, with a target framework of net5.0 See below.

 <TargetFramework>net5.0</TargetFramework>

I had to upgrade all of them, even the ones that only have POCO classes. If not, the solution would not compile, which makes sense to me.

My Solution references 2 NuGet packages. Written by another developer in my company. Who is not with us anymore.

One of the packages is written in .Net Standard. I complete understand why I have no problems with that package. It uses the below target framework.

<TargetFramework>netstandard2.1</TargetFramework>

However, the other package is uses target framework netcoreapp3.1. (I have access to the source code.)

My solution complies and runs fine locally. I don't understand how this is possible.

Why did I have to upgrade all of my project within my solutions to .Net 5. But, the package did not have to be upgraded. I was all prepared to upgrade it.

Was it packaged a special way?

Any inside would be helpful.

I am just trying to understand this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should note that NET5.0 is a new release of Net Core Sdk rather than the traditional Net Framework. See this similar issue and this official document.

That upgrade your project from Net Core 3.1 into Net5.0 is an upgrade of the same type of SDK version.

And the higher version of the Net Core sdk is compatible with the lower version of the sdk. So you do not have to worry about upgrading the nuget packages of Net Core 3.1.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...