Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a NuGet package built with a newer version of c# be used in a project using an older version of c#?

If I build and publish a NuGet package with a Language Version of 9, can I install and reference the NuGet package in a project using a lower Language version (for example c# 7)?

NuGet Package .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>9</LangVersion>
  </PropertyGroup>
</Project>

Consuming library .csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>7.3</LangVersion>
  </PropertyGroup>
</Project>
like image 462
chris31389 Avatar asked Dec 19 '25 12:12

chris31389


1 Answers

This is possible.

So after a suggestion from @ADyson I tried to do this myself locally.

It took me about 30 minutes to build a .netstandard2.0 project with a reference to IAsyncEnumerable with the Microsoft.Bcl.AsyncInterfaces 5.0.0 NuGet package as it doesn't natively get included in .netstardard2.0.

After packing up a NuGet locally, I included it into a Console Application using .netcore2.1 and called a method that used the IAsyncEnumerable. It worked!

like image 169
chris31389 Avatar answered Dec 22 '25 04:12

chris31389



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!