© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
38 replies
astral

How to Build Multiple Binaries from Dotnet New Console?

I have the following:

$ dotnet new console
$ dotnet run
Hello, world!
$ dotnet new console
$ dotnet run
Hello, world!


I move
Program.cs
Program.cs
to
src/Program.cs
src/Program.cs
and it still seems to work. I replace
src/Program.cs
src/Program.cs
with
src/echo.cs
src/echo.cs
with the following:

using System;

class Echo {
    public static void Main(string[] args) {
        foreach (string arg in args) {
            Console.Write(arg);
            // Put space if not last argument
            if (arg != args[args.Length - 1]) {
                Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
};
using System;

class Echo {
    public static void Main(string[] args) {
        foreach (string arg in args) {
            Console.Write(arg);
            // Put space if not last argument
            if (arg != args[args.Length - 1]) {
                Console.Write(" ");
            }
            Console.WriteLine();
        }
    }
};


This is
note-box.csproj
note-box.csproj
:
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>

</Project>


I see there's the executable
note-box
note-box
and it behaves like
echo
echo
when I pass args. When I add a second
main
main
entry point,
src/true.cs
src/true.cs
:
class True {
  public static void Main() {
    System.exit(0);
  }
};
class True {
  public static void Main() {
    System.exit(0);
  }
};


It errors. The goal is to have
echo
echo
and
true
true
be two different programs.

Another solution that I'm not sure if will work is if I just have one entry point:

src/note-box.cs
src/note-box.cs
:
using System;

class NoteBox {
    public static void Main(string[] args) {
        switch (args[0]) {
        case "echo":
            // Call echo
            break;
        case "true":
            // Call true
            break;
        }
    }
};
using System;

class NoteBox {
    public static void Main(string[] args) {
        switch (args[0]) {
        case "echo":
            // Call echo
            break;
        case "true":
            // Call true
            break;
        }
    }
};


This would do something like
./bin/note-box echo
./bin/note-box echo
or
./bin/note-box true
./bin/note-box true
. If this approach is better, I would want to make symlinks to
note-box
note-box
and have the name of the link be what it calls. In C it's something like:

    char *cmd = strrchr(argv[0], '/');
    cmd = cmd ? cmd + 1 : argv[0];
    char *cmd = strrchr(argv[0], '/');
    cmd = cmd ? cmd + 1 : argv[0];


I'm not sure how to resolve link name of executable in a C# way.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

dotnet new console
C#CC# / help
4y ago
✅ How to use dotnet new console in terminal?
C#CC# / help
3y ago
❔ how do i make "dotnet new console" work
C#CC# / help
3y ago
❔ dotnet build
C#CC# / help
4y ago