RFC; [PATCH] Add ikvm.props to the NuGet Package to Copy Native Binaries

Christopher Boumenot <[email protected]> Sun, 30 Aug 2015 23:24:42 -0700
Newsgroups gmane.comp.java.ikvm.devel
Message-ID <CAOZeni7vaDtRTmNJq=wjF2tFHTqgs1cXLMtYr7P0oEggrfBTjw@mail.gmail.com>
I am developing a project that uses IKVM that has to access native
binaries.  In my project I reference ikvm-native-win32-x64.dll and
JVM.dll in my project, but I am trying to figure out how to make this
easier when I ship my project as a NuGet package to end-users.  I
would prefer if end users just install the NuGet package, and the
binaries end up in the build output directory.  This is not true for
IKVM (in the case of these binaries), and instead I need to rely on
the end user referencing the ikvm-native-win32-x64.dll and JVM.dll or
putting it in their load path.  One solution that I have seen (from
libgit2sharp.nativebinaries) is to create a props files that copies
the native binaries to the build output directory.  This provides a
well-defined location for my project to load these necessary binaries
without the user having to take action.  This also makes it easier to
consume my project in LINQPad without having to manually call out
binaries.

Is there a preferred solution to this problem or any ideas on how to
best solve it?  I have attached a patch that implements the props
solution.  Any feedback is appreciated.



Thanks,
Christopher

------------------------------------------------------------------------------

_______________________________________________
Ikvm-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ikvm-developers
0001-Add-props-file-to-NuGet-package.patch (application/octet-stream, 2.4 KB)
From 34dee31a9b7f68df6fdd8243a13f33f650984e88 Mon Sep 17 00:00:00 2001
From: Christopher Boumenot <[email protected]>
Date: Sun, 30 Aug 2015 22:41:17 -0700
Subject: [PATCH] Add props file to NuGet package.

---
 nuget/ikvm.props  | 25 +++++++++++++++++++++++++
 nuget/nupkg.build |  1 +
 2 files changed, 26 insertions(+)
 create mode 100644 nuget/ikvm.props

diff --git a/nuget/ikvm.props b/nuget/ikvm.props
new file mode 100644
index 0000000..6747516
--- /dev/null
+++ b/nuget/ikvm.props
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    <ItemGroup>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x64\lib\ikvm-native-win32-x64.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x64\lib\ikvm-native-win32-x64.dll">
+            <Link>native\x64\lib\ikvm-native-win32-x64.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x64\lib\JVM.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x64\lib\JVM.dll">
+            <Link>native\x64\lib\JVM.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x86\lib\ikvm-native-win32-x86.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x86\lib\ikvm-native-win32-x86.dll">
+            <Link>native\x86\lib\ikvm-native-win32-x86.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x86\lib\JVM.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x86\lib\JVM.dll">
+            <Link>native\x86\lib\JVM.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+    </ItemGroup>
+</Project>
diff --git a/nuget/nupkg.build b/nuget/nupkg.build
index 8545ee6..bec6e5b 100644
--- a/nuget/nupkg.build
+++ b/nuget/nupkg.build
@@ -68,6 +68,7 @@
         <copy file="../bin/ikvm-native-win32-x86.dll" todir="Package/x86/lib" />
         <copy file="../bin-x64/JVM.DLL" todir="Package/x64/lib" />
         <copy file="../bin-x86/JVM.DLL" todir="Package/x86/lib" />
+        <copy file="ikvm.props" todir="Package/build" />
     </target>
 
     <target name="nupkg" depends="clean Package IKVM.nuspec">
-- 
1.9.5.msysgit.0
0001-Add-props-file-to-NuGet-package.patch (application/octet-stream, 2.4 KB)
From 34dee31a9b7f68df6fdd8243a13f33f650984e88 Mon Sep 17 00:00:00 2001
From: Christopher Boumenot <[email protected]>
Date: Sun, 30 Aug 2015 22:41:17 -0700
Subject: [PATCH] Add props file to NuGet package.

---
 nuget/ikvm.props  | 25 +++++++++++++++++++++++++
 nuget/nupkg.build |  1 +
 2 files changed, 26 insertions(+)
 create mode 100644 nuget/ikvm.props

diff --git a/nuget/ikvm.props b/nuget/ikvm.props
new file mode 100644
index 0000000..6747516
--- /dev/null
+++ b/nuget/ikvm.props
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+    <ItemGroup>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x64\lib\ikvm-native-win32-x64.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x64\lib\ikvm-native-win32-x64.dll">
+            <Link>native\x64\lib\ikvm-native-win32-x64.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x64\lib\JVM.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x64\lib\JVM.dll">
+            <Link>native\x64\lib\JVM.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x86\lib\ikvm-native-win32-x86.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x86\lib\ikvm-native-win32-x86.dll">
+            <Link>native\x86\lib\ikvm-native-win32-x86.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+        <None Condition="Exists('$(MSBuildThisFileDirectory)\..\x86\lib\JVM.dll')" 
+              Include="$(MSBuildThisFileDirectory)\..\x86\lib\JVM.dll">
+            <Link>native\x86\lib\JVM.dll</Link>
+            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+        </None>
+    </ItemGroup>
+</Project>
diff --git a/nuget/nupkg.build b/nuget/nupkg.build
index 8545ee6..bec6e5b 100644
--- a/nuget/nupkg.build
+++ b/nuget/nupkg.build
@@ -68,6 +68,7 @@
         <copy file="../bin/ikvm-native-win32-x86.dll" todir="Package/x86/lib" />
         <copy file="../bin-x64/JVM.DLL" todir="Package/x64/lib" />
         <copy file="../bin-x86/JVM.DLL" todir="Package/x86/lib" />
+        <copy file="ikvm.props" todir="Package/build" />
     </target>
 
     <target name="nupkg" depends="clean Package IKVM.nuspec">
-- 
1.9.5.msysgit.0