Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix (or workaround?) for codegen using netcore/netstandard 2.1 #4673

Merged
merged 7 commits into from Jun 13, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Expand Up @@ -23,7 +23,7 @@
<!-- Common compile parameters -->
<PropertyGroup>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<NoWarn>$(NoWarn);1591</NoWarn>
<NoWarn>$(NoWarn);1591;2003</NoWarn>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<!-- We use full (Windows PDBs) until cross platform support for source link will get better -->
<DebugType>full</DebugType>
Expand Down
2 changes: 1 addition & 1 deletion DotnetCLIVersion.txt
@@ -1 +1 @@
2.0.3
2.1.300
8 changes: 1 addition & 7 deletions Ensure-DotNetSdk.cmd
Expand Up @@ -8,20 +8,14 @@ set /p REQUIRED_DOTNET_VERSION=< "%~dp0DotnetCLIVersion.txt"

echo .Net Core version required: %REQUIRED_DOTNET_VERSION%

for /f "tokens=1 delims=. " %%a in ("%REQUIRED_DOTNET_VERSION%") do set REQUIRED_DOTNET_VERSION_MAJOR=%%a

for /f "tokens=*" %%i in ('where dotnet.exe') do (
set INSTALLED_DOTNET_EXE=%%i

echo Found dotnet.exe at: "!INSTALLED_DOTNET_EXE!"

for /f "tokens=*" %%j in ('"!INSTALLED_DOTNET_EXE!" --version') do set INSTALLED_DOTNET_VERSION=%%j

if [!INSTALLED_DOTNET_VERSION!] neq [] (
for /f "tokens=1 delims=. " %%a in ("!INSTALLED_DOTNET_VERSION!") do set INSTALLED_DOTNET_VERSION_MAJOR=%%a
)

if [!REQUIRED_DOTNET_VERSION_MAJOR!]==[!INSTALLED_DOTNET_VERSION_MAJOR!] (
if [!REQUIRED_DOTNET_VERSION!]==[!INSTALLED_DOTNET_VERSION!] (

echo .Net Core major version is matching !INSTALLED_DOTNET_VERSION!, using the installed version.

Expand Down
2 changes: 1 addition & 1 deletion build.sh
Expand Up @@ -16,7 +16,7 @@ while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symli
done
DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

DOCKER_IMAGENAME=microsoft/dotnet:2.0.3-sdk
DOCKER_IMAGENAME=microsoft/dotnet:2.1.300-sdk

# $args array may have empty elements in it.
# The easiest way to remove them is to cast to string and back to array.
Expand Down
14 changes: 7 additions & 7 deletions src/Orleans.CodeGeneration.Build/AssemblyResolver.cs
Expand Up @@ -7,7 +7,7 @@
using Microsoft.Extensions.DependencyModel;
using Microsoft.Extensions.DependencyModel.Resolution;
using Orleans.Runtime;
#if NETCOREAPP2_0
#if NETCOREAPP
using System.Runtime.Loader;
#endif

Expand All @@ -28,7 +28,7 @@ internal class AssemblyResolver

private readonly DependencyContext dependencyContext;
private readonly DependencyContext resolverRependencyContext;
#if NETCOREAPP2_0
#if NETCOREAPP
private readonly AssemblyLoadContext loadContext;
#endif

Expand All @@ -53,7 +53,7 @@ public AssemblyResolver(string path, List<string> referencedAssemblies, bool ins
new PackageCompilationAssemblyResolver()
});

#if NETCOREAPP2_0
#if NETCOREAPP
this.loadContext = AssemblyLoadContext.GetLoadContext(this.Assembly);

if (this.loadContext == AssemblyLoadContext.Default)
Expand Down Expand Up @@ -87,7 +87,7 @@ public AssemblyResolver(string path, List<string> referencedAssemblies, bool ins

public void Dispose()
{
#if NETCOREAPP2_0
#if NETCOREAPP

if (this.loadContext == AssemblyLoadContext.Default)
{
Expand Down Expand Up @@ -120,7 +120,7 @@ public Assembly ResolveAssembly(object sender, ResolveEventArgs args)
{
var context = default(AssemblyLoadContext);

#if NETCOREAPP2_0
#if NETCOREAPP
context = AssemblyLoadContext.GetLoadContext(args.RequestingAssembly);
#endif

Expand Down Expand Up @@ -185,7 +185,7 @@ private Assembly TryLoadAssemblyFromPath(string path)
{
try
{
#if NETCOREAPP2_0
#if NETCOREAPP
return this.loadContext.LoadFromAssemblyPath(path);
#else
return Assembly.LoadFrom(path);
Expand All @@ -197,7 +197,7 @@ private Assembly TryLoadAssemblyFromPath(string path)
}
}

#if !NETCOREAPP2_0
#if !NETCOREAPP
internal class AssemblyLoadContext
{
}
Expand Down
10 changes: 5 additions & 5 deletions src/Orleans.CodeGeneration.Build/CodeGenerator.cs
Expand Up @@ -8,7 +8,7 @@
using Orleans.Serialization;
using Orleans.Runtime;
using Orleans.Metadata;
#if NETCOREAPP2_0
#if NETCOREAPP
using System.Runtime.Loader;
#endif

Expand Down Expand Up @@ -44,7 +44,7 @@ public static bool GenerateCode(CodeGenOptions options)
// Generate source
Console.WriteLine($"Orleans-CodeGen - Generating file {outputFileName}");

#if !NETCOREAPP2_0
#if !NETCOREAPP
var generatedCode = GenerateCodeInAppDomain(options);
#else
var generatedCode = GenerateCodeInternal(options);
Expand Down Expand Up @@ -96,7 +96,7 @@ private static void SetupDepsFilesForAppDomain(AppDomain appDomain, FileInfo inp
}
}

#if !NETCOREAPP2_0
#if !NETCOREAPP
private static string GenerateCodeInAppDomain(CodeGenOptions options)
{
AppDomain appDomain = null;
Expand Down Expand Up @@ -150,7 +150,7 @@ private static string GenerateCodeInternal(CodeGenOptions options)
try
{
// Set up assembly resolution.
#if NETCOREAPP2_0
#if NETCOREAPP
AssemblyLoadContext.Default.Resolving += refResolver.AssemblyLoadContextResolving;
#else
AppDomain.CurrentDomain.AssemblyResolve += refResolver.ResolveAssembly;
Expand All @@ -161,7 +161,7 @@ private static string GenerateCodeInternal(CodeGenOptions options)
finally
{
refResolver.Dispose();
#if NETCOREAPP2_0
#if NETCOREAPP
AssemblyLoadContext.Default.Resolving -= refResolver.AssemblyLoadContextResolving;
#else
AppDomain.CurrentDomain.AssemblyResolve -= refResolver.ResolveAssembly;
Expand Down
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build;PostBuildPublish">
<Project Sdk="Microsoft.NET.Sdk" DefaultTargets="Build;PostBuildPublish">

<PropertyGroup>
<PackageId>Microsoft.Orleans.OrleansCodeGenerator.Build</PackageId>
Expand All @@ -8,8 +8,8 @@

<PropertyGroup>
<TargetFramework />
<TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.0</TargetFrameworks>
<TargetFrameworks>netcoreapp2.0;netcoreapp2.1;net461</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netcoreapp2.0;netcoreapp2.1</TargetFrameworks>
<OutputType>Exe</OutputType>
<NoPackageAnalysis>true</NoPackageAnalysis>
<BuildOutputTargetFolder>tasks</BuildOutputTargetFolder>
Expand Down
Expand Up @@ -12,9 +12,13 @@
</PropertyGroup>

<PropertyGroup Condition="'$(OrleansCodeGeneratorAssembly)' == ''">
<CoreAssembly>$(MSBuildThisFileDirectory)..\tasks\netcoreapp2.0\Orleans.CodeGeneration.Build.dll</CoreAssembly>
<CoreAssembly20>$(MSBuildThisFileDirectory)..\tasks\netcoreapp2.0\Orleans.CodeGeneration.Build.dll</CoreAssembly20>
<CoreAssembly21>$(MSBuildThisFileDirectory)..\tasks\netcoreapp2.1\Orleans.CodeGeneration.Build.dll</CoreAssembly21>
<FullAssembly>$(MSBuildThisFileDirectory)..\tasks\net461\Orleans.CodeGeneration.Build.exe</FullAssembly>

<CoreAssembly Condition="$(TargetFramework.Equals('netcoreapp2.0')) or $(TargetFramework.Equals('netstandard2.0'))">$(CoreAssembly20)</CoreAssembly>
<CoreAssembly Condition="$(TargetFramework.Equals('netcoreapp2.1')) or $(TargetFramework.Equals('netstandard2.1'))">$(CoreAssembly21)</CoreAssembly>

<!-- Specify the assembly containing the MSBuild tasks. -->
<MSBuildIsCore Condition="'$(MSBuildRuntimeType)' == 'Core' or '$(OS)' != 'Windows_NT'">true</MSBuildIsCore>
<TaskAssembly Condition="'$(MSBuildIsCore)' == 'true'">$(CoreAssembly)</TaskAssembly>
Expand Down
5 changes: 5 additions & 0 deletions test/Grains/TestFSharp/TestFSharp.fsproj
Expand Up @@ -4,6 +4,11 @@
<RootNamespace>TestFSharp</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need this because there's already the change in Directory.Build.props.

<NoWarn>;1591;1591;2003</NoWarn>
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>

<ItemGroup>
<Compile Include="Types.fs" />
Expand Down
6 changes: 6 additions & 0 deletions test/Misc/TestFSharpInterfaces/TestFSharpInterfaces.fsproj
Expand Up @@ -4,6 +4,12 @@
<RootNamespace>TestFSharpInterfaces</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We probably don't need this because there's already the change in Directory.Build.props.

<NoWarn>;1591;1591;2003</NoWarn>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<NoWarn>;1591;1591;2003</NoWarn>
</PropertyGroup>

<ItemGroup>
<Compile Include="IFSharpBaseInterface.fs" />
Expand Down