This is how things are with mono on linux. I can use the following commands from the bash command line and these two commands are all I need:
mcs -out:hello.exe hello.cs mono hello.exe
c-sharp/Vscode/ConsoleApp1.sln c-sharp/Vscode/ConsoleApp1 (directory) c-sharp/Vscode/ConsoleApp1/ConsoleApp1.csproj c-sharp/Vscode/ConsoleApp1/Program.cs c-sharp/Vscode/ConsoleApp1/obj c-sharp/Vscode/ConsoleApp1/obj/* c-sharp/Vscode/ConsoleApp1/bin c-sharp/Vscode/ConsoleApp1/bin/Debug/net8.0/ConsoleApp1.dll c-sharp/Vscode/ConsoleApp1/bin/*As a side note, some people call VS-code an editor, others call it an IDE. I call it an IDE given all this complexity. Of course I have also added the extension called C# Dev kit, so maybe that turns it into a sort of IDE.
I have another project in the vscode directory, namely:
vscode/Socket.sln vxcode/Socket/*It has pretty much the same layout as above.
But I can avoid VS-code alogether and build a project as follows:
cd c-sharp/Vscode dotnet build MSBuild version 17.8.5+b5265ef37 for .NET Determining projects to restore... Restored /u1/home/tom/c-sharp/Vscode/ConsoleApp1/ConsoleApp1.csproj (in 305 ms). ConsoleApp1 -> /u1/home/tom/c-sharp/Vscode/ConsoleApp1/bin/Debug/net8.0/ConsoleApp1.dllI still end up with the same .dll file, and it still depends on the .sln and .csproj files that VS-code set up for me.
dotnet new console -hBased on this, I try:
cd vscode dotnet new console -n fish dotnet build fishAnd this works! I compiles what is fish/Program.cs and gives me fish/bin/Debug/net8.0/fish.dll. So far I have avoided VS-code -- to run it is as easy as this:
cd fish/bin/Debug/net8.0 dotnet fish.dllOr better yet:
dotnet fish/bin/Debug/net8.0/fish.dllAs a note, I get no .sln file doing this (with suits me just fine, thank you).
A peeks at fish.csproj shows me that this is an XML file. It tells me this is net8.0 and I see no mention of Program.cs or any .cs file at all. Also it indicates that the OutputType is "Exe", but that declaration seems meaningless.
The only thing to sort out are C# details themselves. I keep Program.cs and add Fish.cs. Inside Fish.cs I have "namespace Tom" and in Program.cs I have "using Tom". The class inside should be called something else (like Fish)> The class name should not be the same as the namespace name apparently.
# Makefile for a dotnet C# project DLL=bin/Debug/net8.0/fish.dll all: run build: cd .. ; dotnet build fish run: build dotnet $(DLL)This is real progress. I can build, make, and run a new project via:
cd vscode dotnet new console -n fish cd fish # copy makefile into place and edit makeOf course I have to put the makefile into place before I can do the above. This allows me to use vim to edit Program.cs
dotnet fish.dll A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Users\Tom\'. Failed to run as a self-contained app. - The application was run as a self-contained app because 'C:\Users\Tom\fish.runtimeconfig.json' was not found. - If this should be a framework-dependent app, add the 'C:\Users\Tom\fish.runtimeconfig.json' file and specify the appropriate framework.That is too bad. Maybe the phrase "self contained app" will yield some kind of answer other than dragging along a bunch of extra dll files and .json files. There are useful tips here:
dotnet build -r linux-x64 dotnet publish -c release -r linux-x64The first generates the dll in the same place as always. And while the second puts things into the "bin" directory, we get no exe file. Ah, but wait!
cd Fish/bin/release/net8.0/linux-x64 ls -l -rwxr-xr-x 1 tom tom 72520 Sep 6 15:07 fish -rw-r--r-- 1 tom tom 4096 Sep 6 15:07 fish.dll file fish fish: ELF 64-bit LSB pie executable, x86-64And indeed, typing "./fish" runs the executable, givng the output I expect.
dotnet build -r win-x64 dotnet publish -c release -r win-x64Things go badly downhill from here and spiraled into a bunch of issues on my Windows machine that I have not yet unravelled. For the ongoing story, use this link:
Tom's Computer Info / tom@mmto.org