J'essaie d'exécuter mon application ASP.NET Core 2.1 avec l'image de menu fixe. Pour cela, j'ai un fichier docker avec le contenu suivant:
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"]
Mais quand on exécute la commande docker build -t MyProject-web .
, cela me donne une erreur:
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
Edit 1: Voici la structure de mon projet:
Build
ClearPluginAssemblies
Libraries
MyProject.Core
MyProject.Data
MyProject.Services
Plugins
MyProject.Plugin.Discount
MyProject.Plugin.Payment
..
Presentation
MyProject.Web
MyProject.Web.Framework
Tests
Edit: 2 Fichier de projet 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>
Cela ressemble plus à un problème de publication de dotnet qu'à un problème de docker.
Si vous recherchez sur l’erreur réelle que dotnet cli affiche MSB3073, vous constaterez qu’elle est souvent liée à des événements post-construction . Pas correcte.
Si nous regardons de plus près où nous en sommes lorsque la commande de publication est exécutée
WORKDIR /app/Presentation/MyProject.Web
Et puis, par exemple, regardez le PluginPath dans le message d'erreur
..PluginPath=/app/Presentation/MyProject.Web/Plugins/DiscountRules.CustomerRoles/;..
Vous pouvez alors voir que le chemin n'est pas en ligne à partir duquel la commande est exécutée.
Une solution consisterait à ajouter un chemin absolu ou à les rendre relatifs par rapport à l'endroit où la commande de publication est exécutée. Vous pouvez également spécifier un post/pré-événement spécifique pour chaque configuration, voici une réponse concernant publish-events