Home > Back-end >  WinForms project seems to depend on ASP.NET runtime for some reason
WinForms project seems to depend on ASP.NET runtime for some reason

Time:02-08

We have recently converted a large solution from .NET 4.8 to .NET 6. It consists of a few WinForms executable projects, class library projects, and unit test projects. But we are having trouble getting the executables to run on a test machine. We have installed the .NET 6 Desktop runtime on that machine, but the executables still refuse to run:

You must install missing frameworks for .NET

We discovered that after we also installed the ASP.NET Core Runtime, in addition to the desktop runtime, the error would no longer occur. This is surprising, because as far as I know we aren't using ASP.NET in our solution. The ProjectName.runtimeconfig.json file seems to contain the following:

{
  "runtimeOptions": {
    "tfm": "net6.0",
    "frameworks": [
      {
        "name": "Microsoft.NETCore.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.WindowsDesktop.App",
        "version": "6.0.0"
      },
      {
        "name": "Microsoft.AspNetCore.App",
        "version": "6.0.0"
      }
    ]
  }
}

Removing the part that mentions Microsoft.AspNetCore.App makes it possible to run the executable on the test machine without the ASP.NET Core Runtime. But why is it even mentioned in that file?

What is going on here? Could it be that our project really requires ASP.NET in some way, maybe because of some NuGet package we are using? If so, how can we find out where that dependency comes from? Ideally our application should only depend on the .NET 6 Desktop Runtime.

CodePudding user response:

A collegue of mine found the problem.

The following was present in multiple project files:

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

Removing those fixed the problem.

According to the git log, that piece of text appears to have been generated by the conversion tool (Upgrade Assistant) for some reason.

  •  Tags:  
  • Related