ikvmnet / ikvm

A Java Virtual Machine and Bytecode-to-IL Converter for .NET
Other
1.23k stars 111 forks source link

Customizing ikvm.home with User setting before initialization #580

Open except11 opened 3 weeks ago

except11 commented 3 weeks ago

Hi, I was trying to use User settings to override ikvm.home.root since I saw in code IKVM checking it first

I am doing it like this IKVM.Runtime.JVM.Properties.User.Add("ikvm.home.root", "ikvm-root");

But to do it system tries to construct static objects and tries to get home path before I can set it

System.TypeInitializationException: The type initializer for 'Internal' threw an exception. ---> IKVM.Runtime.InternalException: Could not locate ikvm home path. at IKVM.Runtime.JVM.Properties.GetHomePath() at System.Lazy1.ViaFactory(LazyThreadSafetyMode mode) at System.Lazy1.ExecutionAndPublication(LazyHelper executionAndPublication, Boolean useDefaultConstructor) at System.Lazy`1.CreateValue() at IKVM.Runtime.JVM.Internal..cctor() --- End of inner exception stack trace --- at IKVM.Runtime.JVM.Init() at IKVM.Runtime.RuntimeInit.Init() at .cctor()

I managed to solve my problem by adding PrivateAssets="buildTransitive" to reference and copying bunch of assets myself, since I can't just replace ikvm.properties - its added to build forcefully, and I want my own version.

Maybe add ikvm.user.properties for this purpose or something? Currently it looks you can customize the path in different ways but none of them actually work as is

wasabii commented 3 weeks ago

You can just use the build script to lay down your own ikvm.properties. But yeah, we can't do any code-based dynamic lookup of this because module inits happen before everything. On Framework, app.config works since it's loaded by the framework. We could find a similar thing for Core.

wasabii commented 3 weeks ago

Replacing ikvm.properties shouldn't be that hard though. You should probably just be able to override the target that lays it down.

except11 commented 3 weeks ago

Yes, I did it like this `

Always

`

And its working while building, but I want to keep java stuff in a separate project and I reference it from bunch of other projects, and when I publish main project I still get Found multiple publish output files with the same relative path. So I had to also specify PrivateAssets="buildTransitive" in IKVM reference since I don't want to change main project's csproj file