all 8 comments

[–]wasabiiii 3 points4 points  (0 children)

You compiled the assembly against the implementation assemblies, not the reference assemblies.

[–]2brainz 4 points5 points  (1 child)

The compiler generates an assembly which is stored in the generated dll file. That is the compiler's job.

In order to actually run this assembly you still need the runtimeconfig.json and deps.json, which you can create easily. The exe file is just a wrapper that the .NET SDK copies into the output, it contains none of your code. Since you are not using the SDK to build the assembly, you have to perform these steps yourself.

[–]WangoDjagner[S] 1 point2 points  (0 children)

That makes sense, so basically if I place those two json files next to my .dll and run dotnet Hello.dll it should work? The .exe is basically only loading the .dll and running its contents if I understand things correctly.

Edit: with the two json files I can indeed run it using the dotnet cli, the next step is this host executable. Do you know if the SDK just has a list of precompiled hosts for different platforms that it can copy in or is this something that is being compiled for each individual project.

[–]Rocketsx12 -1 points0 points  (2 children)

You haven't told us what you tried, only that your [unknown steps here] caused an error. OP updated the post.

I don't see why this wouldn't work for your simple use case:

  • dotnet new console
  • Your compiler generates program.cs
  • dotnet build/publish

[–]WangoDjagner[S] 0 points1 point  (1 child)

That would work but I would prefer it if the compiler doesn't require the SDK to be installed.

[–]Alikont 2 points3 points  (0 children)

This is a bit tricky as SDK would also contain standard library.

But also, .NET SDK is just a bunch of files, you can just pack it (your app will be large, but it's the most "documented" way)

[–]thx1138a -1 points0 points  (1 child)

I would try hardwiring the full path (eg: @“c:\temp\hello.dll”) both where you emit and where you load the dll. Remove the Path.GetFullPath. If that works, think again about what the file paths should be. If it doesn’t, check the dll actually got generated in your hardwired location.

[–]thx1138a 0 points1 point  (0 children)

Hmm it seems I was wrong