简体   繁体   English

从具有多个项目的解决方案构建 docker 容器

[英]Build docker container from solution with multiple projects

I have a .NET Core project that contained 2 projects:我有一个包含 2 个项目的 .NET Core 项目:

SLN: 
     - Web-API
     - Infrastructure

I was building it with docker using this dockerfile我正在使用这个 dockerfile 与 docker 一起构建它

FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
COPY . ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/aspnetcore:2.0
WORKDIR /app
COPY --from=build-env /app/ .
ENTRYPOINT ["dotnet", "/app/Lab/out/API.dll"]

But now I have created a Web application as well in my solution但是现在我在我的解决方案中也创建了一个 Web 应用程序

SLN:
 - Web-API
 - Web-App
 - Infrastructure

Suddenly, docker isn't building anymore.突然间,docker 不再构建了。 How come?怎么来的? How can I create two docker containers based on the same solution one for the Web-API and one for the Web-app?如何基于相同的解决方案创建两个 docker 容器,一个用于 Web-API,另一个用于 Web-app?

Error message from Docker:来自 Docker 的错误消息

The "GetDotNetHost" task could not be loaded from the assembly /usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.aspnetcore.mvc.razor.viewcompilation/2.0.3/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Tasks.dll.无法从程序集 /usr/share/dotnet/sdk/NuGetFallbackFolder/microsoft.aspnetcore.mvc.razor.viewcompilation/2.0.3/build/netstandard2.0/Microsoft.AspNetCore.Mvc.Razor 加载“GetDotNetHost”任务.ViewCompilation.Tasks.dll。 Assembly with same name is already loaded Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.已加载同名程序集 确认声明正确,程序集及其所有依赖项都可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类。 [/app/Lab/API.csproj] [/app/Lab/API.csproj]

So this problem is now finally fixed.所以这个问题现在终于解决了。 It actually turned out it was a problem while compiling a .net core 2.0 project when having Razor views available:事实证明,当有 Razor 视图可用时,在编译 .net core 2.0 项目时会出现问题:

Razor view precompilation is currently unavailable when performing a self-contained deployment (SCD) in ASP.NET Core 2.0.在 ASP.NET Core 2.0 中执行独立部署 (SCD) 时,Razor 视图预编译当前不可用。 The feature will be available for SCDs when 2.1 releases.当 2.1 版本发布时,该功能将可用于 SCD。 For more information, see View compilation fails when cross-compiling for Linux on Windows.有关详细信息,请参阅 Windows 上的 Linux 交叉编译时查看编译失败。

What I needed to do was to add the nuget package:我需要做的是添加 nuget 包:

Microsoft.AspNetCore.Mvc.Razor.ViewCompilation Microsoft.AspNetCore.Mvc.Razor.ViewCompilation

in my project to make it work.在我的项目中使其工作。 Strange thing was that it was building inside visual studio for Mac but not from the command prompt.奇怪的是,它是在 Visual Studio for Mac 中构建的,而不是从命令提示符构建的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 .Net 解决方案中的多个项目 - 结合所有项目的构建工件 - Multiple Projects in .Net Solution - Combine Build Artifacts from all projects 解决方案 .NET 中 Docker 多个项目的问题 - Problems with Docker multiple projects in solution .NET 为同一解决方案的多个项目构建序列 - Build Sequence for multiple projects of the same solution 如何将多个项目复制到单个 Docker 容器中 - How to copy multiple projects into a single Docker container 在 Visual Studio Online Build Definition 中从具有多个 Web 项目的解决方案构建一个 Web 项目 - Build one web project from a Solution with multiple web projects in Visual Studio Online Build Definition 以编程方式从解决方案构建中排除项目 - Exclude projects from solution build programmatically 如何为多个项目构建一个 docker 镜像? - How to build one docker image for multiple projects? 单个解决方案中来自多个项目的日志 - Log from multiple projects in single solution 引用解决方案中多个项目的资源文件 - Referencing resource files from multiple projects in a solution ReSharper:“无法启动构建。 解决方案中有多个项目......“ - ReSharper: “The build could not be started. There are multiple projects in the solution at…”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM