I have a fairly simple .net Core C# project with a .proto
file. The .csproj
looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RootNamespace>My.Overview</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Protobuf Include="..\..\Protos\overview.proto" GrpcServices="Both" Link="Protos\overview.proto" />
</ItemGroup>
<Import Project="..\..\.paket\Paket.Restore.targets" />
</Project>
I have referenced this in an ASP.net Core 3.1 project, and I use Paket for resolution of dependencies.
When I compile this from Visual Studio or dotnet build
everything works fine.
However I also want to build the service as a Docker container. The relevant portion of the Dockerfile looks like this:
RUN dotnet tool install -g paket
ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/.dotnet/tools
COPY paket.dependencies /build/
COPY paket.lock /build/
WORKDIR /build
RUN paket install
COPY . /build
RUN dotnet publish -c Release AppThatUses.My.Overview
When I docker build
, I get this:
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: The specified task executable "/root/.nuget/packages/grpc.tools/2.29.0/tools/linux_x64/protoc" could not be run. System.ComponentModel.Win32Exception (13): Permission denied [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.Start() [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.Execute() [/build/Model/Overview/Overview.csproj]
The command '/bin/sh -c dotnet publish -c Release AppThatUses.My.Overview' returned a non-zero code: 1
I investigated this and I saw that protoc
was not executable, so I added this line just before the dotnet publish
:
RUN find /root/.nuget/packages -name protoc |grep linux |xargs chmod +x
Now, I get:
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: The specified task executable "/root/.nuget/packages/grpc.tools/2.29.0/tools/linux_x64/protoc" could not be run. System.ComponentModel.Win32Exception (2): No such file or directory [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at System.Diagnostics.Process.Start() [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/build/Model/Overview/Overview.csproj]
/root/.nuget/packages/grpc.tools/2.29.0/build/_protobuf/Google.Protobuf.Tools.targets(264,5): error MSB6003: at Microsoft.Build.Utilities.ToolTask.Execute() [/build/Model/Overview/Overview.csproj]
I triple-checked that /build/Model/Overview/Overview.csproj
is actually there.
What am I missing?
Not a bugfix but a workaround:
dotnet tool install
are not executableSo, here's what I did:
mcr.microsoft.com/dotnet/core/sdk:3.1-buster
instead of mcr.microsoft.com/dotnet/core/sdk:3.1-alpine
dotnet build
:
RUN chmod -Rf +x /root/.nuget/packages/grpc.tools/2.29.0/tools
With these changes in place, the build works.