ASP.NET 核心对接嵌套项目

ASP.NET core dockerising a nested project

所以,我最近遇到了一个我想 dockerise 的项目,它是在 dotnet 中构建的(我应该警告我不是 .net 开发人员)

可以在这里找到 repo 以供参考:

https://github.com/observerly/ASCOM.Alpaca.Simulators

我已尽力设置以下 Dockerfile 以便能够将此应用程序容器化:

# syntax=docker/dockerfile:1
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /app 

# copy NuGet config
COPY NuGet.config .

# copy csproj and restore as distinct layers
COPY *.sln .
COPY ASCOM.Alpaca.Simulators/*.csproj ./ASCOM.Alpaca.Simulators/
COPY Camera.Simulator/*.csproj ./Camera.Simulator/
COPY CoverCalibratorSimulator/*.csproj ./CoverCalibratorSimulator/
COPY DomeSimulator/*.csproj ./DomeSimulator/ 
COPY FilterWheelSimulator/*.csproj ./FilterWheelSimulator/ 
COPY FocuserSimulator/*.csproj ./FocuserSimulator/ 
COPY ObservingConditionsSimulator/*.csproj ./ObservingConditionsSimulator/ 
COPY OmniSim.Tools/*.csproj ./OmniSim.Tools/ 
COPY RotatorSimulator/*.csproj ./RotatorSimulator/ 
COPY SafetyMonitorSimulator/*.csproj ./SafetyMonitorSimulator/ 
COPY SwitchSimulator/*.csproj ./SwitchSimulator/ 
COPY TelescopeSimulator/*.csproj ./TelescopeSimulator/ 

# copy WindowsBase.Vector
COPY WindowsBase.Vector/*.sln ./WindowsBase.Vector/ 
COPY WindowsBase.Vector/WindowsBase.Vector/*.csproj ./WindowsBase.Vector/WindowsBase.Vector/ 

RUN dotnet restore 

# copy everything else and build app
COPY ASCOM.Alpaca.Simulators/. ./ASCOM.Alpaca.Simulators/
COPY Camera.Simulator/. ./Camera.Simulator/
COPY CoverCalibratorSimulator/. ./CoverCalibratorSimulator/
COPY DomeSimulator/. ./DomeSimulator/ 
COPY FilterWheelSimulator/. ./FilterWheelSimulator/ 
COPY FocuserSimulator/. ./FocuserSimulator/ 
COPY ObservingConditionsSimulator/. ./ObservingConditionsSimulator/ 
COPY OmniSim.Tools/. ./OmniSim.Tools/ 
COPY RotatorSimulator/. ./RotatorSimulator/ 
COPY SafetyMonitorSimulator/. ./SafetyMonitorSimulator/ 
COPY SwitchSimulator/. ./SwitchSimulator/ 
COPY TelescopeSimulator/. ./TelescopeSimulator/ 

WORKDIR /app/ASCOM.Alpaca.Simulators
RUN dotnet publish -c Release -o out 

# Build runtime image
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS runtime
WORKDIR /app 

COPY --from=build /app/ASCOM.Alpaca.Simulators/out ./
ENTRYPOINT ["dotnet", "ASCOM.Alpaca.Simulators.dll"]

但是,我遇到了以下错误堆栈:

#44 4.204 /app/TelescopeSimulator/AstronomyFunctions.cs(282,23): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.205 /app/TelescopeSimulator/AstronomyFunctions.cs(379,47): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.205 /app/TelescopeSimulator/AstronomyFunctions.cs(379,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.205 /app/TelescopeSimulator/AstronomyFunctions.cs(395,47): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.205 /app/TelescopeSimulator/AstronomyFunctions.cs(395,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.205 /app/TelescopeSimulator/MountFunctions.cs(25,51): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.206 /app/TelescopeSimulator/MountFunctions.cs(25,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.206 /app/TelescopeSimulator/MountFunctions.cs(64,52): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(64,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(97,51): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(97,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(123,52): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(123,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.207 /app/TelescopeSimulator/MountFunctions.cs(159,42): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.208 /app/TelescopeSimulator/MountFunctions.cs(159,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.208 /app/TelescopeSimulator/MountFunctions.cs(168,43): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.209 /app/TelescopeSimulator/MountFunctions.cs(168,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.209 /app/TelescopeSimulator/MountFunctions.cs(177,41): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.210 /app/TelescopeSimulator/MountFunctions.cs(177,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.210 /app/TelescopeSimulator/TelescopeHardware.cs(1497,43): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.210 /app/TelescopeSimulator/TelescopeHardware.cs(1517,42): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.211 /app/TelescopeSimulator/TelescopeHardware.cs(1670,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.212 /app/TelescopeSimulator/TelescopeHardware.cs(1786,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.212 /app/TelescopeSimulator/TelescopeHardware.cs(1843,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.212 /app/TelescopeSimulator/TelescopeHardware.cs(1933,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.212 /app/TelescopeSimulator/TelescopeHardware.cs(158,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.213 /app/TelescopeSimulator/TelescopeHardware.cs(163,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.213 /app/TelescopeSimulator/TelescopeHardware.cs(168,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.214 /app/TelescopeSimulator/TelescopeHardware.cs(173,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.214 /app/TelescopeSimulator/TelescopeHardware.cs(193,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.214 /app/TelescopeSimulator/TelescopeHardware.cs(200,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.215 /app/TelescopeSimulator/TelescopeHardware.cs(202,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.215 /app/TelescopeSimulator/TelescopeHardware.cs(219,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.215 /app/TelescopeSimulator/TelescopeHardware.cs(224,24): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.216 /app/TelescopeSimulator/TelescopeHardware.cs(249,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.216 /app/TelescopeSimulator/TelescopeHardware.cs(254,25): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.216 /app/TelescopeSimulator/TelescopeHardware.cs(265,23): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.217 /app/TelescopeSimulator/TelescopeHardware.cs(274,23): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]
#44 4.217 /app/TelescopeSimulator/TelescopeHardware.cs(279,23): error CS0246: The type or namespace name 'Vector' could not be found (are you missing a using directive or an assembly reference?) [/app/TelescopeSimulator/TelescopeSimulator.csproj]

任何人都可以为我提供解决这个棘手问题的建议吗?

我怀疑是和嵌套的WindowsBase.Vector情况有关...

您的错误是您从未将 WindowsBase.Vector 项目的代码复制到容器中。在此块中添加最后一行。

# copy everything else and build app
COPY ASCOM.Alpaca.Simulators/. ./ASCOM.Alpaca.Simulators/
COPY Camera.Simulator/. ./Camera.Simulator/
COPY CoverCalibratorSimulator/. ./CoverCalibratorSimulator/
COPY DomeSimulator/. ./DomeSimulator/ 
COPY FilterWheelSimulator/. ./FilterWheelSimulator/ 
COPY FocuserSimulator/. ./FocuserSimulator/ 
COPY ObservingConditionsSimulator/. ./ObservingConditionsSimulator/ 
COPY OmniSim.Tools/. ./OmniSim.Tools/ 
COPY RotatorSimulator/. ./RotatorSimulator/ 
COPY SafetyMonitorSimulator/. ./SafetyMonitorSimulator/ 
COPY SwitchSimulator/. ./SwitchSimulator/ 
COPY TelescopeSimulator/. ./TelescopeSimulator/ 
COPY WindowsBase.Vector/. ./WindowsBase.Vector/

但是你可以直接做

而不是单独复制每个项目
# copy everything else and build app
COPY . .

并立即复制所有内容。