简体   繁体   中英

Docker Build : The "ContainerBuildAndLaunch" task failed unexpectedly. Could not load file or assembly 'Microsoft.Win32.Registry

I am trying to build my.Net 6.0 API Project in Visual studio 2022, and I get the following error.

MSB4018 The "ContainerBuildAndLaunch" task failed unexpectedly.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Win32.Registry, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'  user declined directory sharing

Even though project target OS Framework - Linux, it is looking out for Microsoft.Win32.Registry for some reason. Any direction will be highly appreciated.

Docker file

#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["BPBComputerGadgets.ProductsAPI/BPBComputerGadgets.ProductsAPI.csproj", "BPBComputerGadgets.ProductsAPI/"]
RUN dotnet restore "BPBComputerGadgets.ProductsAPI/BPBComputerGadgets.ProductsAPI.csproj"
COPY . .
WORKDIR "/src/BPBComputerGadgets.ProductsAPI"
RUN dotnet build "BPBComputerGadgets.ProductsAPI.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "BPBComputerGadgets.ProductsAPI.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BPBComputerGadgets.ProductsAPI.dll"]

The issue was the user declined directory sharing . Opened the docker desktop->settings->Resources->File Sharing and Add the folders -> Apply and restart.

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM