chris31389
chris31389

Reputation: 9356

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>

Upvotes: 3

Views: 869

Answers (1)

chris31389
chris31389

Reputation: 9356

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!

Upvotes: 4

Related Questions