I creaated a sample .NET5 console application. Just a tiny sample creating some console entries.
using System;
using System.Threading;
namespace ConsoleApp21
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello from the sample app creating console lines!");
while (true)
{
Console.WriteLine("line ...");
Thread.Sleep(1000);
}
}
}
}
The build directory gives me following contents...
- /ref
- ConsoleApp21.exe
- ConsoleApp21.dll
- ConsoleApp21.pdb
- ConsoleApp21.deps.json
- ConsoleApp21.runtimeconfig.dev.json
- ConsoleApp21.runtimeconfig.json
Now if I would like to distribute the app to other users/pcs ...
Of course I want to keep the
- .exe (though I could start the dll directly via the CLI)
- .dll
I know I can remove (or disable the creation of)
- /ref (reference assemblies)
- .pdb (debug symbols)
Testing I could also delete
- .runtimeconfig.dev.json
But why does the application can not run without the 2 json files? It absolutely makes no sense for me to have 2 additional config files.
- .runtimeconfig.json
- .deps.json
Any chances beside self containing builds (which afaik include the whole .NET runtime into the directory) I can run the app only with the .exe and .dll?
Shouldn't the dll know what dependencies it has (deps.json) and find the .NET runtime somehow in a default manner? (I hope I understood the meaning of those two correctly).
You need to add the following line to your project file:
and then you need to publish the project, not just compile. It will provide another executable with everything in it. See here for more details.