繁体   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