From d09ca91ab15a43ba1d19bc0d8f6c85bd3f331ced Mon Sep 17 00:00:00 2001
From: Andrew Arnott <andrewarnott@gmail.com>
Date: Sat, 7 Sep 2019 17:12:51 -0600
Subject: [PATCH 1/3] Target newer frameworks and SDKs

Also drop MSBuild.Sdk.Extras
---
 azure-pipelines.yml                                | 14 ++++++++++----
 src/Directory.Build.targets                        | 11 ++++++-----
 ...mutableObjectGraph.Generation.Attributes.csproj |  4 ++--
 .../ImmutableObjectGraph.Generation.Tests.csproj   |  8 +++-----
 .../ImmutableObjectGraph.Generation.csproj         |  4 ++--
 .../ImmutableObjectGraph.Generation.nuspec         |  4 ++--
 .../ImmutableObjectGraph.csproj                    |  4 ++--
 src/RoslynDemo/RoslynDemo.csproj                   |  2 +-
 src/global.json                                    |  5 +----
 9 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/azure-pipelines.yml b/azure-pipelines.yml
index 7c5676b..4694f28 100644
--- a/azure-pipelines.yml
+++ b/azure-pipelines.yml
@@ -1,8 +1,9 @@
 trigger:
   branches:
-    include: ["master"]
+    include:
+    - master
   paths:
-    exclude: ["doc", "*.md", ".appveyor.yml", ".travis.yml"]
+    exclude: ["doc", "*.md"]
 
 variables:
 #  TreatWarningsAsErrors: true
@@ -12,7 +13,7 @@ variables:
 
 jobs:
 - job: Windows
-  pool: Hosted VS2017
+  pool: Hosted Windows 2019 with VS2019
   steps:
   - script: |
       dotnet tool install --tool-path . nbgv
@@ -20,6 +21,11 @@ jobs:
     displayName: Set build number
     condition: ne(variables['system.pullrequest.isfork'], true)
 
+  - task: UseDotNet@2
+    displayName: Install .NET Core SDK
+    inputs:
+      version: 2.2.401
+
   - script: dotnet --info
     displayName: Show dotnet SDK info
 
@@ -35,7 +41,7 @@ jobs:
   # Use VSBuild on Windows so GitLink will work (it fails on dotnet build)
   - task: VSBuild@1
     inputs:
-      vsVersion: 15.0
+      vsVersion: "16.0"
       msbuildArgs: /t:build,pack /m /v:m /bl:"$(Build.ArtifactStagingDirectory)/build_logs/msbuild.binlog"
       platform: $(BuildPlatform)
       configuration: $(BuildConfiguration)
diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index 3ae6838..4f796f2 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -4,15 +4,16 @@
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Update="CodeGeneration.Roslyn.Attributes" Version="$(CodeGenerationRoslynVersion)" />
-    <PackageReference Update="CodeGeneration.Roslyn" Version="$(CodeGenerationRoslynVersion)" />
     <PackageReference Update="CodeGeneration.Roslyn.BuildTime" Version="$(CodeGenerationRoslynVersion)" />
+    <PackageReference Update="CodeGeneration.Roslyn" Version="$(CodeGenerationRoslynVersion)" />
+    <PackageReference Update="Microsoft.Build" Version="14.3.0" />
     <PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" />
+    <PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.2.0" />
     <PackageReference Update="System.Collections.Immutable" Version="1.5.0" />
     <PackageReference Update="System.Diagnostics.Contracts" Version="4.3.0" />
-    <PackageReference Update="Validation" Version="2.4.18" />
-    <PackageReference Update="Microsoft.Build" Version="14.3.0" />
-    <PackageReference Update="xunit" Version="2.3.1" />
-    <PackageReference Update="xunit.runner.visualstudio" Version="2.3.1" />
+    <PackageReference Update="Validation" Version="2.4.22" />
+    <PackageReference Update="xunit.runner.visualstudio" Version="2.4.1" />
+    <PackageReference Update="xunit" Version="2.4.1" />
   </ItemGroup>
   <ItemGroup>
     <DotNetCliToolReference Update="dotnet-codegen" Version="$(CodeGenerationRoslynVersion)" />
diff --git a/src/ImmutableObjectGraph.Generation.Attributes/ImmutableObjectGraph.Generation.Attributes.csproj b/src/ImmutableObjectGraph.Generation.Attributes/ImmutableObjectGraph.Generation.Attributes.csproj
index 8a1ae05..315dbfc 100644
--- a/src/ImmutableObjectGraph.Generation.Attributes/ImmutableObjectGraph.Generation.Attributes.csproj
+++ b/src/ImmutableObjectGraph.Generation.Attributes/ImmutableObjectGraph.Generation.Attributes.csproj
@@ -1,7 +1,7 @@
-﻿<Project Sdk="MSBuild.Sdk.Extras">
+﻿<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <RootNamespace>ImmutableObjectGraph.Generation</RootNamespace>
-    <TargetFrameworks>netstandard1.0</TargetFrameworks>
+    <TargetFrameworks>netstandard2.0</TargetFrameworks>
     <Description>The runtime components behind the types generated with the ImmutableObjectGraph.Generation package.</Description>
 
     <!-- This gets included in ImmutableObjectGraph.Generation -->
diff --git a/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj b/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
index 8afbd42..0205ced 100644
--- a/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
+++ b/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
@@ -1,9 +1,6 @@
 ﻿<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFramework>net461</TargetFramework>
-
-    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
-    <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
+    <TargetFrameworks>net472</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
     <Compile Update="TestSources\AbstractClassMidTypeHierarchyWithRequiredField.cs">
@@ -85,6 +82,7 @@
     <PackageReference Include="xunit" />
     <PackageReference Include="xunit.runner.visualstudio" />
     <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" />
     <PackageReference Include="CodeGeneration.Roslyn" PrivateAssets="all" />
   </ItemGroup>
   <ItemGroup>
@@ -95,4 +93,4 @@
     <ProjectReference Include="..\ImmutableObjectGraph.Generation\ImmutableObjectGraph.Generation.csproj" />
     <ProjectReference Include="..\ImmutableObjectGraph\ImmutableObjectGraph.csproj" />
   </ItemGroup>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
index 12165b7..97a35cb 100644
--- a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
+++ b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
@@ -1,7 +1,7 @@
 ﻿<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
     <RootNamespace>ImmutableObjectGraph.Generation</RootNamespace>
-    <TargetFramework>netstandard1.6</TargetFramework>
+    <TargetFramework>netstandard2.0</TargetFramework>
     <Description>MSBuild-based code generator to transform simple mutable type definitions into fully functional immutable types with persistent characteristics.</Description>
 
     <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
@@ -57,4 +57,4 @@
       <NuspecProperties>id=$(PackageId);version=$(NuGetPackageVersion);authors=$(Authors);copyright=$(Copyright);tags=$(PackageTags);requireLicenseAcceptance=$(PackageRequireLicenseAcceptance);licenseUrl=$(PackageLicenseUrl);description=$(Description);CodeGenerationRoslynVersion=$(CodeGenerationRoslynVersion);Configuration=$(Configuration);OutDir=$(OutDir)</NuspecProperties>
     </PropertyGroup>
   </Target>
-</Project>
\ No newline at end of file
+</Project>
diff --git a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.nuspec b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.nuspec
index d1ec9a2..81e8819 100644
--- a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.nuspec
+++ b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.nuspec
@@ -11,7 +11,7 @@
     <copyright>$Copyright$</copyright>
     <tags>$PackageTags$</tags>
     <dependencies>
-      <group targetFramework=".NETStandard1.0">
+      <group targetFramework=".NETStandard2.0">
         <dependency id="CodeGeneration.Roslyn.BuildTime" version="$CodeGenerationRoslynVersion$" />
         <dependency id="ImmutableObjectGraph" version="$version$" />
       </group>
@@ -25,6 +25,6 @@
     <file src="..\..\lib\netstandard1.0\CG.Pluralization.dll" target="tools\" />
     <file src="Readme.txt" target="Readme.txt" />
     <file src="build\*" target="build\" />
-    <file src="..\..\bin\ImmutableObjectGraph.Generation.Attributes\$Configuration$\netstandard1.0\ImmutableObjectGraph.Generation.Attributes.dll" target="lib\netstandard1.0\" />
+    <file src="..\..\bin\ImmutableObjectGraph.Generation.Attributes\$Configuration$\netstandard2.0\ImmutableObjectGraph.Generation.Attributes.dll" target="lib\netstandard2.0\" />
   </files>
 </package>
diff --git a/src/ImmutableObjectGraph/ImmutableObjectGraph.csproj b/src/ImmutableObjectGraph/ImmutableObjectGraph.csproj
index ce49fec..41e881d 100644
--- a/src/ImmutableObjectGraph/ImmutableObjectGraph.csproj
+++ b/src/ImmutableObjectGraph/ImmutableObjectGraph.csproj
@@ -1,6 +1,6 @@
-﻿<Project Sdk="MSBuild.Sdk.Extras">
+﻿<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFrameworks>netstandard1.0</TargetFrameworks>
+    <TargetFrameworks>netstandard2.0</TargetFrameworks>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Include="Validation" PrivateAssets="compile" />
diff --git a/src/RoslynDemo/RoslynDemo.csproj b/src/RoslynDemo/RoslynDemo.csproj
index 536eafd..639c146 100644
--- a/src/RoslynDemo/RoslynDemo.csproj
+++ b/src/RoslynDemo/RoslynDemo.csproj
@@ -1,6 +1,6 @@
 ﻿<Project Sdk="Microsoft.NET.Sdk">
   <PropertyGroup>
-    <TargetFramework>net461</TargetFramework>
+    <TargetFramework>net472</TargetFramework>
     <OutputType>Exe</OutputType>
     <IsPackable>false</IsPackable>
   </PropertyGroup>
diff --git a/src/global.json b/src/global.json
index 61922f8..3d26ee6 100644
--- a/src/global.json
+++ b/src/global.json
@@ -1,8 +1,5 @@
 {
   "sdk": {
-    "version": "2.1.402"
-  },
-  "msbuild-sdks": {
-    "MSBuild.Sdk.Extras": "1.5.4"
+    "version": "2.2.401"
   }
 }

From 0f97e348b31ce8c0d774faf7a14b98ef20a67449 Mon Sep 17 00:00:00 2001
From: Andrew Arnott <andrewarnott@gmail.com>
Date: Sat, 7 Sep 2019 18:49:30 -0600
Subject: [PATCH 2/3] Update to latest CG.R

---
 src/Directory.Build.targets                                  | 5 +++--
 .../GenerateImmutableAttribute.cs                            | 2 +-
 src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs    | 2 ++
 .../ImmutableObjectGraph.Generation.Tests.csproj             | 2 ++
 src/ImmutableObjectGraph.Generation/CodeGen.cs               | 1 +
 .../ImmutableObjectGraph.Generation.csproj                   | 1 +
 .../Roslyn/CSharpDeclarationComputer.cs                      | 2 +-
 .../Roslyn/DeclarationComputer.cs                            | 2 +-
 .../Roslyn/DeclarationInfo.cs                                | 2 +-
 src/ImmutableObjectGraph.Generation/Syntax.cs                | 1 +
 10 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/src/Directory.Build.targets b/src/Directory.Build.targets
index 4f796f2..1286826 100644
--- a/src/Directory.Build.targets
+++ b/src/Directory.Build.targets
@@ -1,13 +1,14 @@
 <Project>
   <PropertyGroup>
-    <CodeGenerationRoslynVersion>0.4.88</CodeGenerationRoslynVersion>
+    <CodeGenerationRoslynVersion>0.6.1</CodeGenerationRoslynVersion>
   </PropertyGroup>
   <ItemGroup>
     <PackageReference Update="CodeGeneration.Roslyn.Attributes" Version="$(CodeGenerationRoslynVersion)" />
     <PackageReference Update="CodeGeneration.Roslyn.BuildTime" Version="$(CodeGenerationRoslynVersion)" />
     <PackageReference Update="CodeGeneration.Roslyn" Version="$(CodeGenerationRoslynVersion)" />
+    <PackageReference Update="CodeGeneration.Roslyn.Engine" Version="$(CodeGenerationRoslynVersion)" />
     <PackageReference Update="Microsoft.Build" Version="14.3.0" />
-    <PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0" />
+    <PackageReference Update="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="3.1.0" />
     <PackageReference Update="Microsoft.NET.Test.Sdk" Version="16.2.0" />
     <PackageReference Update="System.Collections.Immutable" Version="1.5.0" />
     <PackageReference Update="System.Diagnostics.Contracts" Version="4.3.0" />
diff --git a/src/ImmutableObjectGraph.Generation.Attributes/GenerateImmutableAttribute.cs b/src/ImmutableObjectGraph.Generation.Attributes/GenerateImmutableAttribute.cs
index 0d7ed4e..d651913 100644
--- a/src/ImmutableObjectGraph.Generation.Attributes/GenerateImmutableAttribute.cs
+++ b/src/ImmutableObjectGraph.Generation.Attributes/GenerateImmutableAttribute.cs
@@ -6,7 +6,7 @@
 
     [AttributeUsage(AttributeTargets.Class)]
     [Conditional("CodeGeneration")]
-    [CodeGenerationAttribute("ImmutableObjectGraph.Generation.CodeGenerator, ImmutableObjectGraph.Generation, Version=" + ThisAssembly.AssemblyVersion + ", Culture=neutral, PublicKeyToken=bfd91f1bd601e0d7")]
+    [CodeGenerationAttribute("ImmutableObjectGraph.Generation.CodeGenerator, ImmutableObjectGraph.Generation, Version=" + ThisAssembly.AssemblyVersion + ", Culture=neutral, PublicKeyToken=" + ThisAssembly.PublicKeyToken)]
     public class GenerateImmutableAttribute : Attribute
     {
         public GenerateImmutableAttribute()
diff --git a/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs b/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
index 7e88cf2..d39f126 100644
--- a/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
+++ b/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
@@ -9,7 +9,9 @@
     using System.Text;
     using System.Threading;
     using System.Threading.Tasks;
+    using CodeGeneration.Roslyn.Engine;
     using global::CodeGeneration.Roslyn;
+    using ImmutableObjectGraph.Generation.Roslyn;
     using Microsoft.CodeAnalysis;
     using Microsoft.CodeAnalysis.CSharp;
     using Microsoft.CodeAnalysis.Diagnostics;
diff --git a/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj b/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
index 0205ced..6d9cd56 100644
--- a/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
+++ b/src/ImmutableObjectGraph.Generation.Tests/ImmutableObjectGraph.Generation.Tests.csproj
@@ -79,11 +79,13 @@
   </ItemGroup>
   <ItemGroup>
     <PackageReference Include="Microsoft.Build" />
+    <PackageReference Include="Validation" />
     <PackageReference Include="xunit" />
     <PackageReference Include="xunit.runner.visualstudio" />
     <PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" PrivateAssets="all" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" />
     <PackageReference Include="CodeGeneration.Roslyn" PrivateAssets="all" />
+    <PackageReference Include="CodeGeneration.Roslyn.Engine" PrivateAssets="all" />
   </ItemGroup>
   <ItemGroup>
     <DotNetCliToolReference Include="dotnet-codegen" />
diff --git a/src/ImmutableObjectGraph.Generation/CodeGen.cs b/src/ImmutableObjectGraph.Generation/CodeGen.cs
index 2f8c120..7082d82 100644
--- a/src/ImmutableObjectGraph.Generation/CodeGen.cs
+++ b/src/ImmutableObjectGraph.Generation/CodeGen.cs
@@ -12,6 +12,7 @@
     using System.Threading;
     using System.Threading.Tasks;
     using global::CodeGeneration.Roslyn;
+    using ImmutableObjectGraph.Generation.Roslyn;
     using Microsoft.CodeAnalysis;
     using Microsoft.CodeAnalysis.CSharp;
     using Microsoft.CodeAnalysis.CSharp.Syntax;
diff --git a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
index 97a35cb..b01d157 100644
--- a/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
+++ b/src/ImmutableObjectGraph.Generation/ImmutableObjectGraph.Generation.csproj
@@ -36,6 +36,7 @@
     <PackageReference Include="CodeGeneration.Roslyn" PrivateAssets="all" />
     <PackageReference Include="CodeGeneration.Roslyn.BuildTime" PrivateAssets="none" />
     <PackageReference Include="System.Diagnostics.Contracts" PrivateAssets="all" />
+    <PackageReference Include="Validation" PrivateAssets="all" />
   </ItemGroup>
   <ItemGroup>
     <DotNetCliToolReference Include="dotnet-codegen" />
diff --git a/src/ImmutableObjectGraph.Generation/Roslyn/CSharpDeclarationComputer.cs b/src/ImmutableObjectGraph.Generation/Roslyn/CSharpDeclarationComputer.cs
index a369cd9..7347cd2 100644
--- a/src/ImmutableObjectGraph.Generation/Roslyn/CSharpDeclarationComputer.cs
+++ b/src/ImmutableObjectGraph.Generation/Roslyn/CSharpDeclarationComputer.cs
@@ -13,7 +13,7 @@
 
 namespace ImmutableObjectGraph.Generation.Roslyn
 {
-    internal class CSharpDeclarationComputer : DeclarationComputer
+    public class CSharpDeclarationComputer : DeclarationComputer
     {
         public static ImmutableArray<DeclarationInfo> GetDeclarationsInSpan(SemanticModel model, TextSpan span, bool getSymbol, CancellationToken cancellationToken)
         {
diff --git a/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationComputer.cs b/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationComputer.cs
index 9f17184..18d51bf 100644
--- a/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationComputer.cs
+++ b/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationComputer.cs
@@ -10,7 +10,7 @@ namespace ImmutableObjectGraph.Generation.Roslyn
     using System.Threading;
     using Microsoft.CodeAnalysis;
 
-    internal class DeclarationComputer
+    public class DeclarationComputer
     {
         internal static DeclarationInfo GetDeclarationInfo(SemanticModel model, SyntaxNode node, bool getSymbol, IEnumerable<SyntaxNode> executableCodeBlocks, CancellationToken cancellationToken)
         {
diff --git a/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationInfo.cs b/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationInfo.cs
index ef5111d..d2bcd3c 100644
--- a/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationInfo.cs
+++ b/src/ImmutableObjectGraph.Generation/Roslyn/DeclarationInfo.cs
@@ -12,7 +12,7 @@ namespace ImmutableObjectGraph.Generation.Roslyn
     /// <summary>
     /// Struct containing information about a source declaration.
     /// </summary>
-    internal struct DeclarationInfo
+    public struct DeclarationInfo
     {
         private readonly SyntaxNode _declaredNode;
         private readonly ImmutableArray<SyntaxNode> _executableCodeBlocks;
diff --git a/src/ImmutableObjectGraph.Generation/Syntax.cs b/src/ImmutableObjectGraph.Generation/Syntax.cs
index 7a47b7c..37192e2 100644
--- a/src/ImmutableObjectGraph.Generation/Syntax.cs
+++ b/src/ImmutableObjectGraph.Generation/Syntax.cs
@@ -8,6 +8,7 @@
     using System.Text;
     using System.Threading;
     using System.Threading.Tasks;
+    using ImmutableObjectGraph.Generation.Roslyn;
     using Microsoft.CodeAnalysis;
     using Microsoft.CodeAnalysis.CSharp;
     using Microsoft.CodeAnalysis.CSharp.Syntax;

From d51e3705ff7f8269d12d4222aa845af3423850d6 Mon Sep 17 00:00:00 2001
From: Andrew Arnott <andrewarnott@gmail.com>
Date: Sun, 8 Sep 2019 18:30:56 -0600
Subject: [PATCH 3/3] Fix test failures by targeting test-run codegen to
 netstandard2.0

---
 .../CodeGenTests.cs                                    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs b/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
index d39f126..afb53bf 100644
--- a/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
+++ b/src/ImmutableObjectGraph.Generation.Tests/CodeGenTests.cs
@@ -36,8 +36,7 @@ public CodeGenTests(ITestOutputHelper logger)
             var workspace = new AdhocWorkspace();
             var project = workspace.CurrentSolution.AddProject("test", "test", "C#")
                 .WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))
-                .AddMetadataReferences(GetReferences("Profile78"))
-                .AddMetadataReference(MetadataReference.CreateFromFile(Assembly.Load("netstandard, Version=2.0.0.0").Location))
+                .AddMetadataReferences(GetNetStandard20References())
                 .AddMetadataReference(MetadataReference.CreateFromFile(typeof(GenerateImmutableAttribute).Assembly.Location))
                 .AddMetadataReference(MetadataReference.CreateFromFile(typeof(CodeGenerationAttributeAttribute).Assembly.Location))
                 .AddMetadataReference(MetadataReference.CreateFromFile(typeof(Optional).Assembly.Location))
@@ -337,10 +336,11 @@ private static string EscapeLineEndingCharacters(string whitespace)
             return builder.ToString();
         }
 
-        private static IEnumerable<MetadataReference> GetReferences(string profile)
+        private static IEnumerable<MetadataReference> GetNetStandard20References()
         {
-            string profileDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), @"Reference Assemblies\Microsoft\Framework\.NETPortable\v4.5\Profile", profile);
-            foreach (string assembly in Directory.GetFiles(profileDirectory, "*.dll"))
+            string nugetPackageRoot = Environment.GetEnvironmentVariable("NUGET_PACKAGES") ?? Environment.ExpandEnvironmentVariables(@"%USERPROFILE%\.nuget\packages");
+            string netstandardRoot = Path.Combine(nugetPackageRoot, @"netstandard.library\2.0.3\build\netstandard2.0\ref");
+            foreach (string assembly in Directory.GetFiles(netstandardRoot, "*.dll"))
             {
                 yield return MetadataReference.CreateFromFile(assembly);
             }
