Closed DmitryGolubenkov closed 1 year ago
Dockerfile generated by Visual Studio Code. NuGet configs were placed in solution folder, and in project folder. Another config was placed in a folder above solution, and that was ignored.
#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:7.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["BlazorApp1/nuget.config", "BlazorApp1/"]
COPY ["nuget.config", "."]
COPY ["BlazorApp1/BlazorApp1.csproj", "BlazorApp1/"]
RUN dotnet restore "BlazorApp1/BlazorApp1.csproj"
COPY . .
WORKDIR "/src/BlazorApp1"
RUN dotnet build "BlazorApp1.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "BlazorApp1.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "BlazorApp1.dll"]
So we need to detect nuget.config files in solution and in selected project.
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["src/folder/WebApplication1/nuget.config", "src/folder/WebApplication1/"]
COPY ["src/folder/nuget.config", "src/folder/"]
COPY ["src/nuget.config", "src/"]
COPY ["nuget.config", "."]
COPY ["src/folder/WebApplication1/WebApplication1.csproj", "src/folder/WebApplication1/"]
RUN dotnet restore "src/folder/WebApplication1/WebApplication1.csproj"
COPY . .
WORKDIR "/src/src/folder/WebApplication1"
RUN dotnet build "WebApplication1.csproj" -c Release -o /app/build
Also we need to copy all NuGet configs from solution folder to project folder. Project subfolders are ignored (also, who would hide their nuget.config inside one of project folders)?
Description
Sometimes nuget.config files are used to help build .NET projects. We need to check if those files exist and include their copy in Dockerfile.