ikvm icon indicating copy to clipboard operation
ikvm copied to clipboard

Customizing ikvm.home with User setting before initialization

Open except11 opened this issue 1 year ago • 3 comments

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

except11 avatar Aug 22 '24 08:08 except11

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 avatar Aug 22 '24 18:08 wasabii

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

wasabii avatar Aug 22 '24 18:08 wasabii

Yes, I did it like this <Target Name="ReplaceIkvmProperties" AfterTargets="GetDefaultIkvmPropertiesFile"> <ItemGroup> <None Remove="@(None)" Condition="'%(Extension)'=='.properties'" /> <Content Remove="@(Content)" Condition="'%(Extension)'=='.properties'" /> <None Include="ikvm.properties"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> <Message Text="Replaced ikvm.properties @(None)" Importance="high" /> </Target>

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

except11 avatar Aug 26 '24 07:08 except11