9
votes

Is it possible to use ASP.NET Core 2.1 and still run on the full .NET Framework 4.7.1?

I'm currently using ASP.NET Core 2.0 on .NET 4.7.1 and i'm also using Azure Functions v1 on 4.7.1 and share Class Librarys between the Functions- and the Web Projects.

Upgrading to Azure Functions v2 to go all-in on .NET Core seems a bit too risky given the current state of Azure Functions v2 so i would prefer staying on .NET Framework for now.

1
Yes. In VS when you create a new project you can select your framework. It's possible to edit the csproj manually but it's generally easier to create a new project and copy your source across.Rory
Have you considered putting the shared classes into .NET Standard 2.0 based projects which are shareable between .NET Core 2.1 & .NET 4.7.1 based projects?Sixto Saez
@SixtoSaez i actually did but i have dependencys like entity framework core and when i wanted to scaffold a dbcontext in a .net standard 2.0 project, this failed because i have to choose a runtime in order to make the scaffolding tools work. scaffolding in another project and moving just the generated code to the .net standard project seemed like a bit of a hack to me. also i wasn't sure about the implications it would have when using document db.core in the shared class librarys and using them as well in the azure functions project. my fear is that this would have been entrance to dep hellMarkus S.
@SixtoSaez Especially the DocumentDb Dependency was the Showstopper in this Scenario because i am not able to use the DocumentDb.Core Package in an Azure Functions V1 project as they both contain the same types in the same namespaces.Markus S.
No problem, my comment was targeted more at business logic encapsulation rather than fundamental frameworks like EF and DI.Sixto Saez

1 Answers

15
votes

Yes.

The metapackages Microsoft.AspNetCore.App and Microsoft.AspNetCore.All require netcoreapp, but the they are just a collection of other packages to install.

If you install the individual packages in the metapackage, it'll work fine, just like you currently have with 2.0

Your .csproj file will end up looking similar to this...

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net471</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Antiforgery" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.1.1" />
    ...

Just notice that some packages, eg. Microsoft.AspNetCore.Http.Connections are not tagged to 2.1.1, so you need to make sure you match the versions from the metapackage constraints.