找不到匹配命令"dotnet-/app/Build\ClearPluginAssemblies.dll"Docker的可执行文件

Div*_*Div 9 c# docker docker-build asp.net-core asp.net-core-2.0

我正在尝试使用docker镜像运行我的ASP.NET Core 2.1应用程序.为此我有docker文件,其中包含以下内容:

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app

# copy csproj and restore as distinct layers
COPY . .
RUN dotnet restore

# copy everything else and build app
COPY Presentation/MyProject.Web/. ./Presentation/MyProject.Web/
WORKDIR /app/Presentation/MyProject.Web
RUN dotnet publish -c Release -o out

# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build /app/Presentation/MyProject.Web/out .
ENTRYPOINT ["dotnet", "MyProject.Web.dll"] 
Run Code Online (Sandbox Code Playgroud)

但是当执行命令时docker build -t MyProject-web .它会给我一个错误:

The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1


 MyProject.Web -> /app/Presentation/MyProject.Web/bin/Release/netcoreapp2.1/MyProject.Web.dll
  No executable found matching command "dotnet-/app/Build\ClearPluginAssemblies.dll"
/app/Build/ClearPluginAssemblies.proj(21,5): error MSB3073: The command "dotnet "/app/Build\ClearPluginAssemblies.dll" "OutputPath=/app/Build/../Presentation/MyProject.Web/bin/Release/netcoreapp2.1/|PluginPath=/app/Presentation/MyProject.Web/Plugins/DiscountRules.CustomerRoles/;/app/Presentation/MyProject.Web/Plugins/ExchangeRate.EcbExchange/;/app/Presentation/MyProject.Web/Plugins/ExternalAuth.Facebook/;/app/Presentation/MyProject.Web/Plugins/Payments.CheckMoneyOrder/;/app/Presentation/MyProject.Web/Plugins/Payments.Manual/;/app/Presentation/MyProject.Web/Plugins/Payments.PayPalStandard/;/app/Presentation/MyProject.Web/Plugins/Payments.Square/;/app/Presentation/MyProject.Web/Plugins/Payments.Worldpay/;/app/Presentation/MyProject.Web/Plugins/Pickup.PickupInStore/;/app/Presentation/MyProject.Web/Plugins/Shipping.FixedByWeightByTotal/;/app/Presentation/MyProject.Web/Plugins/Shipping.UPS/;/app/Presentation/MyProject.Web/Plugins/Tax.FixedOrByCountryStateZip/;/app/Presentation/MyProject.Web/Plugins/Widgets.GoogleAnalytics/;/app/Presentation/MyProject.Web/Plugins/Widgets.NivoSlider/|SaveLocalesFolders="" exited with code 1.
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
Run Code Online (Sandbox Code Playgroud)

编辑1: 这是我的项目结构:

Build
    ClearPluginAssemblies
Libraries
    MyProject.Core
    MyProject.Data
    MyProject.Services
Plugins
    MyProject.Plugin.Discount
    MyProject.Plugin.Payment
    ..
Presentation
    MyProject.Web   
    MyProject.Web.Framework
Tests
Run Code Online (Sandbox Code Playgroud)

编辑:2 Web项目文件:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>        
    <Description>MyProject.Web is also an MVC web application project, a presentation layer for public store and admin area.</Description>                
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..\..\Libraries\MyProject.Core\MyProject.Core.csproj" />
    <ProjectReference Include="..\..\Libraries\MyProject.Data\MyProject.Data.csproj" />
    <ProjectReference Include="..\..\Libraries\MyProject.Services\MyProject.Services.csproj" />
    <ProjectReference Include="..\MyProject.Web.Framework\MyProject.Web.Framework.csproj" />
  </ItemGroup>

  <ItemGroup>
    <!-- We copy the entire \App_Data directory. But we ignore JSON files and data protection keys  -->
    <Content Include="App_Data\**" CopyToPublishDirectory="PreserveNewest" Exclude="App_Data\*.json" />
    <Content Update="App_Data\*.json" CopyToPublishDirectory="Never" />
    <Content Update="App_Data\DataProtectionKeys\*.xml" CopyToPublishDirectory="Never" />

    <Compile Remove="Plugins\**" />
    <EmbeddedResource Remove="Plugins\**" />
    <None Remove="Plugins\**" />

    <Content Include="Plugins\**" CopyToPublishDirectory="PreserveNewest" Exclude="Plugins\**\*.config;Plugins\**\*.cshtml;Plugins\**\*.json" />
    <Content Include="Themes\**" CopyToPublishDirectory="PreserveNewest" Exclude="Themes\**\*.config;Themes\**\*.cshtml;Themes\**\*.json" />

    <!-- We copy the \Logs directory -->
    <Content Include="Logs\**" CopyToPublishDirectory="PreserveNewest" />

    <None Update="Areas\Admin\sitemap.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>

  <ItemGroup>
    <Folder Include="Plugins\" />
  </ItemGroup>

  <!-- This target execute after "Build" target.
    We use it to clean up folder with plugins from unnecessary and obsolete libraries. -->
  <Target Name="NopTarget" AfterTargets="Build">
    <ItemGroup>
      <!-- Get plugin description files to get plugin paths -->
      <PluginsDescription Include="$(MSBuildProjectDirectory)\Plugins\**\plugin.json;" />      
      <!-- Get paths for all plugins -->
      <PluginsFolders Include="@(PluginsDescription->'%(relativedir)')" />

      <!-- Get all the libraries from the shadow copy folder to remove them,
        because depending on the settings, this may not happen when the application is starting,
        but this can lead to unpredictable results during debugging of the project. -->
      <ShadowCopiesLibraries Include="$(MSBuildProjectDirectory)\Plugins\bin\*.*" Exclude="$(MSBuildProjectDirectory)\Plugins\bin\placeholder.txt" />
    </ItemGroup>
    <PropertyGroup>
      <PluginsFolders>@(PluginsFolders)</PluginsFolders>
    </PropertyGroup>
    <!-- Delete libraries from the shadow copy folder -->
    <Delete Files="@(ShadowCopiesLibraries)" />
    <!-- When .NET Core builds a project, it copies all referenced libraries to the output folder.
      For plugins it creates too many unnecessary files that just take up space.
      At the moment you can't disable this behavior. That's why we have to manually delete all unnecessary libraries from plugin output directories. -->
    <MSBuild Projects="$(MSBuildProjectDirectory)\..\..\Build\ClearPluginAssemblies.proj" Properties="PluginPath=$(PluginsFolders)" Targets="NopClear" />
  </Target>

  <PropertyGroup>  
    <ConcurrentGarbageCollection>false</ConcurrentGarbageCollection>
  </PropertyGroup>

</Project> 
Run Code Online (Sandbox Code Playgroud)

Mar*_*und 1

这看起来更像是一个 dotnet 发布问题,而不是 docker 的实际问题。

如果您搜索 dotnet cli 显示MSB3073的实际错误,您会发现它通常与构建后事件相关。在许多情况下,构建后事件中引用的每个文件夹/程序集的路径不正确。

如果我们仔细看看执行发布命令时我们所处的位置

WORKDIR /app/Presentation/MyProject.Web
Run Code Online (Sandbox Code Playgroud)

然后例如查看错误消息中的 PluginPath

..PluginPath=/app/Presentation/MyProject.Web/Plugins/DiscountRules.CustomerRoles/;..
Run Code Online (Sandbox Code Playgroud)

然后您可以看到该路径不是从执行命令的位置内联的。

一种解决方案是添加绝对路径或使它们相对于执行发布命令的位置。您还可以为每个配置指定特定的后/前事件,这是有关发布事件的答案