Search code examples
.net-core.net-5.net-6.0

Building a net5.0 targeted app which can run on net6.0 runtime


I previously thought the net6.0 runtime was backwards compatible in that net5.0 apps would just run as-is, but that isn't what I'm seeing in testing. My development system is using VS2019, so it does not support the net6.0 SDK. I have tried to manually convert the TargetFramework tag to TargetFrameworks and add net5.0;net6.0, but it won't build. I would love some kind of net5.0+ tag which indicates 5 or later, but I can't find that either.

But why doesn't TargetFramework set to net5.0 work when deployed to a system with only the net6.0 runtime? Let's say my app was built before net6.0 existed. I wouldn't want to have to issue a new package when net6.0 was released. Would this require the customer to keep net5.0 installed indefinitely to keep supporting my app?

I feel like I'm missing something simple, but after several hours of reading I'm not any closer to figuring it out.


Solution

  • I think I have finally figured this out. Adding a RollForward to the .csproj seems to be the necessary ingredient:

      <PropertyGroup>
        <TargetFramework>net5.0</TargetFramework>
        <RollForward>Major</RollForward>
      </PropertyGroup>
    

    I had previously tried adding RollForward to an app.runtimeconfig.json file but that didn't seem to have any effect. I'm wondering if in my case, where I'm doing a "single file" framework dependent published exe, if it perhaps doesn't look at those runtimeconfig files at all. Not sure there, but at least I have a solution now. I have only the 6.0.2 runtime installed on a test machine and it is allowing the net5.0 built binary to run.