我正在使用Windows 10机器,因为当我尝试构建其引发错误的应用程序时,我想对我的dotnet应用程序进行Docker化。
error MSB4019: The imported project "C:\Program Files\dotnet\sdk\2.1.302\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
The command 'cmd /S /C dotnet restore' returned a non-zero code: 1
下面是我的docker文件:
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "AppGenerator.dll"]
请帮帮我
感谢和问候,
答案 0 :(得分:0)
我相信您可以通过更改以下内容来解决此问题
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build-env /app/out .
到
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /out
COPY --from=build-env /out .
否则,请查阅以下工作解决方案。我有这样的项目结构
我的docker文件是
#Stage 1 build
FROM microsoft/dotnet:sdk as builder
#Create the src in the immediate build steps
WORKDIR /src
# Cache the result bui copying csproj in the current folder
COPY *.csproj .
RUN dotnet restore
# Copy the rest of your code
COPY . .
RUN dotnet publish --output /app/ --configuration Release
#stage 2
FROM microsoft/dotnet:2.1-aspnetcore-runtime
WORKDIR /app
COPY --from=builder /app .
CMD [ "dotnet", "Fantastic.dll" ]
结果是