Home > Software design >  C# .Net 6.0 App's Console.WriteLine not output to /bin/bash on Linux
C# .Net 6.0 App's Console.WriteLine not output to /bin/bash on Linux

Time:02-04

I'm running into trouble with the following steps:

  1. Create a simple C# .net 6 console app with the Hello World boilerplate, and publish the portable binaries locally.
  2. Create a docker container based on mcr.microsoft.com/dotnet/sdk:6.0
  3. Copy the publish results to the container in a consoleapp directory.
  4. Open an interactive session to the container
  5. Execute /consoleapp/ConsoleApp1.exe

No error, but no result. Here's the (only) code in the app:

Console.WriteLine("Hello, World!");

I'm expecting to see:

Hello, World!

I feel like I'm missing something incredibly simple...any help would be appreciated.

CodePudding user response:

The .exe file is only for Windows. In the container (running on Linux) you start your app with

dotnet ConsoleApp1.dll

In this case your Dockerfile would look like this:

FROM mcr.microsoft.com/dotnet/runtime:6.0

WORKDIR /app
COPY bin/Release/net6.0/publish/* .

CMD ["dotnet", "ConsoleApp1.dll"]
  •  Tags:  
  • Related