Errors installing microsoft-net-sdk-blazorwebassembly-aot in Dockerfile - asp.net

I'm trying to run dotnet workload install microsoft-net-sdk-blazorwebassembly-aot from my Dockerfile while building my Blazor project in order to enable AOT WASM compilation.
Here is the relevant Dockerfile code:
FROM mcr.microsoft.com/dotnet/sdk:6.0-focal-amd64 AS builder
...
RUN dotnet workload install microsoft-net-sdk-blazorwebassembly-aot
RUN dotnet publish -c Release
However, this fails with an error like:
Updated advertising manifest microsoft.net.sdk.ios.
Updated advertising manifest microsoft.net.sdk.maccatalyst.
Updated advertising manifest microsoft.net.sdk.macos.
Updated advertising manifest microsoft.net.workload.mono.toolchain.
Updated advertising manifest microsoft.net.sdk.tvos.
Updated advertising manifest microsoft.net.sdk.android.
Installing workload manifest microsoft.net.sdk.ios version 14.5.100-preview.5.894.
Workload installation failed, rolling back installed packs...
Installing workload manifest microsoft.net.sdk.ios version 14.5.100-preview.5.881.
Installation roll back failed: Failed to install manifest microsoft.net.sdk.ios version 14.5.100-preview.5.881: The transaction has aborted..
Workload installation failed: Failed to install manifest microsoft.net.sdk.ios version 14.5.100-preview.5.894: Invalid cross-device link.
I also tried with --skip-manifest, and this appears to install the workload, but then fails to perform the AOT build.
RUN dotnet workload install microsoft-net-sdk-blazorwebassembly-aot --skip-manifest-update
Installing pack Microsoft.NETCore.App.Runtime.Mono.browser-wasm version 6.0.0-preview.5.21301.5...
Writing workload pack installation record for Microsoft.NETCore.App.Runtime.Mono.browser-wasm version 6.0.0-preview.5.21301.5...
...
Garbage collecting for SDK feature bands 6.0.100...
Successfully installed workload(s) microsoft-net-sdk-blazorwebassembly-aot.
RUN dotnet publish -c Release
...
Optimizing assemblies for size, which may change the behavior of the app. Be sure to test after publishing. See: https://aka.ms/dotnet-illink
AOT'ing 50 assemblies
/usr/share/dotnet/packs/Microsoft.NET.Runtime.WebAssembly.Sdk/6.0.0-preview.5.21301.5/Sdk/WasmApp.targets(507,5): error MSB3073: The command "emcc --version" exited with code 1.
Any advice?

Morgan, you're hitting two issues:
On the skip-manifest (which is the workaround) is issue https://github.com/dotnet/sdk/issues/18450
The emcc --version error is issue https://github.com/dotnet/runtime/issues/54342 and resolved by installing Python first...see example: https://github.com/timheuer/PictureFixer/blob/docker/PictureFixer/Dockerfile#L11-L12 (on docker branch in the repo)
You will then hit a different bug (could not find cross compiler) which is issue https://github.com/dotnet/runtime/pull/54651 (which has been checked in).
Once #3 is fixed in an image you can consume, it should work ensuring you add #2 in your script. Example full Docker file:
FROM mcr.microsoft.com/dotnet/nightly/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
#FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
FROM mcr.microsoft.com/dotnet/nightly/sdk:6.0 AS build
COPY ["nuget.config", "nuget.config"]
RUN apt-get update
RUN apt-get install --no-install-recommends --yes python3
RUN dotnet workload install microsoft-net-sdk-blazorwebassembly-aot --skip-manifest-update
WORKDIR /src
COPY ["Server/PictureFixer.Server.csproj", "Server/"]
COPY ["Shared/PictureFixer.Shared.csproj", "Shared/"]
COPY ["Client/PictureFixer.Client.csproj", "Client/"]
RUN dotnet restore "Server/PictureFixer.Server.csproj"
COPY . .
WORKDIR "/src/Server"
RUN dotnet build "PictureFixer.Server.csproj" -c Release -o /app/build --nologo
FROM build AS publish
RUN dotnet publish "PictureFixer.Server.csproj" -c Release -o /app/publish --nologo
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "PictureFixer.Server.dll"]
You can temporarily work around #3 by adding this to your Blazor Wasm project csproj:
<PropertyGroup>
<_MonoAotCrossCompilerPath>#(MonoAotCrossCompiler->WithMetadataValue('RuntimeIdentifier','browser-wasm'))</_MonoAotCrossCompilerPath>
</PropertyGroup>

Related

.Net Dockerizing excluding build stage in the dockerfile

I am new to docker and AKS, I am working on a .Net project that is migrated from .Net core 3.1 to .Net 6 , I am trying to containerize and deploy to AKS. First i wanted to test in the local machine so i had setup docker in the macbook m1 and followed this link https://learn.microsoft.com/en-us/visualstudio/mac/docker-quickstart?view=vsmac-2022 to create a dockerfile, I am able to run the dockerfile from Visual Studio if i follow the steps given in the link but if i run docker compose command from terminal i am getting issues with SDK version, however what i am trying to achieve is remove the build stage and directly run the .net application as the build stage is taken care by Jenkins and the DLL is placed in a folder
Here is the complete dockerfile with all the stages
FROM mcr.microsoft.com/dotnet/core/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/core/sdk:6.0 AS build
WORKDIR /src
COPY DockerDemo/DockerDemo.csproj DockerDemo/
RUN dotnet restore "DockerDemo/DockerDemo.csproj"
COPY . .
WORKDIR "/src/DockerDemo"
RUN dotnet build "DockerDemo.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "DockerDemo.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "DockerDemo.dll"]
I modified dockerfile excluding build stage, I am taking DLL file from a "lib/net6.0" that is built by jenkins and placed in this folder
FROM mcr.microsoft.com/dotnet/core/aspnet:6.0 AS base
COPY ["lib/net6.0","/src/"]
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM base as final
WORKDIR /app
COPY --from=base /src/ .
ENTRYPOINT["dotnet","DockerDemo.dll"]
If i build the dockerfile the image is getting created but when i run I am getting following error
unhandled exception system.io.filenotfoundexception could not load
file or assembly 'NLog, Version=.5.0.0.0
The project is using NLog.Web.ASPNetCore 5.1.4 version, i tried downgrading it to 5.0.0 but i am still getting the same error, i also tried adding just NLog 5.0.0 package but no luck
As i said i am new to Docker and also to the .net development on macbook
My Questions
Q1) Is it possible to exclude the build stage in dockerfile and directly run
Q2) Does the macbook m1 completely supports .Net Core and .Net 6 development so that it can be deployed to AKS via Jenkins pipeline

Deploy Blazor Wasm with Docker from Visual Studio

I want to deploy my Blazor Webassambly App to a Docker Container to run it on my synology NAS.
So my problem is now, that since I want to run my Webassembly App in my VisualStudio IDE with Docker, I have an error "The library 'hostpolicy.dll' required to execute the application was not found in ..."
Has anyone an idea what i could do do solve this error?
Here is the full console output:
docker exec -i -e ASPNETCORE_HTTPS_PORT="55427" -w "C:\app" d274a895523ac47657707b86a7df5ea304df8bfe68330a64b00d9cc357ed1546 "C:\Program Files\dotnet\dotnet.exe" --additionalProbingPath c:\\.nuget\\fallbackpackages2 --additionalProbingPath c:\\.nuget\\fallbackpackages "C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.dll"
Cannot use file stream for [C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.deps.json]: No such file or directory
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\app\bin\Debug\net5.0\'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.runtimeconfig.json' file and specify the appropriate framework.
docker exec -i -e ASPNETCORE_HTTPS_PORT="55427" -w "C:\app" d274a895523ac47657707b86a7df5ea304df8bfe68330a64b00d9cc357ed1546 "C:\Program Files\dotnet\dotnet.exe" --additionalProbingPath c:\\.nuget\\fallbackpackages2 --additionalProbingPath c:\\.nuget\\fallbackpackages "C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.dll"
Cannot use file stream for [C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.deps.json]: No such file or directory
A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\app\bin\Debug\net5.0\'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'C:\app\bin\Debug\net5.0\Jordan_Webapp_Client.runtimeconfig.json' file and specify the appropriate framework.
And here is my Docker File:
#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["Jordan_Webapp_Client/Jordan_Webapp_Client.csproj", "Jordan_Webapp_Client/"]
RUN dotnet restore "Jordan_Webapp_Client/Jordan_Webapp_Client.csproj"
COPY . .
WORKDIR "/src/Jordan_Webapp_Client"
RUN dotnet build "Jordan_Webapp_Client.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Jordan_Webapp_Client.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Jordan_Webapp_Client.dll"] ```
If you're using a private nuget feed, try changing the "RUN dotnet restore..." command.
Example:
RUN dotnet restore -s "https://your-nuget-feed.example.com/nuget" -s "https://api.nuget.org/v3/index.json" "Jordan_Webapp_Client/Jordan_Webapp_Client.csproj"

Cannot connect to azure nuget feed when creating a container

I have been trying to get docker to pull from a private nuget feed which is hosted within Azure Devops, but I consistently get a 401 unauthorized error. I have looked a numerous other answers and resources, but all of which have not helped. My dockerfile script is the following
# escape=`
FROM mcr.microsoft.com/dotnet/core/sdk:3.1 AS build-env
WORKDIR /src
EXPOSE 80
EXPOSE 443
ARG FEED_URL
ARG FEED_ACCESSTOKEN
# Install powershell via dotnet
RUN dotnet tool install --global PowerShell --version 7.0.0
SHELL ["pwsh", "-command"]
## CURRENT ERROR - "-AddNetfx" - NOT CONSIDERED AN ARGUMENT, ALTHOUGH IT IS (CAN BE SEEN IN THE SCRIPT ENTRY) ##
# Install credprovider which is required for accessing private artifact repository
RUN Invoke-WebRequest https://raw.githubusercontent.com/microsoft/artifacts-credprovider/master/helpers/installcredprovider.ps1 -OutFile installcredprovider.ps1; `
.\installcredprovider.ps1 -AddNetfx; `
del installcredprovider.ps1
#################################################################################################################
# Copy csproj and sln files
COPY ["Abstractions/*.csproj", "./Abstractions/"]
COPY ["AdminServicesPortal/*.csproj", "./AdminServicesPortal/"]
COPY ["DataInterface/*.csproj", "./DataInterface/"]
COPY ["Resources/*.csproj", "./Resources/"]
# Need to copy over docker NuGet packages
COPY "AdminServicesPortal/nuget.config" "AdminServicesPortal/"
# Enable session token cache
ENV NUGET_CREDENTIALPROVIDER_SESSIONTOKENCACHE_ENABLED true
ENV VSS_NUGET_EXTERNAL_FEED_ENDPOINTS `
"{`"endpointCredentials`": [{`"endpoint`":`"https://pkgs.dev.azure.com/ORG/PROJECT/_packaging/FEED/nuget/v3/index.json`", `"username`":`"USER`", `"password`":`"PAT`"}]}"
RUN echo $Env:VSS_NUGET_EXTERNAL_FEED_ENDPOINTS
# Restore dependencies before copying everything else over
RUN dotnet restore "AdminServicesPortal/Portal.csproj"
# Copy the rest of the files required for a build
# Note that this is separate, because we should stop building
# the container if we do not have all required dependencies
COPY Abstractions/. ./Abstractions/
COPY AdminServicesPortal/. ./AdminServicesPortal/
COPY DataInterface/. ./DataInterface/
COPY Resources/. ./Resources/
WORKDIR "/src/AdminServicesPortal"
RUN dotnet build "Portal.csproj" -c Release -o /app/build
# Publish application
FROM build-env AS publish
RUN dotnet publish "Portal.csproj" -c Release -o /app/publish
# Runtime environment for container
FROM build-env AS final
WORKDIR /app
COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "MPX.AdminServices.Portal.dll"]
The error I get from Visual Studio is the following
2> Failed to restore C:\src\Resources\Resources.csproj (in 2.99 sec).
2>C:\Program Files\dotnet\sdk\3.1.404\NuGet.targets(128,5): error : Unable to load the service index for source https://pkgs.dev.azure.com/{ORG}/{PROJECT}/_packaging/{FEED}/nuget/v3/index.json. [C:\src\AdminServicesPortal\Portal.csproj]
2>C:\Program Files\dotnet\sdk\3.1.404\NuGet.targets(128,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\src\AdminServicesPortal\Portal.csproj]
From what I can tell in the link below; my dockerfile script should work
https://github.com/dotnet/dotnet-docker/blob/master/documentation/scenarios/nuget-credentials.md#using-the-azure-artifact-credential-provider
To ensure it wasn't an issue with the PAT of the user not having access, I gave them access to everything across the whole entire organisation. Any help would be greatly appreciated!
Note #1: My current suspicion is that there are some additional parameters I might need to pass, since the private nuget feed is for a project rather than the entire organisation?
Note #2: I ran the following PowerShell command (https://learn.microsoft.com/en-us/azure/devops/artifacts/tutorials/private-powershell-library?view=azure-devops#package-and-publish-the-module) which worked fine, so I am even more confused to why my dockerfile script does not work.
nuget sources Add -Name "PowershellModules" -Source "https://pkgs.dev.azure.com/<org_name>/_packaging/<feed_name>/nuget/v3/index.json" -username "<user_name>" -password "<personal_access_token(PAT)>"
You can check out below workarounds without using NuGet credential plugin.
1, Use dotnet cli to add credentials to the nuget source in your docker file. And then pass the $PAT in the build arguments (ie. --build-arg PAT=$PAT ):
ARG PAT
COPY . .
RUN dotnet nuget add source "your-source-url" --name "source-name" --username "useless" --password "$PAT" --store-password-in-clear-text
RUN dotnet restore
2, You can also try adding the credentials to the config file using the nuget command. And include the nuget.config which has the credentials in the build context. And copy the nuget.config in your docker file . See below:
sources Add -Name "MyPackages" -Source "https://my.pkgs.visualstudio.com/_packaging/MyPackages/nuget/v3/index.json" -username any -password $PAT -ConfigFile Source/Nuget.config -StorePasswordInClearText
Copy the nuget.config in the docker file, You can delete the nuget.config file when the restore is complete:
COPY *.csproj .
COPY ./nuget.config .
RUN dotnet restore
RUN rm nuget.config
You can refer to my answer to this similar thread that using azure nuget feed in the docker container in Azure pipelines.

Install .NET Runtime on .NET Core 3.1 Nano Server Docker Image

I have a .NET Core 3.1 console app that uses the Microsoft.NET.Sdk.WindowsDesktop project SDK because it references Geometry3D in System.Windows.Media.Media3D.
I would like to run this in a Docker container on Windows Nano Server, but I receive the following error when executing docker run:
It was not possible to find any compatible framework version
The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=3.1.0&arch=x64&rid=win10-x64
How do I go about installing the required sdk and runtime?
Here is my existing Dockerfile:
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["HelloWpfCore/HelloWpfCore.csproj", "HelloWpfCore/"]
RUN dotnet restore "HelloWpfCore/HelloWpfCore.csproj"
COPY . .
WORKDIR "/src/HelloWpfCore"
RUN dotnet build "HelloWpfCore.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HelloWpfCore.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloWpfCore.dll"]
GitHub repo is here: https://github.com/tonysneed/hello-netcore-wpf-nano
I figured it out. I created an image that installs the Windows Desktop runtime on Nano Server base image.
# escape=`
# Installer image
FROM mcr.microsoft.com/windows/servercore:1909 AS installer
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Retrieve .NET Core Runtime
# USER ContainerAdministrator
RUN $dotnet_version = '3.1.5'; `
Invoke-WebRequest -OutFile dotnet-installer.exe https://download.visualstudio.microsoft.com/download/pr/86835fe4-93b5-4f4e-a7ad-c0b0532e407b/f4f2b1239f1203a05b9952028d54fc13/windowsdesktop-runtime-3.1.5-win-x64.exe; `
$dotnet_sha512 = '5df17bd9fed94727ec5b151e1684bf9cdc6bfd3075f615ab546759ffca0679d23a35fcf7a8961ac014dd5a4ff0d22ef5f7434a072e23122d5c0415fcd4198831'; `
if ((Get-FileHash dotnet-installer.exe -Algorithm sha512).Hash -ne $dotnet_sha512) { `
Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
exit 1; `
}; `
`
./dotnet-installer.exe /S
# Runtime image
FROM mcr.microsoft.com/windows/nanoserver:1909
ENV `
# Enable detection of running in a container
DOTNET_RUNNING_IN_CONTAINER=true
# In order to set system PATH, ContainerAdministrator must be used
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\Program Files\dotnet"
USER ContainerUser
COPY --from=installer ["/Program Files/dotnet", "/Program Files/dotnet"]
I pushed this to my repo on Docker Hub: https://hub.docker.com/repository/docker/tonysneed/dotnet-runtime-windowsdesktop
Then I simply used this custom image as the base image for my sample app: https://github.com/tonysneed/hello-netcore-wpf-nano

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file

I have an issue perform docker build
docker build -t ordering .
My Dockerfile
FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY . .
WORKDIR /src/src/Services/Ordering/Ordering.API
RUN dotnet restore -nowarn:msb3202,nu1503
RUN dotnet build --no-restore -c Release -o /app
FROM build AS publish
RUN dotnet publish --no-restore -c Release -o /app
FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "Ordering.API.dll"]
Error from the terminal
Step 9/15 : RUN dotnet build --no-restore -c Release -o /app
---> Running in edb1cdf64b43
Microsoft (R) Build Engine version 15.5.180.51428 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.
The command '/bin/sh -c dotnet build --no-restore -c Release -o /app' returned a non-zero code: 1
I have been google for a while for this issues.
Please help
I've only seen that error when attempting to run dotnet run with an already published project (which you do seem to be working with an already published project). Instead, you should simply do dotnet MyProject.dll (no run).
The issue fix by using docker-compose.yml up

Resources