Aspnetcore.docs: Help Migrating .NET Standard 2.0 Class Library From ASP.NET Core 2.2 To ASP.NET Core 3.0

Created on 24 Oct 2019  Â·  8Comments  Â·  Source: dotnet/AspNetCore.Docs

While it is helpful that this migration document lists all of the ASP.NET Core 2.2 nuget packages that no longer exist in ASP.NET Core 3.0, it would be much more helpful to also note where in ASP.NET Core 3.0 the references have been moved to.

For Example:
I have a netstandard2.0 class library that currently has a reference to
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
as it uses several built in types such as ServiceFilterAttribute, AuthorizeAttribute, AuthorizationPolicyBuilder, etc. From the migration document, I know that the Microsoft.AspNetCore.Mvc.Core package does not exist in ASP.NET Core 3.0; however, I'm left clueless as to what ASP.NET Core 3.0 package I now need to reference to continue using the types that were exposed in the ASP.NET Core 2.2 package.

Could the document please be updated with guidance on how to migrate an existing netstadard2.0 class library that currently references ASP.NET Core 2.2 packages to ASP.NET Core 3.0? Or at the very least update the list of removed ASP.NET Core 2.2 packages to reflect their new location in ASP.NET Core 3.0?


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Source - Docs.ms doc-enhancement

Most helpful comment

Rubber :duck: thus far says that you'll have to use the netcoreapp TFM in order for the framework references to resolve those assemblies from the shared framework. Stand-by for a bit ... time zones are at play ... I'm east coast, but many are out west. 🤠

All 8 comments

Hello @ideoclickVanessa ... Try making them framework references. See the last section (Reducing the duplication between NuGet packages and shared frameworks) of the announcement ...

https://github.com/aspnet/Announcements/issues/325

... and they have some linked discussion/cross-references that should shed additional light.

I agree that it would be nice to clarify this in the topic.

shed additional light

... but unfortunately https://github.com/aspnet/AspNetCore/issues/3757 is closed for further discussion.

For perhaps more info and a chance to ask questions 🤞 until the docs team gets to this issue, try searching the engineering repo (open and closed issues). I have a feeling that there are some threads there discussing this scenario.

https://github.com/aspnet/AspNetCore/issues

EDIT ... yes ... try it the way it appears in the topic and you should get those namespaces you're looking for ...

Projects that target Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor SDK, should add an explicit FrameworkReference to Microsoft.AspNetCore.App:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#framework-reference

Hi @guardrex,

My project file looks like this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>

    <Product>MyProduct</Product>
    <Version Condition="'$(BUILD_BUILDNUMBER)' != ''">$(BUILD_BUILDNUMBER)</Version>

    <AssemblyName>MyProduct.Core</AssemblyName>
    <RootNamespace>MyProduct.Core</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
  </ItemGroup>

</Project>

Re-reading the Framework reference section (https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.0&tabs=visual-studio#framework-reference), I am now less confused. The first time through, I missed the fact that this verbal call out

Projects that target Microsoft.NET.Sdk or Microsoft.NET.Sdk.Razor SDK, should add an explicit FrameworkReference to Microsoft.AspNetCore.App:

included Microsoft.NET.Sdk most likely due to the code sample only being for the Microsoft.NET.Sdk.Razor.

To verify that I correctly understand, I would update my above project file to this in order to move the .NET Standard library from ASP.NET Core 2.2 support to ASP.NET Core 3.0 support:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <LangVersion>latest</LangVersion>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <NoWarn>$(NoWarn);1591</NoWarn>

    <Product>MyProduct</Product>
    <Version Condition="'$(BUILD_BUILDNUMBER)' != ''">$(BUILD_BUILDNUMBER)</Version>

    <AssemblyName>MyProduct.Core</AssemblyName>
    <RootNamespace>MyProduct.Core</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

</Project>

Do I also need to update <TargetFramework>netstandard2.0</TargetFramework> to <TargetFramework>netstandard2.1</TargetFramework>?

Let's hold this open for a sec ... Rick should look. I build so few libs here that I need help, too, with the change for libs. I build just about 100% apps.

They seem to want netcoreapp3.0 for the TFM. When I created a new class lib for 3.0 in VS, that's what the template gave me.

Take a look at the reference source for a 3.0 Razor class lib ...

<TargetFramework Condition="'$(SupportPagesAndViews)' == 'True'">
    netcoreapp3.0
</TargetFramework>
<TargetFramework Condition="'$(SupportPagesAndViews)' != 'True'">
    netstandard2.0
</TargetFramework>

https://github.com/aspnet/AspNetCore/blob/release/3.0/src/ProjectTemplates/Web.ProjectTemplates/RazorClassLibrary-CSharp.csproj.in

... so if it supports pages+views, they go netcoreapp3.0 ... I think that's the way it goes these days for what you're doing.

I'll let Rick comment further and close. There might be work to do here ... additional explanation perhaps that would help in the topic explaining it out a bit more.

Thanks for reopening. I work mostly on REST APIs so I have no use for Razor (Pages and Views); however, I do build sharable filters, controllers, etc. in class libraries that I would prefer stayed targeting .NET Standard rather than ASP.NET Core.

Rubber :duck: thus far says that you'll have to use the netcoreapp TFM in order for the framework references to resolve those assemblies from the shared framework. Stand-by for a bit ... time zones are at play ... I'm east coast, but many are out west. 🤠

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Rick-Anderson picture Rick-Anderson  Â·  3Comments

AnthonyMastrean picture AnthonyMastrean  Â·  3Comments

serpent5 picture serpent5  Â·  3Comments

YeyoCoder picture YeyoCoder  Â·  3Comments

danroth27 picture danroth27  Â·  3Comments