Skip to content

Commit 3ecd15c

Browse files
author
dse
committed
NetCoreApp 2.0 compilation passed.
1 parent 6cebb5d commit 3ecd15c

File tree

9 files changed

+77
-26
lines changed

9 files changed

+77
-26
lines changed

src/clrmodule/clrmodule.15.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
2222
<NoWarn>1591</NoWarn>
2323
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
24-
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
24+
<PythonBuildDir Condition=" '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
25+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)$(TargetFramework)\</PythonBuildDir>
2526
<LangVersion>6</LangVersion>
2627
<ErrorReport>prompt</ErrorReport>
2728
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>

src/console/Console.15.csproj

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
33
<PropertyGroup>
4-
<TargetFrameworks>net40</TargetFrameworks>
4+
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
55
<Platforms>x64;x86</Platforms>
66
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
77
<OutputType>Exe</OutputType>
@@ -15,12 +15,15 @@
1515
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1616
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
1717
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
18-
<DocumentationFile>bin\nPython.xml</DocumentationFile>
1918
<OutputPath>bin\</OutputPath>
20-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
19+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
20+
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
21+
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
2122
<NoWarn>1591</NoWarn>
2223
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
23-
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
24+
<PythonBuildDir Condition=" '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
25+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)$(TargetFramework)\</PythonBuildDir>
26+
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)</PublishDir>
2427
<LangVersion>6</LangVersion>
2528
<ApplicationIcon>python-clear.ico</ApplicationIcon>
2629
<ErrorReport>prompt</ErrorReport>
@@ -88,7 +91,7 @@
8891
</ItemGroup>
8992
<ItemGroup>
9093
<Content Include="python-clear.ico" />
91-
<EmbeddedResource Include="$(PythonBuildDir)\Python.Runtime.dll">
94+
<EmbeddedResource Condition="'$(TargetFramework)'=='net40'" Include="$(PythonBuildDir)\Python.Runtime.dll">
9295
<LogicalName>Python.Runtime.dll</LogicalName>
9396
</EmbeddedResource>
9497
</ItemGroup>
@@ -99,6 +102,6 @@
99102
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
100103

101104
<Target Name="AfterBuild">
102-
<Copy SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
105+
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetPath)" DestinationFolder="$(PythonBuildDir)" />
103106
</Target>
104107
</Project>

src/console/pythonconsole.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,21 @@ namespace Python.Runtime
1616
/// </remarks>
1717
public sealed class PythonConsole
1818
{
19+
#if NET40
1920
private static AssemblyLoader assemblyLoader = new AssemblyLoader();
20-
21+
#endif
2122
private PythonConsole()
2223
{
2324
}
2425

2526
[STAThread]
2627
public static int Main(string[] args)
2728
{
29+
// Only net40 is capable to safely inject python.runtime.dll into resources.
30+
#if NET40
2831
// reference the static assemblyLoader to stop it being optimized away
2932
AssemblyLoader a = assemblyLoader;
30-
33+
#endif
3134
string[] cmd = Environment.GetCommandLineArgs();
3235
PythonEngine.Initialize();
3336

@@ -37,6 +40,7 @@ public static int Main(string[] args)
3740
return i;
3841
}
3942

43+
#if NET40
4044
// Register a callback function to load embedded assemblies.
4145
// (Python.Runtime.dll is included as a resource)
4246
private sealed class AssemblyLoader
@@ -73,5 +77,6 @@ public AssemblyLoader()
7377
};
7478
}
7579
}
80+
#endif
7681
}
7782
}

src/embed_tests/Python.EmbeddingTest.15.csproj

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>net40</TargetFrameworks>
5+
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
66
<Platforms>x64;x86</Platforms>
77
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
88
<AssetTargetFallback Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono'))">net45</AssetTargetFallback>
@@ -15,11 +15,14 @@
1515
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
1616
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1717
<OutputPath>bin\</OutputPath>
18-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
19-
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
18+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
19+
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
20+
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
2021
<NoWarn>1591</NoWarn>
2122
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
22-
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
23+
<PythonBuildDir Condition=" '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
24+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)$(TargetFramework)\</PythonBuildDir>
25+
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)embed_test</PublishDir>
2326
<LangVersion>6</LangVersion>
2427
<ErrorReport>prompt</ErrorReport>
2528
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>
@@ -87,8 +90,11 @@
8790
<ItemGroup>
8891
<PackageReference Include="NUnit" Version="3.7.1" />
8992
<PackageReference Include="NUnit.ConsoleRunner" Version="3.7.0" />
93+
<PackageReference Include="NUnit3TestAdapter" Version="3.8.0" />
94+
</ItemGroup>
95+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
96+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
9097
</ItemGroup>
91-
9298
<ItemGroup>
9399
<ProjectReference Include="..\runtime\Python.Runtime.15.csproj" />
94100
</ItemGroup>
@@ -113,7 +119,7 @@
113119
</PropertyGroup>
114120

115121
<Target Name="AfterBuild">
116-
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
122+
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
117123
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
118124
</Target>
119125

src/runtime/Python.Runtime.15.csproj

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22
<Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
33
<PropertyGroup>
4-
<TargetFrameworks>net40</TargetFrameworks>
4+
<TargetFrameworks>net40;netcoreapp2.0</TargetFrameworks>
55
<Platforms>AnyCPU</Platforms>
66
<Configurations>DebugMono;DebugMonoPY3;ReleaseMono;ReleaseMonoPY3;DebugWin;DebugWinPY3;ReleaseWin;ReleaseWinPY3</Configurations>
77
<AssetTargetFallback Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono'))">net45</AssetTargetFallback>
@@ -16,17 +16,21 @@
1616
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
1717
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
1818
<OutputPath>bin\</OutputPath>
19-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
20-
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
19+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
20+
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
21+
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
2122
<NoWarn>1591;NU1701</NoWarn>
2223
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
23-
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
24+
<PythonBuildDir Condition=" '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
25+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)$(TargetFramework)\</PythonBuildDir>
26+
<PublishDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)</PublishDir>
2427
<LangVersion>6</LangVersion>
2528
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
2629
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
2730
<CustomDefineConstants Condition="'$(CustomDefineConstants)' == ''">$(PYTHONNET_DEFINE_CONSTANTS)</CustomDefineConstants>
2831
<BaseDefineConstants>XPLAT</BaseDefineConstants>
2932
<DefineConstants>$(DefineConstants);$(CustomDefineConstants);$(BaseDefineConstants);</DefineConstants>
33+
<DefineConstants Condition="'$(TargetFramework)'=='netcoreapp2.0'">$(DefineConstants);NETCOREAPP</DefineConstants>
3034
<FrameworkPathOverride Condition="'$(TargetFramework)'=='net40' AND $(Configuration.Contains('Mono'))">$(NuGetPackageRoot)\microsoft.targetingpack.netframework.v4.5\1.0.1\lib\net45\</FrameworkPathOverride>
3135
</PropertyGroup>
3236

@@ -98,6 +102,12 @@
98102
</EmbeddedResource>
99103
</ItemGroup>
100104

105+
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
106+
<PackageReference Include="System.Security.Permissions">
107+
<Version>4.4.0</Version>
108+
</PackageReference>
109+
</ItemGroup>
110+
101111
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
102112
<Reference Include="Microsoft.CSharp" />
103113
</ItemGroup>
@@ -118,7 +128,7 @@
118128
<Exec Command="cp $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.XML.dll $(NuGetPackageRoot)/microsoft.targetingpack.netframework.v4.5/1.0.1/lib/net45/System.Xml.dll" />
119129
</Target>
120130
<Target Name="AfterBuild">
121-
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
131+
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetAssembly)" DestinationFolder="$(PythonBuildDir)" />
122132
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
123133
</Target>
124134
</Project>

src/runtime/nativecall.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,19 @@ private static void GenerateThunk(TypeBuilder tb, MethodInfo method)
106106

107107
il.Emit(OpCodes.Ldarg_1);
108108

109+
#if NETCOREAPP
110+
il.EmitCalli(OpCodes.Calli,
111+
CallingConventions.ExplicitThis,
112+
method.ReturnType,
113+
nargs, null
114+
);
115+
#else
109116
il.EmitCalli(OpCodes.Calli,
110117
CallingConvention.Cdecl,
111118
method.ReturnType,
112119
nargs
113120
);
114-
121+
#endif
115122
il.Emit(OpCodes.Ret);
116123

117124
tb.DefineMethodOverride(mb, method);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Reflection.Emit;
4+
5+
namespace Python.Runtime
6+
{
7+
public static class ReflectionPolifills
8+
{
9+
#if NETCOREAPP
10+
public static AssemblyBuilder DefineDynamicAssembly(this AppDomain appDomain, AssemblyName assemblyName, AssemblyBuilderAccess assemblyBuilderAccess)
11+
{
12+
return AssemblyBuilder.DefineDynamicAssembly(assemblyName, assemblyBuilderAccess);
13+
}
14+
#endif
15+
}
16+
}

src/testing/Python.Test.15.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
<RootNamespace>Python.Test</RootNamespace>
99
<PackageId>Python.Test</PackageId>
1010
<VersionPrefix>2.4.0</VersionPrefix>
11-
<DocumentationFile>bin\Python.Test.xml</DocumentationFile>
1211
<OutputPath>bin\</OutputPath>
13-
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
12+
<AppendTargetFrameworkToOutputPath Condition="'$(TargetFramework)'=='net40'">false</AppendTargetFrameworkToOutputPath>
13+
<DocumentationFile Condition="'$(TargetFramework)'=='net40'">$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
14+
<DocumentationFile Condition="'$(TargetFramework)'!='net40'">$(OutputPath)\$(TargetFramework)\$(AssemblyName).xml</DocumentationFile>
1415
<NoWarn>1591,0067</NoWarn>
1516
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
16-
<PythonBuildDir Condition=" '$(PythonBuildDir)' == '' ">$(SolutionDir)\bin\</PythonBuildDir>
17+
<PythonBuildDir Condition=" '$(PythonBuildDir)' == ''">$(SolutionDir)\bin\</PythonBuildDir>
18+
<PythonBuildDir Condition="'$(TargetFramework)'!='net40'">$(PythonBuildDir)$(TargetFramework)\</PythonBuildDir>
1719
<LangVersion>6</LangVersion>
1820
<SignAssembly>false</SignAssembly>
1921
<AssemblyOriginatorKeyFile>..\pythonnet.snk</AssemblyOriginatorKeyFile>
@@ -75,7 +77,7 @@
7577
</ItemGroup>
7678

7779
<ItemGroup>
78-
<ProjectReference Include="..\runtime\Python.Runtime.15.csproj"/>
80+
<ProjectReference Include="..\runtime\Python.Runtime.15.csproj" />
7981
</ItemGroup>
8082

8183
<Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
@@ -85,7 +87,8 @@
8587
<TargetAssemblyPdb>$(TargetDir)$(TargetName).pdb</TargetAssemblyPdb>
8688
</PropertyGroup>
8789
<Target Name="AfterBuild">
88-
<Copy SourceFiles="$(TargetAssembly)" DestinationFolder="$(SolutionDir)\src\tests\fixtures" />
90+
<Copy Condition="'$(TargetFramework)'=='net40'" SourceFiles="$(TargetAssembly)" DestinationFolder="$(SolutionDir)\src\tests\fixtures" />
91+
<Copy Condition="'$(TargetFramework)'!='net40'" SourceFiles="$(TargetAssembly)" DestinationFolder="$(SolutionDir)\src\tests\fixtures\$(TargetFramework)" />
8992
<!--Copy SourceFiles="$(TargetAssemblyPdb)" Condition="Exists('$(TargetAssemblyPdb)')" DestinationFolder="$(PythonBuildDir)" /-->
9093
</Target>
9194
</Project>

src/tests/fixtures/netcoreapp2.0/.gitkeep

Whitespace-only changes.

0 commit comments

Comments
 (0)