Is there a simple way of exporting a symbol/constant from .Net 5+ applications without having to install third-party NuGets? I'd like to do something like:
[DllExport("MySymbol")]
public static int MySymbol = 1234;
This would be the equivalent of exporting a symbol from C++:
extern "C" { __declspec(dllexport) extern const UINT MySymbol = 1234; }
I found some repositories that add unmanaged export capability, but I don't need to export classes or methods, but just a symbol, so if there's a way of doing this without adding a thousand lines of code or extra dependencies, it would be great.
This is the answer I'd have liked to see: .Net core applications are launched using a native host. Therefore, even if you manage to export symbols from the .Net assembly, they wouldn't be exported by the main executable of the running process.
In order to export symbols, the default native host needs to be replaced by a custom host using this documentation. In this case, the manifest and app icon/resources may also need to be included by the developer, since the native host is no longer automatically generated.