How to Build Multiple Binaries from Dotnet New Console?
I have the following:
I move
Program.cs
to src/Program.cs
and it still seems to work. I replace src/Program.cs
with src/echo.cs
with the following:
This is note-box.csproj
:
I see there's the executable note-box
and it behaves like echo
when I pass args. When I add a second main
entry point, src/true.cs
:
It errors. The goal is to have echo
and 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
:
This would do something like ./bin/note-box echo
or ./bin/note-box true
. If this approach is better, I would want to make symlinks to note-box
and have the name of the link be what it calls. In C it's something like:
I'm not sure how to resolve link name of executable in a C# way.12 Replies
if you want 2 programs you need 2 projects
or one program with an argument to select the behavior like you have
I want two exe
csproj should be able to be configured to build that
The POSIX C library gives strrchr to resolve real name of link. e.g. If I
ln -sf note-box bin/echo
Calling ./bin/echo
will results in strrchr(argv[0], '/')
returning the name of the link.
The idea is to be able to call the symbolic link ./bin/echo
instead of ./bin/note-box echo
It looks like each exe needs a csproj, so im learning towards the one main entry point approach
I just don't know how to resolve link names in C# IOi'm missing how strrchr has anything to do with symlinks
that's a string search function
Environment.GetCommandLineArgs()
gives you the equivalent of argv
in Cah i see
i looked into ISO / IEC 9899:1999 a little more and found strrchr returns points to last known path starting with what was specified in second arg
From ISO/IEC 9899:1999
let's say I have this:
And the goal is calling
./bin/<util>
shall invoke ./bin/note-box <util>
to call that util.is there a particular reason you want it to work like this compared to calling the program with an argument?
Yes. The idea is to be able to call
./bin/echo
instead of ./bin/note-box echo
^^but why?
because that is the design scope
i want to try and write something like this https://github.com/astralchan/astral-box in c# / dotnet. something to tinker with ^^
Maybe
System.Environment
has something to read link path. I'll check ^^i mean it does, the thing i told you to use will get you the command line arguments including the path used to run the executable
the same way the first element of argv would
Okay, I'll try it out ^^
hmm,
GetCommandLineArgs()
gives me argv
. I found Environment.CommandLine
, which gives /home/amber/dox/dev/note-box.git/main/bin/Debug/net8.0/note-box.dll true
.
I'll see if I can tinker around and get only the second part of it
I found a solution 😃
That only seemed to work when passing it as an arg
i tried making a symlink and errored its out of bounds
I tried this:
which gives me note-box.dll
at the moment I just manually made the link:
This seems to work, too:
ill brb imma tinker with system.environment and see if theres something to read link namesi'm not sure why you're doing this, i thought you wanted the path used to execute the file?
if you want the program arguments just use the
args
array you get in MainI have this generator:
I can't seem to get it to build - smthn with the csproj:
This is csproj of one level up: