Skip to content

Commit

Permalink
[Java.Interop] Target .NET Standard 2.0
Browse files Browse the repository at this point in the history
We would like to be able to build [xamarin-android][0]'s
`Xamarin.Android.sln` within Visual Studio (Windows).

@joj believes that the difficulty is "caused" by
`src/Java.Interop/Java.Interop.csproj` being a PCL project, and thus
if we migrated our PCL projects to instead use .NET Standard the
difficulties would be resolved.

Update `Java.Interop`, `Java.Interop.Dynamic`, `Java.Interop.Export`,
and `Java.Interop.GenericMarshaler` to be .NET Standard 2.0 projects
instead of PCL projects.

This in turn requires updating *every other project* to have a
`$(TargetFrameworkVersion)` value of v4.6.1 (or later) so that they
can reference .NET Standard 2.0 libraries.

Additionally, `make fxcop` and related need to be updated, as the
output paths for .NET Standard 2.0 builds has changed.

Migrating to .NET Standard 2 *also* impacts the downstream
xamarin-android repo: building `xamarin-android/src/Mono.Android`
would fail:

	Microsoft.NuGet.targets(184,5): error : Your project is not referencing the "MonoAndroid,Version=v1.0" framework. Add a reference to "MonoAndroid,Version=v1.0" in the "frameworks" section of your project.json, and then re-run NuGet restore.

The fix for this is twofold:

 1. Provide a new `Java.Interop-MonoAndroid.csproj` file for use by
    the `xamarin-android/src/Mono.Android` build [^1], and

 2. *Override* the `$(BaseIntermediateOutputPath)` MSBuild property.
    `$(BaseIntermediateOutputPath)` is used to find the
    `project*.json` files within `Microsoft.NuGet.targets`, and
    altering `$(BaseIntermediateOutputPath)` thus prevents the
    `project*.json` files from being found, allowing the build to
    succeed.

Finally, building .NET Standard 2 projects often requires that the
`msbuild /restore` or `msbuild /t:Restore` commands be used.
Integrate `msbuild /t:Restore` into `make prepare`, and fix the
`src/java-interop` project so that `msbuild /t:Restore` works without
emitting errors.

[0]: https://github.com/xamarin/xamarin-android/

[^1]: The following patch needs to be applied to `xamarin-android`
      when performing the next `Java.Interop` submodule bump:

diff --git a/src/Mono.Android/Mono.Android.targets b/src/Mono.Android/Mono.Android.targets
index 1d7e0c1a..848a3f63 100644
--- a/src/Mono.Android/Mono.Android.targets
+++ b/src/Mono.Android/Mono.Android.targets
@@ -20,7 +20,7 @@
       </_GlobalProperties>
     </PropertyGroup>
     <MSBuild
-        Projects="$(JavaInteropFullPath)\src\Java.Interop\Java.Interop.csproj"
+        Projects="$(JavaInteropFullPath)\src\Java.Interop\Java.Interop-MonoAndroid.csproj"
         Properties="$(_GlobalProperties)"
     />
     <ItemGroup>
  • Loading branch information
jonpryor authored and radekdoulik committed Dec 10, 2018
1 parent 706e4cc commit 85be94f
Show file tree
Hide file tree
Showing 43 changed files with 265 additions and 428 deletions.
15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,17 @@ run-all-tests: run-tests run-test-jnimarshal run-test-generator-core run-ptests

include build-tools/scripts/msbuild.mk

prepare:: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config

prepare:: prepare-bootstrap
$(MSBUILD) $(MSBUILD_FLAGS) /t:Restore Java.Interop.sln

prepare-bootstrap: prepare-external bin/Build$(CONFIGURATION)/Java.Interop.BootstrapTasks.dll

bin/Build$(CONFIGURATION)/Java.Interop.BootstrapTasks.dll: build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks.csproj \
external/xamarin-android-tools/src/Xamarin.Android.Tools.AndroidSdk/Xamarin.Android.Tools.AndroidSdk.csproj \
$(wildcard build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks/*.cs)
$(MSBUILD) $(MSBUILD_FLAGS) "$<"
$(MSBUILD) $(MSBUILD_FLAGS) /restore "$<"

prepare-external $(PREPARE_EXTERNAL_FILES): $(PACKAGES) $(NUNIT_CONSOLE)
git submodule update --init --recursive
Expand All @@ -82,15 +85,13 @@ else
JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD = '/@JAVA_RUNTIME_ENVIRONMENT_DLLMAP@/ {' -e 'r $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE)' -e 'd' -e '}'
endif

prepare:: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config

src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config.in \
bin/Build$(CONFIGURATION)/JdkInfo.props
sed -e 's#@JI_JVM_PATH@#$(JI_JVM_PATH)#g' -e 's#@OS_NAME@#$(DLLMAP_OS_NAME)#g' -e $(JAVA_RUNTIME_ENVIRONMENT_DLLMAP_OVERRIDE_CMD) < $< > $@

fxcop: lib/gendarme-2.10/gendarme.exe bin/GendarmeDebug/Java.Interop.dll
cp src/Java.Interop/obj/Gendarme/Java.Interop.dll.mdb bin/GendarmeDebug/
$(RUNTIME) $< --html gendarme.html $(if @(GENDARME_XML),--xml gendarme.xml) --ignore gendarme-ignore.txt bin/GendarmeDebug/Java.Interop.dll
fxcop: lib/gendarme-2.10/gendarme.exe bin/GendarmeDebug/netstandard2.0/Java.Interop.dll
cp src/Java.Interop/obj/Gendarme/netstandard2.0/Java.Interop.dll.mdb bin/GendarmeDebug/netstandard2.0
$(RUNTIME) $< --html gendarme.html $(if @(GENDARME_XML),--xml gendarme.xml) --ignore gendarme-ignore.txt bin/GendarmeDebug/netstandard2.0/Java.Interop.dll

lib/gendarme-2.10/gendarme.exe:
-mkdir -p `dirname "$@"`
Expand Down Expand Up @@ -127,7 +128,7 @@ bin/Test$(CONFIGURATION)/Android.Interop-Tests.dll: $(wildcard src/Android.Inter
bin/$(CONFIGURATION)/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
$(MSBUILD) $(if $(V),/v:diag,) /p:Configuration=$(CONFIGURATION) $(if $(SNK),"/p:AssemblyOriginatorKeyFile=$(SNK)",)

bin/GendarmeDebug/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
bin/GendarmeDebug/netstandard2.0/Java.Interop.dll: $(wildcard src/Java.Interop/*/*.cs) src/Java.Interop/Java.Interop.csproj
$(MSBUILD) $(if $(V),/v:diag,) /p:Configuration="Gendarme" $(if $(SNK),"/p:AssemblyOriginatorKeyFile=$(SNK)",) /p:CscToolExe=`which mcs` src/Java.Interop/Java.Interop.csproj

CSHARP_REFS = \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.BootstrapTasks</RootNamespace>
<AssemblyName>Java.Interop.BootstrapTasks</AssemblyName>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion samples/Hello/Hello.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Exe</OutputType>
<RootNamespace>Hello</RootNamespace>
<AssemblyName>Hello</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
45 changes: 8 additions & 37 deletions src/Java.Interop.Dynamic/Java.Interop.Dynamic.csproj
Original file line number Diff line number Diff line change
@@ -1,54 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{AD4468F8-8883-434B-9D4C-E1801BB3B52A}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Dynamic</RootNamespace>
<AssemblyName>Java.Interop.Dynamic</AssemblyName>
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.Dynamic</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Java.Interop.Dynamic\DynamicJavaClass.cs" />
<Compile Include="Java.Interop.Dynamic\DynamicJavaInstance.cs" />
<Compile Include="Java.Interop.Dynamic\JavaClassInfo.cs" />
<Compile Include="Java.Interop.Dynamic\JavaConstructorInfo.cs" />
<Compile Include="Java.Interop.Dynamic\JavaFieldInfo.cs" />
<Compile Include="Java.Interop.Dynamic\JavaInstanceProxy.cs" />
<Compile Include="Java.Interop.Dynamic\JavaMemberInfo.cs" />
<Compile Include="Java.Interop.Dynamic\JavaMethodBase.cs" />
<Compile Include="Java.Interop.Dynamic\JavaMethodInfo.cs" />
<Compile Include="Java.Interop.Dynamic\JniMetaObject.cs" />
<Compile Remove="Tests\**\*.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>
Expand Down
27 changes: 0 additions & 27 deletions src/Java.Interop.Dynamic/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.DynamicTests</RootNamespace>
<AssemblyName>Java.Interop.Dynamic-Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
35 changes: 8 additions & 27 deletions src/Java.Interop.Export/Java.Interop.Export.csproj
Original file line number Diff line number Diff line change
@@ -1,44 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{B501D075-6183-4E1D-92C9-F7B5002475B1}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop</RootNamespace>
<AssemblyName>Java.Interop.Export</AssemblyName>
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.Export</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>full</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Java.Interop\JavaCallableAttribute.cs" />
<Compile Include="Java.Interop\MarshalMemberBuilder.cs" />
<Compile Remove="Tests\**\*.cs" />
<Compile Remove="Java.Interop\JniLocationException.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>
Expand Down
22 changes: 0 additions & 22 deletions src/Java.Interop.Export/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,50 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<TargetFramework>netstandard2.0</TargetFramework>
<ProjectGuid>{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}</ProjectGuid>
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.GenericMarshaler</RootNamespace>
<AssemblyName>Java.Interop.GenericMarshaler</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
<AssemblyTitle>Java.Interop.GenericMarshaler</AssemblyTitle>
<Company>Microsoft Corporation</Company>
<Copyright>Microsoft Corporation</Copyright>
<AssemblyVersion>0.1.0.0</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.cs">
<DependentUpon>Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.tt</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.cs</LastGenOutput>
</None>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>
Expand Down
26 changes: 0 additions & 26 deletions src/Java.Interop.GenericMarshaler/Properties/AssemblyInfo.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Tools.Cecil</RootNamespace>
<AssemblyName>Java.Interop.Tools.Cecil</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Tools.Diagnostics</RootNamespace>
<AssemblyName>Java.Interop.Tools.Diagnostics</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Tools.JavaCallableWrappers</RootNamespace>
<AssemblyName>Java.Interop.Tools.JavaCallableWrappers</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>Library</OutputType>
<RootNamespace>Java.Interop.Tools.JavaCallableWrappersTests</RootNamespace>
<AssemblyName>Java.Interop.Tools.JavaCallableWrappers-Tests</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down
1 change: 1 addition & 0 deletions src/Java.Interop/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Java.Interop/JniEnvironment.g.cs
obj-MonoAndroid
Loading

0 comments on commit 85be94f

Please sign in to comment.