aspnetcore icon indicating copy to clipboard operation
aspnetcore copied to clipboard

Package not found error Blazor hosted wasm app while docker build

Open ziaulhasanhamim opened this issue 3 years ago • 7 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

Dockerizing a wasm app leads to a weird error.

#19 2.430 MSBuild version 17.4.0+18d5aef85 for .NET
#19 8.448 /usr/share/dotnet/sdk/7.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(267,5): error NETSDK1064: Package Microsoft.AspNetCore.Components.Analyzers, version 7.0.0 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions. [/src/Server/BlazorApp.Server.csproj]
------
executor failed running [/bin/sh -c dotnet publish -c release -o /app --no-restore]: exit code: 1

This problem only happens with an asp.net core app when it is hosting blazor wasm app.

The docker file I used for containerizing -

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY *.sln .
COPY ./Client/*.csproj ./Client/
COPY ./Shared/*.csproj ./Shared/
COPY ./Server/*.csproj ./Server/
RUN dotnet restore
COPY ./Shared/. ./Shared/
COPY ./Client/. ./Client/
COPY ./Server/. ./Server/
WORKDIR /src/Server/
RUN dotnet publish -c release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./
CMD ASPNETCORE_URLS=http://*:$PORT dotnet BlazorApp.Server.dll

Expected Behavior

If I remove --no-restore from publish command then it works fine. But It's weird. Because there is a call for restoring packages already so there is no need to restore the packages again while publishing.

Steps To Reproduce

To reproduce this issue just create a new blazor wasm hosted app. dotnet new blazorwasm --hosted. Then use the docker file I provided above to docker build.

Exceptions (if any)

No response

.NET Version

7.0.100

Anything else?

No response

ziaulhasanhamim avatar Nov 25 '22 13:11 ziaulhasanhamim

@ziaulhasanhamim thanks for contacting us.

Can you try release with a capital R? I believe configurations are case sensitive.

javiercn avatar Nov 25 '22 15:11 javiercn

Hi @ziaulhasanhamim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 25 '22 15:11 ghost

Nope, it doesn't help. I tried.

ziaulhasanhamim avatar Nov 25 '22 15:11 ziaulhasanhamim

@ziaulhasanhamim thanks for the additional details.

On a second look, it might be due to how you are copying the files. I fired up a container instance, created a new project, restored and published without problem, so I suspect something in your docker instructions is causing the issue.

Maybe you can try and run your container, attach to it and see if you are missing files from your copy from one folder to another. That would explain the issue.

With that in mind, it does not look like it's an issue on the framework

javiercn avatar Nov 25 '22 15:11 javiercn

Hi @ziaulhasanhamim. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

ghost avatar Nov 25 '22 15:11 ghost

@javiercn are you using the exact same docker file of above with 'dotnet new blazorwasm --hosted' template? Because simple changes in docker make it work fine.

For example, doing dotnet restore after coping all the files just work fine for me.

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY *.sln .
COPY ./Client/*.csproj ./Client/
COPY ./Shared/*.csproj ./Shared/
COPY ./Server/*.csproj ./Server/
COPY ./Shared/. ./Shared/
COPY ./Client/. ./Client/
COPY ./Server/. ./Server/
RUN dotnet restore
WORKDIR /src/Server/
RUN dotnet publish -c release -o /app --no-restore

FROM mcr.microsoft.com/dotnet/aspnet:7.0
WORKDIR /app
COPY --from=build /app ./
CMD ASPNETCORE_URLS=http://*:$PORT dotnet BlazorApp.Server.dll

If it is not a framework issue then why it only happens with blazor wasm projects? Everything else works fine without even changing the docker file.

ziaulhasanhamim avatar Nov 25 '22 15:11 ziaulhasanhamim

This is the exact wasm and asp.net core project that is producing this issue https://github.com/ziaulhasanhamim/BlazorWasmContainerApp

ziaulhasanhamim avatar Nov 25 '22 16:11 ziaulhasanhamim

Thanks for contacting us. We don't usually investigate customer apps. Looking at this a bit more this looks more like an issue with your custom steps. To get a faster response we suggest posting your questions to StackOverflow using the blazor tag.

mkArtakMSFT avatar Nov 28 '22 17:11 mkArtakMSFT