Skip to content

Commit 85be94f

Browse files
jonpryorradekdoulik
authored andcommitted
[Java.Interop] Target .NET Standard 2.0
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>
1 parent 706e4cc commit 85be94f

File tree

43 files changed

+265
-428
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+265
-428
lines changed

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,17 @@ run-all-tests: run-tests run-test-jnimarshal run-test-generator-core run-ptests
5151

5252
include build-tools/scripts/msbuild.mk
5353

54+
prepare:: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
55+
5456
prepare:: prepare-bootstrap
57+
$(MSBUILD) $(MSBUILD_FLAGS) /t:Restore Java.Interop.sln
5558

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

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

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

85-
prepare:: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config
86-
8788
src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config: src/Java.Runtime.Environment/Java.Runtime.Environment.dll.config.in \
8889
bin/Build$(CONFIGURATION)/JdkInfo.props
8990
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) < $< > $@
9091

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

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

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

133134
CSHARP_REFS = \

build-tools/Java.Interop.BootstrapTasks/Java.Interop.BootstrapTasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<OutputType>Library</OutputType>
88
<RootNamespace>Java.Interop.BootstrapTasks</RootNamespace>
99
<AssemblyName>Java.Interop.BootstrapTasks</AssemblyName>
10-
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
10+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1111
<ProductVersion>8.0.30703</ProductVersion>
1212
<SchemaVersion>2.0</SchemaVersion>
1313
</PropertyGroup>

samples/Hello/Hello.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<OutputType>Exe</OutputType>
1010
<RootNamespace>Hello</RootNamespace>
1111
<AssemblyName>Hello</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1313
</PropertyGroup>
1414
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1515
<DebugSymbols>true</DebugSymbols>

src/Java.Interop.Dynamic/Java.Interop.Dynamic.csproj

Lines changed: 8 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
4+
<TargetFramework>netstandard2.0</TargetFramework>
85
<ProjectGuid>{AD4468F8-8883-434B-9D4C-E1801BB3B52A}</ProjectGuid>
9-
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10-
<OutputType>Library</OutputType>
11-
<RootNamespace>Java.Interop.Dynamic</RootNamespace>
12-
<AssemblyName>Java.Interop.Dynamic</AssemblyName>
13-
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
14-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
157
<SignAssembly>true</SignAssembly>
168
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
9+
<AssemblyTitle>Java.Interop.Dynamic</AssemblyTitle>
10+
<Company>Microsoft Corporation</Company>
11+
<Copyright>Microsoft Corporation</Copyright>
12+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1713
</PropertyGroup>
1814
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<DebugSymbols>true</DebugSymbols>
20-
<DebugType>full</DebugType>
21-
<Optimize>false</Optimize>
2215
<OutputPath>..\..\bin\Debug</OutputPath>
23-
<DefineConstants>DEBUG;</DefineConstants>
24-
<ErrorReport>prompt</ErrorReport>
25-
<WarningLevel>4</WarningLevel>
26-
<ConsolePause>false</ConsolePause>
27-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2816
</PropertyGroup>
2917
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30-
<DebugType>full</DebugType>
31-
<Optimize>true</Optimize>
3218
<OutputPath>..\..\bin\Release</OutputPath>
33-
<ErrorReport>prompt</ErrorReport>
34-
<WarningLevel>4</WarningLevel>
35-
<ConsolePause>false</ConsolePause>
36-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3719
</PropertyGroup>
3820
<ItemGroup>
39-
<Compile Include="Properties\AssemblyInfo.cs" />
40-
<Compile Include="Java.Interop.Dynamic\DynamicJavaClass.cs" />
41-
<Compile Include="Java.Interop.Dynamic\DynamicJavaInstance.cs" />
42-
<Compile Include="Java.Interop.Dynamic\JavaClassInfo.cs" />
43-
<Compile Include="Java.Interop.Dynamic\JavaConstructorInfo.cs" />
44-
<Compile Include="Java.Interop.Dynamic\JavaFieldInfo.cs" />
45-
<Compile Include="Java.Interop.Dynamic\JavaInstanceProxy.cs" />
46-
<Compile Include="Java.Interop.Dynamic\JavaMemberInfo.cs" />
47-
<Compile Include="Java.Interop.Dynamic\JavaMethodBase.cs" />
48-
<Compile Include="Java.Interop.Dynamic\JavaMethodInfo.cs" />
49-
<Compile Include="Java.Interop.Dynamic\JniMetaObject.cs" />
21+
<Compile Remove="Tests\**\*.cs" />
5022
</ItemGroup>
51-
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
5223
<ItemGroup>
5324
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
5425
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>

src/Java.Interop.Dynamic/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Java.Interop.Dynamic/Tests/Java.Interop.Dynamic-Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<OutputType>Library</OutputType>
1010
<RootNamespace>Java.Interop.DynamicTests</RootNamespace>
1111
<AssemblyName>Java.Interop.Dynamic-Tests</AssemblyName>
12-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
12+
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
1313
</PropertyGroup>
1414
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
1515
<DebugSymbols>true</DebugSymbols>

src/Java.Interop.Export/Java.Interop.Export.csproj

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,25 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
4+
<TargetFramework>netstandard2.0</TargetFramework>
85
<ProjectGuid>{B501D075-6183-4E1D-92C9-F7B5002475B1}</ProjectGuid>
9-
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10-
<OutputType>Library</OutputType>
11-
<RootNamespace>Java.Interop</RootNamespace>
12-
<AssemblyName>Java.Interop.Export</AssemblyName>
13-
<TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
14-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
156
<SignAssembly>true</SignAssembly>
167
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
8+
<AssemblyTitle>Java.Interop.Export</AssemblyTitle>
9+
<Company>Microsoft Corporation</Company>
10+
<Copyright>Microsoft Corporation</Copyright>
11+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1712
</PropertyGroup>
1813
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<DebugSymbols>true</DebugSymbols>
20-
<DebugType>full</DebugType>
21-
<Optimize>false</Optimize>
2214
<OutputPath>..\..\bin\Debug</OutputPath>
23-
<DefineConstants>DEBUG;</DefineConstants>
24-
<ErrorReport>prompt</ErrorReport>
25-
<WarningLevel>4</WarningLevel>
26-
<ConsolePause>false</ConsolePause>
2715
</PropertyGroup>
2816
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<DebugType>full</DebugType>
30-
<Optimize>true</Optimize>
3117
<OutputPath>..\..\bin\Release</OutputPath>
32-
<ErrorReport>prompt</ErrorReport>
33-
<WarningLevel>4</WarningLevel>
34-
<ConsolePause>false</ConsolePause>
3518
</PropertyGroup>
3619
<ItemGroup>
37-
<Compile Include="Properties\AssemblyInfo.cs" />
38-
<Compile Include="Java.Interop\JavaCallableAttribute.cs" />
39-
<Compile Include="Java.Interop\MarshalMemberBuilder.cs" />
20+
<Compile Remove="Tests\**\*.cs" />
21+
<Compile Remove="Java.Interop\JniLocationException.cs" />
4022
</ItemGroup>
41-
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
4223
<ItemGroup>
4324
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
4425
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>

src/Java.Interop.Export/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

src/Java.Interop.GenericMarshaler/Java.Interop.GenericMarshaler.csproj

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,28 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
2+
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5-
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
6-
<ProductVersion>8.0.30703</ProductVersion>
7-
<SchemaVersion>2.0</SchemaVersion>
4+
<TargetFramework>netstandard2.0</TargetFramework>
85
<ProjectGuid>{D1243BAB-23CA-4566-A2A3-3ADA2C2DC3AF}</ProjectGuid>
9-
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10-
<OutputType>Library</OutputType>
11-
<RootNamespace>Java.Interop.GenericMarshaler</RootNamespace>
12-
<AssemblyName>Java.Interop.GenericMarshaler</AssemblyName>
13-
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
14-
<TargetFrameworkProfile>Profile111</TargetFrameworkProfile>
6+
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
157
<SignAssembly>true</SignAssembly>
168
<AssemblyOriginatorKeyFile>..\..\product.snk</AssemblyOriginatorKeyFile>
9+
<AssemblyTitle>Java.Interop.GenericMarshaler</AssemblyTitle>
10+
<Company>Microsoft Corporation</Company>
11+
<Copyright>Microsoft Corporation</Copyright>
12+
<AssemblyVersion>0.1.0.0</AssemblyVersion>
1713
</PropertyGroup>
1814
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
19-
<DebugSymbols>true</DebugSymbols>
20-
<DebugType>full</DebugType>
21-
<Optimize>false</Optimize>
2215
<OutputPath>..\..\bin\Debug</OutputPath>
23-
<DefineConstants>DEBUG;</DefineConstants>
24-
<ErrorReport>prompt</ErrorReport>
25-
<WarningLevel>4</WarningLevel>
26-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
2716
</PropertyGroup>
2817
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
29-
<Optimize>true</Optimize>
3018
<OutputPath>..\..\bin\Release</OutputPath>
31-
<ErrorReport>prompt</ErrorReport>
32-
<WarningLevel>4</WarningLevel>
33-
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
3419
</PropertyGroup>
35-
<ItemGroup>
36-
<Compile Include="Properties\AssemblyInfo.cs" />
37-
<Compile Include="Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.cs">
38-
<DependentUpon>Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.tt</DependentUpon>
39-
</Compile>
40-
</ItemGroup>
4120
<ItemGroup>
4221
<None Include="Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.tt">
4322
<Generator>TextTemplatingFileGenerator</Generator>
4423
<LastGenOutput>Java.Interop.GenericMarshaler\JniPeerInstanceMethodsExtensions.cs</LastGenOutput>
4524
</None>
4625
</ItemGroup>
47-
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
4826
<ItemGroup>
4927
<ProjectReference Include="..\Java.Interop\Java.Interop.csproj">
5028
<Project>{94BD81F7-B06F-4295-9636-F8A3B6BDC762}</Project>

src/Java.Interop.GenericMarshaler/Properties/AssemblyInfo.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)