簡體   English   中英

警告:無法解析此引用。 找不到程序集“PackageName”。 檢查以確保程序集存在於磁盤上

[英]WARNING: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk

需要一點幫助來解決我在構建 ASP.NET 項目時遇到的問題,該項目引用 docker 容器內的本地 class 庫。

我在用着:

  • ASP.NET 6.0
  • Docker 版本 20.10.21,構建 baeda1f
  • do.net sdk 6.0

當我嘗試運行docker build.

我收到以下錯誤:

 => ERROR [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build                                                                                                                                                                       1.9s
------
 > [build 7/7] RUN dotnet build "ProjectName.csproj" -c Debug -o /app/build:
#15 0.434 MSBuild version 17.3.2+561848881 for .NET
#15 0.655   Determining projects to restore...
#15 0.885   All projects are up-to-date for restore.
#15 1.042 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
 by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.847 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852
#15 1.852 Build FAILED.
#15 1.852
#15 1.852 /usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(2302,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "PackageName". Check to make sure the assembly exists on disk. If this reference is required
 by your code, you may get compilation errors. [/src/ProjectName/ProjectName.csproj]
#15 1.852 CSC : error CS5001: Program does not contain a static 'Main' method suitable for an entry point [/src/ProjectName/ProjectName.csproj]
#15 1.852     1 Warning(s)
#15 1.852     1 Error(s)
#15 1.852
#15 1.852 Time Elapsed 00:00:01.38
------
executor failed running [/bin/sh -c dotnet build "ProjectName.csproj" -c Debug -o /app/build]: exit code: 1

我正在使用的dockerfile

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY ["ProjectName.csproj", "ProjectName/"]
RUN dotnet restore "ProjectName/ProjectName.csproj"
COPY .. .
WORKDIR "/src/ProjectName"
RUN dotnet build "ProjectName.csproj" -c Publish -o /app/build

FROM build AS debug
RUN dotnet publish "ProjectName.csproj" -c Publish -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "ProjectName.dll"]

.csproj文件

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <Nullable>enable</Nullable>
        <ImplicitUsings>enable</ImplicitUsings>
        <DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
    </PropertyGroup>

    <ItemGroup>
        ....
    </ItemGroup>

    <ItemGroup>
      <Reference Include="PackageName">
        <HintPath>..\..\PackageName\PackageName\bin\Debug\netstandard2.1\PackageName.dll</HintPath>
      </Reference>
    </ItemGroup>

</Project>


關於我讓dockerfile獲取構建中的 package .dll有什么想法嗎? 還是 go 關於獲得我想要的東西的錯誤方式?

我願意在 nuget 上托管 package,但目前這個dockerfile僅用於開發目的。

請記住,package 在本地的正確位置,因為使用以下方法構建項目:

do.net build ProjectName.csproj

工作正常


PS 我用“PackageName”替換了 package 名稱,用“ProjectName”替換了項目名稱。

我嘗試為 ASP.NET 6.0 構建 dockerfile,我希望它能通過,但我得到了一個錯誤。

所以我幾乎立即解決了這個問題,我將 class 庫構建到我的 asp.net 項目所在的位置,清除了 docker 緩存,然后再次構建。

Id項目位於您的計算機上,您需要在定義后復制xxx.dll

SWORKDIR /src COPY ["Xxx.csproj", "."] COPY ["output/Debug.net6.0/xxx.dll", "."]

否則你必須創建 nuget package dll 然后你從 nuget 安裝

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM