Search code examples
c#asp.netframeworks

How to tell which frameworks are required in ASP.NET Core project?


I have an ASP.NET Core 7.0 web project (C#) that I publish to an Azure App Service. It has been working fine, until a bad surprise happened.

I published the project, and it I was greeted with this error:

App: C:\home\site\wwwroot\MySuper.dll
Architecture: x86
Framework: 'Microsoft.WindowsDesktop.App', version '7.0.0' (x86)
.NET location: C:\Program Files (x86)\dotnet\

No frameworks were found.

Learn more:
https://aka.ms/dotnet/app-launch-failed

To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=7.0.0&arch=x86&rid=win-x86&os=win10
You must install or update .NET to run this application.

Now, this caused a bit of panic which I would prefer not to repeat. I ended up fixing the problem by restoring from the backup and have not published since this mistake. Of course, this means new code is not getting deployed to production.

So, before I publish the website again, I would like to be extremely sure that I know which framework(s) will be required.

By the way, I believe the problem was that another dev on the project had added EntityFramework, which it seems depends on 'Microsoft.WindowsDesktop.App', so the WindowsDesktop.App framework was added incidentally (but still blew up my app just the same).

I assume the necessary frameworks are stored somewhere in some file in the project folder. However, which file and where is it?


Solution

  • After digging around, it seems like the information is in the file [projectname].runtimeconfig.json.

    This file is under the [projectname]\bin\release

    I see the old one looked like this:

    {
      "runtimeOptions": {
        "tfm": "net7.0",
        "includedFrameworks": [
          {
            "name": "Microsoft.NETCore.App",
            "version": "7.0.16"
          },
          {
            "name": "Microsoft.WindowsDesktop.App",
            "version": "7.0.16"
          },
          {
            "name": "Microsoft.AspNetCore.App",
            "version": "7.0.16"
          }
        ],
        "configProperties": {
          "System.GC.Server": true,
          "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
          "System.Reflection.NullabilityInfoContext.IsSupported": true,
          "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
        }
      }
    }
    

    Once I removed a few dependencies it now looks like this.

    {
      "runtimeOptions": {
        "tfm": "net7.0",
        "frameworks": [
          {
            "name": "Microsoft.NETCore.App",
            "version": "7.0.0"
          },
          {
            "name": "Microsoft.AspNetCore.App",
            "version": "7.0.0"
          }
        ],
        "configProperties": {
          "System.GC.Server": true,
          "System.Reflection.Metadata.MetadataUpdater.IsSupported": false,
          "System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
        }
      }
    }
    

    Most importantly, I could deploy without it saying I needed the Microsoft.WindowsDesktop.App framework installed on the server.