4

We have existing libraries that depend on MVC, for example to provide custom action filters. These libraries are published as Nuget.

Until now, we just referenced Microsoft.AspNetCore.Mvc from the library, so that we could use the respective types (such as ActionFilterAttribute). But starting with ASP.NET Core 3, Microsoft stopped publishing many Nuget packages as indicated by the upgrade guide, among them Microsoft.AspNetCore.Mvc.

How should libraries that depend on MVC reference MVC, starting with ASP.NET Core 3?

2 Answers 2

3

This is outlined in section library multi-targeting in the upgrade guide:

The library must target both .NET Core 3 and .NET Standard 2.0, and use conditionals to either use a PackageReference or FrameworkReference:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.0;netstandard2.0</TargetFrameworks>
  </PropertyGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

  <ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.2" />
  </ItemGroup>
</Project>
Sign up to request clarification or add additional context in comments.

1 Comment

1

According to the documentation in the link you provided, you can either target the Microsoft.NET.Sdk.Web SDK which will reference Microsoft.AspNetCore.App shared framework implicitly:

Projects that target the Microsoft.NET.Sdk.Web SDK implicitly reference the Microsoft.AspNetCore.App framework.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>
    ...
</Project>

Or explicitly for other SDKs:

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.Razor">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

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

Are there certain libraries that you depended on that aren't included in the Microsoft.AspNetCore.App shared framework?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.