Docker - dotnet no framework found - docker

Trying to run a dotnet core based docker container on a windows 2022 server that's setup with WSL2 (Ubuntu). Running the container fails with the below error message indicating I don't have any dotnet frameworks installed...
You must install or update .NET to run this application.
App: /app/TodoApi.dll
Architecture: x64
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet/
No frameworks were found.
https://aka.ms/dotnet/app-launch-failed
To install missing framework, download:
https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=6.0.0&arch=x64&rid=debian.11-x64
Running dotnet --info I can see I have version sdk - 6.0.400, runtime - 6.0.8
azureuser#myworkstation01:/mnt/c/Users/azureuser$ dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.400
Commit: 7771abd614
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/6.0.400/
global.json file:
Not found
Host:
Version: 6.0.8
Architecture: x64
Commit: 55fb7ef977
.NET SDKs installed:
6.0.400 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.0 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Checking in $PATH, i can see there is an environment variable for dotnet already...
azureuser#myworkstation01:/mnt/c/Users/azureuser$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/mnt/c/Windows/system32:/mnt/c/Windows:/mnt/c/Windows/System32/Wbem:/mnt/c/Windows/System32/WindowsPowerShell/v1.0/:/mnt/c/Windows/System32/OpenSSH/:/mnt/c/Program Files/dotnet/:/mnt/c/Program Files (x86)/dotnet/:/mnt/c/Program Files/Docker/Docker/resources/bin:/mnt/c/ProgramData/DockerDesktop/version-bin:/mnt/c/ProgramData/chocolatey/bin:/mnt/c/Program Files/PowerShell/7/:/mnt/c/Users/azureuser/AppData/Local/Microsoft/WindowsApps:/mnt/c/Users/azureuser/AppData/Local/Programs/Microsoft VS Code/bin:/mnt/c/Users/azureuser/.dotnet/tools:/snap/bin:/home/azureuser/.dotnet/tools
I am using WSL2, I can see Docker is configured to use Ubuntu distro in the WSL integration.
I've config RollForward to LatestMajor in my dotnet core project property...
Is there anything obvious I am missing?

I upgraded ubuntu and had the same problem.
Try uninstalling dotnet and specifying the version you want to install.
Github Reference
$ sudo apt install aspnetcore-runtime-6.0=6.0.8-1 dotnet-apphost-pack-6.0=6.0.8-1 dotnet-host=6.0.8-1 dotnet-hostfxr-6.0=6.0.8-1 dotnet-runtime-6.0=6.0.8-1 dotnet-sdk-6.0=6.0.400-1 dotnet-targeting-pack-6.0=6.0.8-1

The WSL2 led me down a rabbithole. The issue was in the docker file itself, my baseimage didn't have the right aspnet core framework. This has been resolved using the following stackoverflow answer - The framework 'Microsoft.AspNetCore.App', version '6.0.0' (x64) was not found
Check for Project tag of .csproj file. If it's Sdk attribute is set to Microsoft.NET.Sdk.Web then this would be a reason for ASP.NET Core runtime requirement. Also check for libraries referencing Microsoft.AspNetCore.App.

Related

How can I target multiple .NET Core versions from a single Docker image?

I have a library that targets .NET Standard 2.0. To verify compatibility, I would like to run my unit tests with the current and long term support (LTS) versions of .NET Core. When this question was written, those were:
Target Framework
Target framework moniker (TFM)
.NET 5.0 (current)
net5.0
.NET Core 3.1 (LTS)
netcoreapp3.1
.NET Core 2.1 (LTS)
netcoreapp2.1
It's easy enough to set up the csproj files to target multiple frameworks:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1;net5.0</TargetFrameworks>
</PropertyGroup>
That works well for local builds when all of these SDKs are installed. However, I'd prefer to have my CI builds take place on a single, lightweight Docker container. I'm not worried about verifying .NET Framework support, so I don't need Windows. The .NET SDK images on Docker Hub work well for any single framework (i.e., mcr.microsoft.com/dotnet/sdk:5.0), but I would like to find a Docker image that includes all three of these SDKs without the baggage of a "kitchen sink" image like the GitHub-hosted runners, which include many unrelated frameworks and tools.
I could write my own Dockerfile, starting from a base image and scripting the installation of the extra SDKs, but surely I can't be the only person who could use something like this. Does a suitable Docker image already exist somewhere? Should I be taking a different approach to this problem, like scripting the SDK installation with setup-dotnet or an equivalent?
While the latest dotnet SDK can target any previous SDK versions,dotnet test requires the particular dotnet runtime. There are many ways to install dotnet sdk/runtimes into a base docker image, but the easiest is to just copy the SDK and/or runtimes from existing base images. Here's an example for dotnet 6, should you need the dotnet 5.0 runtime for unit tests:
FROM mcr.microsoft.com/dotnet/sdk:6.0 as build
#uncomment if you need the 5.0 SDK also (unlikely):
#COPY --from=mcr.microsoft.com/dotnet/sdk:5.0 /usr/share/dotnet/sdk /usr/share/dotnet/sdk
# "install" the dotnet 5 runtime
COPY --from=mcr.microsoft.com/dotnet/sdk:5.0 /usr/share/dotnet/shared /usr/share/dotnet/shared
If you run the above image and get into the shell and do dotnet --info it's as expected:
$ docker run -it --rm 0de6f2cdf814
root#b4bb146dcf7e:/src# dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.200
Commit: 4c30de7899
Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: debian.11-x64
Base Path: /usr/share/dotnet/sdk/6.0.200/
Host (useful for support):
Version: 6.0.2
Commit: 839cdfb0ec
.NET SDKs installed:
6.0.200 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 5.0.10 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 5.0.10 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
root#b4bb146dcf7e:/src#
Just use the Docker image for the latest .NET version (currently mcr.microsoft.com/dotnet/sdk:5.0). It's capable of building projects that target different versions. It's the same as how you can do this locally on your dev machine. You can just install 5.0 SDK on your machine and build projects that target 2.1, 3.1, or 5.0.
If you're wanting to run unit tests in the same container, you will need to install the extra runtimes that you require for each of the versions other than 5.0. This will vary based on what OS you're targeting but you can find details on the installation at https://learn.microsoft.com/en-us/dotnet/core/install/. For example, on Debian, you can install ASP.NET 3.1 runtime with the following:
wget https://packages.microsoft.com/config/debian/10/packages-microsoft-prod.deb -O packages-microsoft-prod.deb && \
dpkg -i packages-microsoft-prod.deb && \
apt-get update && \
apt-get install -y apt-transport-https && \
apt-get update && \
apt-get install -y aspnetcore-runtime-3.1
I've tried to avoid building custom images and scripting extra runtimes, so my variant was to run build/test on multiple containers (sdk:2.1, sdk:3.1) separately.
Funny enough, having multitarget:
<PropertyGroup>
<TargetFrameworks>netcoreapp2.1;netcoreapp3.1</TargetFrameworks>
</PropertyGroup>
does not allow building on sdk:2.1 container, even if you specify that you only want to build for 2.1, with parameter -f netcoreapp2.1.
I ended up with conditioned csproj file, which specifies TargetFrameworks based on outside parameter. For example, my csproj configuration is:
<TargetFrameworks Condition=" '$(TestTargetFramework)' == '' ">netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition=" '$(TestTargetFramework)' == 'netcoreapp2.1' ">netstandard2.0</TargetFrameworks>
<TargetFrameworks Condition=" '$(TestTargetFramework)' == 'netcoreapp3.1' ">netstandard2.1</TargetFrameworks>
And I can build/test it on sdk:2.1:
dotnet test ./test/Tests --configuration Release /p:TestTargetFramework=netcoreapp2.1
Or sdk:3.1:
dotnet test ./test/Tests --configuration Release /p:TestTargetFramework=netcoreapp3.1

Update .NET Core Tools

I'm trying to use EntityFrameworkCore#3.1. In order to do this at this point I already have:
- Installed Visual Studio 2019 Preview
- Installed the .NET Core 3.1 Runtime
- Installed the .NET Core 3.1 SDK
Now I still can't run the command dotnet ef migrations add xxx. It's saying that I have to update the dotnet tools. So I run the following command in an administrator powershell:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef
Tool 'dotnet-ef' was reinstalled with the latest stable version (version '3.0.0')
Okay, not including the preview versions. So I try to specify the version explicitly:
PS C:\WINDOWS\system32> dotnet tool update --global dotnet-ef --version="3.1.0-preview1.19506.2"
error NU1202: Package dotnet-ef 3.1.0-preview1.19506.2 is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1) / any. Package dotnet-ef 3.1.0-preview1.19506.2 supports: netcoreapp3.1 (.NETCoreApp,Version=v3.1)
Tool 'dotnet-ef' failed to update due to the following:
The tool package could not be restored.
Tool 'dotnet-ef' failed to install. This failure may have been caused by:
* You are attempting to install a preview release and did not use the --version option to specify the version.
* A package by this name was found, but it was not a .NET Core tool.
* The required NuGet feed cannot be accessed, perhaps because of an Internet connection problem.
* You mistyped the name of the tool.
For more reasons, including package naming enforcement, visit https://aka.ms/failure-installing-tool
Now it's saying that a .NET Core 3.1 tool is not compatible with the .NET Core 3.1 runtime.
However, if I do a simple version check:
PS C:\WINDOWS\system32> dotnet --version
3.1.100-preview1-014459
PS C:\WINDOWS\system32> dotnet ef --version
Entity Framework Core .NET Command-line Tools
3.0.0
I can see that the EntityFrameworkCore.Tools is still at version 3.0.0 instead of 3.1.0 (which tools version is installed in my project).
Am I still missing something or is this a bug?
Thanks to #lars-haupt-hansen for pointing me to the bug, I followed the trail to the PR which shows it was merged into "aspnet:release/3.1". The latest 3.1 is still a preview (preview3) [edit: it's out of preview]. You can find and download the latest SDK here.
To use it in Visual Studio projects, you have to
install the SDK from the above link;
go to Tools > Options > Environment > Preview Features and enable "Use previews of the .NET Core SDK"; (not required for 3.1 anymore)
restart VS (not required for 3.1 anymore)
Go to each project properties, and then you can choose the Target Framework .NET Core 3.1
Then to install EF Core via the command line, run dotnet tool install --global dotnet-ef from your project directory.
dotnet tool install -g dotnet-ef --version 3.0.0-preview4.19216.3
dotnet tool install --global dotnet-ef --version 3.0.0-preview8.19405.11

The specified framework 'Microsoft.AspNetCore.App', version '2.1.8' was not found. with docker

I have a project compiling with .net core 2.1
The project is very simple:
Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
</ItemGroup>
I have these two libraries reference:
It compiles and runs properly on the host.
I made a docker image:
FROM microsoft/dotnet:2.1-sdk AS build
COPY ./Test /src/Test
WORKDIR /src/Test
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app --no-restore
FROM microsoft/dotnet:2.1-runtime AS final
WORKDIR /app
COPY --from=publish /app .
CMD ["dotnet", "Test.dll"]
It builds properly, no warnings.
But when I execute it:
# dotnet Test.dll
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' was not found.
- Check application dependencies and target a framework version installed at:
/usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
https://aka.ms/dotnet-download
So, when I check the framework version (I build with dotnet:2.1-runtime):
# dotnet --info
Host (useful for support):
Version: 2.1.8
Commit: 209f8aa25c
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
So it looks like 2.1.8 is installed and somehow, it can't do the role of 2.1.1.
I tried two things:
update my libs to version 2.1.8... then it can't find version 2.1.8 of the asp lib
not put any version requirement in the csproj file and it can't find the asp lib either
How to get this working?
I found that when using ASP, you can’t use the .net core image and add asp libraries.
You need to take the .net core asp docker image.

Error using dotnet in Jenkins for NetCore 1.1 projects

I have two basic NetCore project (just a Console app).
- One with NetCore 2.0 target and the other with NetCore 1.1.
- I'm using "dotnet build xxxx.csproj" to build de project
The question is, Do you know why NetCore 2.0 build correctly and why NetCore 1.1 cannot build in the same way?
Detail error:
"C:\Program Files\dotnet\sdk\2.0.2\NuGet.targets(102,5): error : U2nable to load the service index for source https://api.nuget.org/v3/index.json."
Additional information:
- dotnet --info
Version: 2.0.2
Commit SHA-1 hash: a04b4bf512
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk\2.0.2\
Microsoft .NET Core Shared Framework Host
Version : 2.0.0
Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
dotnet nuget --version
NuGet Command Line
4.4.0.3
Thanks so much in advance for your help.
Regards
Juanlu

dotnet restore cmd failing - error MSB4019 - \DotNet\Microsoft.DotNet.Props file missing #5175

So I've done some searching most articles suggest installing the Vs2015 tooling. Which I have installed. But I am still getting this error when I try to restore a project from Yeomans. The 'Microsoft.DotNet.Props' file definitely does not exist on my machine. Im running Windows 7 x64 with Vs2015update3 and Vs2015 tools preview 2.0.3. What am I doing wrong?
Not sure if this helps but here is my dotnet --info
Product Information:
Version: 1.0.0-preview4-004233
Commit SHA-1 hash: 8cec61c
Runtime Environment:
OS Name: Windows
OS Version: 6.1.7601
OS Platform: Windows
RID: win7-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0-preview4-004233
I was able to work through this issue. The original Yeomans template I was using was generated with a different version to dotnet so I had to manually force this switch using the global.json file with Solution file and the Visual Studio IDE was able to update the build. Then I could switch back and get the builds to run. This may not be the only way but this did work for me in this case. Here is more details on the issue.
https://forums.asp.net/t/2113044.aspx?dotnet+restore+failing+error+MSB4019+1+0+0+preview4+004233+Microsoft+VisualStudio+v14+0+DotNet+Microsoft+DotNet+Props+was+not+found+

Resources