ikvm icon indicating copy to clipboard operation
ikvm copied to clipboard

Solution Build

Open Xemrox opened this issue 6 months ago • 3 comments

Hi there,

using IKVM in a solution with multiple different projects referencing the same jar files. Somehting along these lines in my Directory.Build.props:

<ItemGroup Condition="'$(UseIKVM)' == 'true'">
  <IkvmReference Include="core-lib">
    <AssemblyName>~snip~</AssemblyName>
    <AssemblyVersion>~snip~</AssemblyVersion>
    <Compile>~snip1~.jar;~snip2~.jar;~snip3~.jar</Compile>
  </IkvmReference>
  <IkvmReference Include="utilities">
    <AssemblyName>~snip~</AssemblyName>
    <AssemblyVersion>~snip~</AssemblyVersion>
    <AssemblyFileVersion>~snip~</AssemblyFileVersion>
    <Compile>~snip~-utilities.jar</Compile>
    <References>core-lib</References>
  </IkvmReference>
  <IkvmReference Include="~snip-xyz~.jar">
    <AssemblyName>~snip~</AssemblyName>
    <AssemblyVersion>~snip~</AssemblyVersion>
    <AssemblyFileVersion>~snip~</AssemblyFileVersion>
    <References>core-lib;utilities</References>
  </IkvmReference>

  <PackageReference Include="IKVM" />
</ItemGroup>

This is working great so far! Using azure devops CI pipeline I am running into some parallel problems tough.

2025-06-13T<snip> ##[error]<snip>\.nuget\packages\ikvm\8.11.2\buildTransitive\IKVM.IkvmReference.Tasks.targets(31,9): Error MSB4018: Unerwarteter Fehler bei der IkvmCompiler-Aufgabe. [<snip>.csproj]
2025-06-13T<snip> ##[error]<snip>\.nuget\packages\ikvm\8.11.2\buildTransitive\IKVM.IkvmReference.Tasks.targets(31,9): Error MSB4018: System.IO.IOException: The process cannot access the file '<snip>\obj\Release\net9.0\ikvm\stage\1\ee4b3fafa395ae267b41da2dc39fc4df\<snip>.dll.log' because it is being used by another process. [<snip>.csproj]
2025-06-13T<snip> ##[error]<snip>\.nuget\packages\ikvm\8.11.2\buildTransitive\IKVM.IkvmReference.Tasks.targets(31,9): Error MSB4018: at Microsoft.Win32.SafeHandles.SafeFileHandle.CreateFile(String fullPath, FileMode mode, FileAccess access, FileShare share, FileOptions options) [<snip>.csproj]

Any ideas on how to fix that?

Xemrox avatar Jun 13 '25 15:06 Xemrox

So, here's what I notice. The path to the file is to the staging directory. That's within a single project. So, Project/obj/Release/net9.0.

The IKVM build system assumes, like every part of MSBuild, that the unique obj directory is not acccessed by multiple concurrent processes. Hence, we stage our files here, and then mark them for copy to their final location (the IKVM cache directory).

Your problem is you somehow are doing something that should never happen: building the same PROJECT, with the same Configuration and TFM, concurrently. The problem isn't accessing the JAR files: it's writing to the staging DLL output, which is unique per Project/Configuration/TFM.

wasabii avatar Jun 13 '25 15:06 wasabii

Good catch! Now I can see it too. Leaves me totally buffled though. From what I can see it's because I have multiple projects requesting the same dependency.

Output.csproj -> Main.csproj Other.csproj -> Main.csproj

This dependency might be transitive and our pipeline triggers the same build twice? Will report back if I find the source of the problem. Thanks!

Xemrox avatar Jun 16 '25 07:06 Xemrox

They should not, no. MSBuild runs a unique "copy" of each project for each set of Project and all unique GlobalProperties. Of which TFM/Configuration/Platform, etc, count. But transitive references do not pass different global properties. So, even if two projects reference one, that one would be called only once per unique combination of TFM/etc.

I would really need to see the rest of your build to have much of an idea beyond that.

wasabii avatar Jun 26 '25 19:06 wasabii