Closed kdaek21 closed 1 week ago
There's no such thing as a managed EXE for .Net Core. You must generate a DLL and then assemble a launcher some other way.
There's no such thing as a managed EXE for .Net Core. You must generate a DLL and then assemble a launcher some other way.
I analyzed the part where ikvmReference uses ikvmc and found a way to compile it.
When ikvmReference uses ikvmc, it includes the -nostdlib option, so I tried using it with the -nostdlib option and ikvmc as shown below, and it compiled without any errors. (I think the error occurs because it automatically tries to use the standard mscorlib when used without the -nostdlib option..)
ikvmc -target:exe -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -runtime:"C:\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -nostdlib Test.class
And as you answered, .net core creates a .dll with a dedicated launcher file for the environment built (or specified) during the build, so even if you compile it as above and an exe is created, an error occurs when you run it directly, so you have no choice but to use it in the dotnet file.exe format.
You need to compile it in the format below so that it cannot be run directly and use it in the dotnet file.dll format. (Of course, after manually creating the [file name].runtimeconfig.json file)
ikvmc -target:library -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -runtime:"C:\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -nostdlib -main:Test Test.class
.Net Core has detailed references, so if you want to statically convert something more complex, you need to add a few more references.
Additionally, if you try to use it in the format of ikvmc -target:library -lib:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0" -r:System.Runtime.dll -runtime:"C:\ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" -nostdlib -main:Test Test.class, an error may occur.
After finding out how to use ikvmc directly for net472 version, I am looking for how to use ikvmc for net6.0 and net8.0.. (* I found a case where there is a difference between using ikvmc to statically convert Java classes to CIL and using ikvmReference to statically convert and use it as a library in .NET code, so I need to use ikvmc directly..)
First, I tested it and successfully converted it
ikvmc -target:exe -r:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.dll" -r:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.dll" -lib:"C:\Windows\Microsoft.NET\Framework64\v4.0.30319" -runtime:"C:\ikvm-jre8-net472\bin\IKVM.Runtime.dll" Test.class
Refer to
ikvmc -target:exe -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\ net8.0\System.Runtime.dll" -lib:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0" -runtime:"C: \ikvm-jre8-net8.0\bin\IKVM.Runtime.dll" Test.class
I tried it in the format, but the following error occurred.
COMPILER ERROR
IKVM.Tools.Importer, Version=8.10.3.0, Culture=neutral, PublicKeyToken=13235d27fcbfff58 D:\IKVM-8.10.3-tools-net8.0-win-x64\ 8.0.10 64-bit
System.IO.FileNotFoundException: System.Runtime at IKVM.Reflection.Universe.Load(String refname, Module requestingModule, Boolean throwOnError) in //src/IKVM.Reflection/Universe.cs:line 595 at IKVM.Tools.Importer.AssemblyResolver.Init(Universe universe, Boolean nostdlib, IList
1 references, IList
1 userLibPaths) in //src/IKVM.Tools.Importer/AssemblyResolver.cs:line 88 at IKVM.Tools.Importer.IkvmImporterInternal.Compile(String[] args) in //src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 180 at IKVM.Tools.Importer.IkvmImporterInternal.Execute(String[] args) in //src/IKVM.Tools.Importer/IkvmImporterInternal.cs:line 113As shown below, it seems that you can build the .NET Core app directly by finding the compiler and inserting the .NET source file without the dotnet build command.
dotnet "C:\Program Files\dotnet\sdk\8.0.403\Roslyn\bincore\csc.dll" -target:exe -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll" -r:"C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Console.dll" TestProg.cs
The reference 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.10\ref\net8.0\System.Runtime.dll' appears to be correct.
Is there no way to use ikvmc for static conversion for .NET Core?
IKVM-tools doesn't seem to be for net6.0, so I tried it for net6.0 by setting up IKVM-jre and references, but the same error occurred.
I found information on how to compile .NET Core source files directly on the Internet, and I figured it out after combining them and trying it out.