skip to Main Content

I have an existing dotnet core 3.1 web app that builds and deploys to an azure app service. it works fine. I am trying to containerize the app.

the build is fine, but when the container runs it gives me

It was not possible to find any compatible framework version
The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' (x64) was not found.
  - No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.

my docker

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /source

# copy csproj and restore as distinct layers
COPY myreports/*.csproj .

RUN dotnet restore

# copy and publish app and libraries
COPY . .
RUN dotnet publish -c release -o /app

# final stage/image
FROM mcr.microsoft.com/dotnet/runtime:6.0
WORKDIR /app
COPY --from=build /app .
ENTRYPOINT ["dotnet", "myreports.dll"]

I’ve tried a variety of docker images(inc dotnet/core) and its the same.
my csproj

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <RootNamespace>myreports</RootNamespace>
    <UserSecretsId>ed68b972-ed89-4115-8e6c-5f0d032efa4d</UserSecretsId>
    <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
    <PackageReference Include="FastReport.Core3.Web" Version="2021.3.0" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.16.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.16.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.PerfCounterCollector" Version="2.16.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="3.1.9" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.9">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <!--PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.14.0" /-->
    <PackageReference Include="Microsoft.AspNetCore.AzureAppServices.HostingStartup" Version="3.1.9" />
    <PackageReference Include="Microsoft.Azure.EventGrid" Version="3.0.0" />
    <PackageReference Include="Microsoft.Azure.Management.ResourceManager" Version="1.6.0-preview" />
    <PackageReference Include="Microsoft.IdentityModel.Clients.ActiveDirectory" Version="4.5.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.14.0" />
  </ItemGroup>
</Project>

I suspect its this
<PackageReference Include="FastReport.Core3.Web" Version="2021.3.0" />

But its required as its core to the project. What gets me is that my config in the (working) app settings is:
enter image description here

4

Answers


  1. Chosen as BEST ANSWER

    I believe I was able to resolve this by changing the final image to :

    FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019
    

  2. Your project is targeting .NET Core 3.1 but your Dockerfile is referencing 6.0 tags, which refers to .NET 6. A .NET Core 3.1 app won’t be able to run in a 6.0 runtime container. You should update your Dockerfile to reference 3.1 instead of 6.0.

    Update

    Since there’s also a dependency on the Microsoft.WindowsDesktop.App framework, you’ll need to manually add that framework into the runtime. By default, the runtime image only contains the Microsoft.NETCore.App.

    However, the sdk image does contain the Microsoft.WindowsDesktop.App framework. This allows you to use an sdk container to build a project that has a Microsoft.WindowsDesktop.App framework dependency. You just can’t run, by default, in the runtime container because it’s very atypical to run an app in a container that has such a dependency.

    What this all means is that you can copy the Microsoft.WindowsDesktop.App framework from the sdk to the runtime container which should resolve your issue. I’ve updated your Dockerfile to include COPY instruction which does this:

    FROM mcr.microsoft.com/dotnet/sdk:3.1 AS build
    WORKDIR /source
    
    # copy csproj and restore as distinct layers
    COPY myreports/*.csproj .
    
    RUN dotnet restore
    
    # copy and publish app and libraries
    COPY . .
    RUN dotnet publish -c release -o /app
    
    # final stage/image
    FROM mcr.microsoft.com/dotnet/runtime:3.1
    COPY --from=build ["C:/Program Files/dotnet/shared/Microsoft.WindowsDesktop.App", "C:/Program Files/dotnet/shared/Microsoft.WindowsDesktop.App/"]
    WORKDIR /app
    COPY --from=build /app .
    ENTRYPOINT ["dotnet", "myreports.dll"]
    
    Login or Signup to reply.
  3. As the package name indicates it is a windows dependant component. Try running your application on a windows container not linux.

    Login or Signup to reply.
  4. Following your answer on changing the image to mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2019

    If you did not change your csproj you now have a .NET Core 3.1 app running on .NET 4.8. This could lead to subtle runtime problems. (citation needed)

    I would strongly suggest upgrading your csproj to .NET 6 since .NET 3.1 is running out of support in some months anyways.

    I might be mistaken but the first step would be to change <TargetFramework>netcoreapp3.1</TargetFramework> to <TargetFramework>net6.0</TargetFramework> and of course follow an upgrade guide online https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-60?view=aspnetcore-6.0&tabs=visual-studio

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search