Skip to content

Commit 45e94c4

Browse files
committed
Simplify Roslyn net5.0 patches
Use build task for find-replace instead of large patches.
1 parent 45641ee commit 45e94c4

9 files changed

+163
-1741
lines changed

patches/roslyn/0012-Build-Roslyn-as-net5.0-in-source-build.patch

Lines changed: 97 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
1-
From 4c8ad3e2ec5968670132183dd7ec9e18760b6fc1 Mon Sep 17 00:00:00 2001
1+
From ed6e61977542a2fb1f69da41eb9806a4212d4046 Mon Sep 17 00:00:00 2001
22
From: Davis Goodin <[email protected]>
33
Date: Mon, 28 Dec 2020 18:21:27 -0600
44
Subject: [PATCH] Build Roslyn as net5.0 in source-build
55

6+
Set compilers package targetframework to net5.0.
7+
Update _RoslynTargetDirectoryName for net5.0
8+
9+
Fixups for new types and changes introduced with net5.0:
10+
11+
* Disable some warnings to let code continue to compile.
12+
13+
* Remove S.Runtime.InteropServices.WindowsRuntime using. Doesn't exist
14+
and doesn't seem necessary in net5.0.
615
---
16+
Directory.Build.props | 5 +++
717
Directory.Build.targets | 12 +++++++
818
eng/Versions.props | 4 +++
919
src/Compilers/CSharp/csc/csc.csproj | 2 +-
10-
.../Microsoft.Build.Tasks.CodeAnalysis.csproj | 4 +--
20+
.../Microsoft.Build.Tasks.CodeAnalysis.csproj | 2 +-
21+
src/Compilers/Core/MSBuildTask/Utilities.cs | 14 ++++----
22+
.../VBCSCompiler/ClientConnectionHandler.cs | 1 -
1123
.../Server/VBCSCompiler/VBCSCompiler.csproj | 4 +--
1224
src/Compilers/VisualBasic/vbc/vbc.csproj | 2 +-
25+
...Microsoft.NETCore.Compilers.Package.csproj | 2 +-
1326
.../CoreClrCompilerArtifacts.targets | 36 +++++++++----------
1427
...osoft.Net.Compilers.Toolset.Package.csproj | 16 ++++-----
15-
.../Core/CompilerExtensions.projitems | 2 +-
16-
9 files changed, 49 insertions(+), 33 deletions(-)
28+
.../Microsoft.Net.Compilers.Toolset.props | 2 +-
29+
13 files changed, 62 insertions(+), 40 deletions(-)
1730

31+
diff --git a/Directory.Build.props b/Directory.Build.props
32+
index 05f2dcec7d6..e468e163eb6 100644
33+
--- a/Directory.Build.props
34+
+++ b/Directory.Build.props
35+
@@ -2,5 +2,10 @@
36+
<Project>
37+
<Import Project="Sdk.props" Sdk="Microsoft.DotNet.Arcade.Sdk" />
38+
<Import Project="eng\targets\Settings.props" />
39+
+
40+
+ <PropertyGroup>
41+
+ <WarningsNotAsErrors>$(WarningsNotAsErrors);CS8600;CS8602;CS8603;CS8604;CS8605;CS8777</WarningsNotAsErrors>
42+
+ </PropertyGroup>
43+
+
44+
</Project>
45+
1846
diff --git a/Directory.Build.targets b/Directory.Build.targets
1947
index 8f38a48cd95..c8ba19fdf98 100644
2048
--- a/Directory.Build.targets
@@ -65,18 +93,9 @@ index 01e6741bb09..0d1b86f4a69 100644
6593
<ItemGroup>
6694
<Compile Include="..\..\Shared\RuntimeHostInfo.cs" />
6795
diff --git a/src/Compilers/Core/MSBuildTask/Microsoft.Build.Tasks.CodeAnalysis.csproj b/src/Compilers/Core/MSBuildTask/Microsoft.Build.Tasks.CodeAnalysis.csproj
68-
index 9802a8ebac0..98ec812d772 100644
96+
index 9802a8ebac0..f3b6f741aa1 100644
6997
--- a/src/Compilers/Core/MSBuildTask/Microsoft.Build.Tasks.CodeAnalysis.csproj
7098
+++ b/src/Compilers/Core/MSBuildTask/Microsoft.Build.Tasks.CodeAnalysis.csproj
71-
@@ -41,7 +41,7 @@
72-
<Compile Include="..\Portable\InternalUtilities\CommandLineUtilities.cs" />
73-
<Compile Include="..\Portable\InternalUtilities\CompilerOptionParseUtilities.cs" />
74-
<Compile Include="..\Portable\InternalUtilities\Debug.cs" Link="Debug.cs" />
75-
- <Compile Include="..\Portable\InternalUtilities\IReadOnlySet.cs" />
76-
+ <Compile Include="..\Portable\InternalUtilities\IReadOnlySet.cs" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))" />
77-
<Compile Include="..\Portable\InternalUtilities\NullableAttributes.cs" />
78-
<Compile Include="..\Portable\InternalUtilities\PlatformInformation.cs" />
79-
<Compile Include="..\Portable\InternalUtilities\ReflectionUtilities.cs" />
8099
@@ -54,7 +54,7 @@
81100
<ItemGroup>
82101
<PackageReference Include="Microsoft.Build.Framework" Version="$(MicrosoftBuildFrameworkVersion)" ExcludeAssets="Runtime" />
@@ -86,6 +105,43 @@ index 9802a8ebac0..98ec812d772 100644
86105
</ItemGroup>
87106
<ItemGroup>
88107
<InternalsVisibleTo Include="Microsoft.Build.Tasks.CodeAnalysis.UnitTests" />
108+
diff --git a/src/Compilers/Core/MSBuildTask/Utilities.cs b/src/Compilers/Core/MSBuildTask/Utilities.cs
109+
index 74da0c2bdd3..b6af0715406 100644
110+
--- a/src/Compilers/Core/MSBuildTask/Utilities.cs
111+
+++ b/src/Compilers/Core/MSBuildTask/Utilities.cs
112+
@@ -154,12 +154,14 @@ internal static void DeleteNoThrow(string path)
113+
114+
internal static string? TryGetAssemblyPath(Assembly assembly)
115+
{
116+
- if (assembly.GlobalAssemblyCache)
117+
- {
118+
- return null;
119+
- }
120+
-
121+
- if (assembly.CodeBase is { } codebase)
122+
+ // Removed: error CS0618: 'Assembly.GlobalAssemblyCache' is obsolete: 'The Global Assembly Cache is not supported.'
123+
+ // if (assembly.GlobalAssemblyCache)
124+
+ // {
125+
+ // return null;
126+
+ // }
127+
+
128+
+ // error CS0618: 'Assembly.CodeBase' is obsolete: 'Assembly.CodeBase and Assembly.EscapedCodeBase are only included for .NET Framework compatibility. Use Assembly.Location instead.'
129+
+ if (assembly.Location is { } codebase)
130+
{
131+
var uri = new Uri(codebase);
132+
return uri.IsFile ? uri.LocalPath : assembly.Location;
133+
diff --git a/src/Compilers/Server/VBCSCompiler/ClientConnectionHandler.cs b/src/Compilers/Server/VBCSCompiler/ClientConnectionHandler.cs
134+
index 6bda91e310b..ce7b044b208 100644
135+
--- a/src/Compilers/Server/VBCSCompiler/ClientConnectionHandler.cs
136+
+++ b/src/Compilers/Server/VBCSCompiler/ClientConnectionHandler.cs
137+
@@ -8,7 +8,6 @@
138+
using System.IO;
139+
using System.IO.Pipes;
140+
using System.Net.Sockets;
141+
-using System.Runtime.InteropServices.WindowsRuntime;
142+
using System.Text;
143+
using System.Threading;
144+
using System.Threading.Tasks;
89145
diff --git a/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj b/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj
90146
index ec4dd26af5c..f43748ae3da 100644
91147
--- a/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj
@@ -114,6 +170,19 @@ index 48843d2c542..4432fa0a2f2 100644
114170
</ItemGroup>
115171
<ItemGroup>
116172
<Compile Include="..\..\Shared\RuntimeHostInfo.cs" />
173+
diff --git a/src/NuGet/Microsoft.NETCore.Compilers/Microsoft.NETCore.Compilers.Package.csproj b/src/NuGet/Microsoft.NETCore.Compilers/Microsoft.NETCore.Compilers.Package.csproj
174+
index dcb5df09f24..0f3093bdc54 100644
175+
--- a/src/NuGet/Microsoft.NETCore.Compilers/Microsoft.NETCore.Compilers.Package.csproj
176+
+++ b/src/NuGet/Microsoft.NETCore.Compilers/Microsoft.NETCore.Compilers.Package.csproj
177+
@@ -1,7 +1,7 @@
178+
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. -->
179+
<Project Sdk="Microsoft.NET.Sdk">
180+
<PropertyGroup>
181+
- <TargetFramework>netcoreapp3.1</TargetFramework>
182+
+ <TargetFramework>$(TargetFrameworkForNETSDK)</TargetFramework>
183+
184+
<IsPackable>true</IsPackable>
185+
<ExcludeFromSourceBuild>false</ExcludeFromSourceBuild>
117186
diff --git a/src/NuGet/Microsoft.Net.Compilers.Toolset/CoreClrCompilerArtifacts.targets b/src/NuGet/Microsoft.Net.Compilers.Toolset/CoreClrCompilerArtifacts.targets
118187
index 45590df74bb..f34eea8d105 100644
119188
--- a/src/NuGet/Microsoft.Net.Compilers.Toolset/CoreClrCompilerArtifacts.targets
@@ -218,19 +287,19 @@ index cefd5f48e0f..6aab5fae98b 100644
218287
- <Import Project="CoreClrCompilerArtifacts.targets" Condition="'$(TargetFramework)' == 'netcoreapp3.1'" />
219288
+ <Import Project="CoreClrCompilerArtifacts.targets" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'netcoreapp3.1'))" />
220289
</Project>
221-
diff --git a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems
222-
index 7e8add9bbc2..edda3ef935f 100644
223-
--- a/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems
224-
+++ b/src/Workspaces/SharedUtilitiesAndExtensions/Compiler/Core/CompilerExtensions.projitems
225-
@@ -12,7 +12,7 @@
226-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\Debug.cs" Link="InternalUtilities\Debug.cs" />
227-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\EnumerableExtensions.cs" Link="InternalUtilities\EnumerableExtensions.cs" />
228-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\ExceptionUtilities.cs" Link="InternalUtilities\ExceptionUtilities.cs" />
229-
- <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\IReadOnlySet.cs" Link="InternalUtilities\IReadOnlySet.cs" />
230-
+ <Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\IReadOnlySet.cs" Link="InternalUtilities\IReadOnlySet.cs" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net5.0'))" />
231-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\KeyValuePairUtil.cs" Link="InternalUtilities\KeyValuePairUtil.cs" />
232-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\NonCopyableAttribute.cs" Link="InternalUtilities\NonCopyableAttribute.cs" />
233-
<Compile Include="$(MSBuildThisFileDirectory)..\..\..\..\Compilers\Core\Portable\InternalUtilities\NonDefaultableAttribute.cs" Link="InternalUtilities\NonDefaultableAttribute.cs" />
290+
diff --git a/src/NuGet/Microsoft.Net.Compilers.Toolset/build/Microsoft.Net.Compilers.Toolset.props b/src/NuGet/Microsoft.Net.Compilers.Toolset/build/Microsoft.Net.Compilers.Toolset.props
291+
index 157388e0be7..aac3dcdee92 100644
292+
--- a/src/NuGet/Microsoft.Net.Compilers.Toolset/build/Microsoft.Net.Compilers.Toolset.props
293+
+++ b/src/NuGet/Microsoft.Net.Compilers.Toolset/build/Microsoft.Net.Compilers.Toolset.props
294+
@@ -2,7 +2,7 @@
295+
<Project>
296+
297+
<PropertyGroup>
298+
- <_RoslynTargetDirectoryName Condition="'$(MSBuildRuntimeType)' == 'Core'">netcoreapp3.1</_RoslynTargetDirectoryName>
299+
+ <_RoslynTargetDirectoryName Condition="'$(MSBuildRuntimeType)' == 'Core'">net5.0</_RoslynTargetDirectoryName>
300+
<_RoslynTargetDirectoryName Condition="'$(MSBuildRuntimeType)' != 'Core'">net472</_RoslynTargetDirectoryName>
301+
<_RoslynTasksDirectory>$(MSBuildThisFileDirectory)..\tasks\$(_RoslynTargetDirectoryName)\</_RoslynTasksDirectory>
302+
<RoslynTasksAssembly>$(_RoslynTasksDirectory)Microsoft.Build.Tasks.CodeAnalysis.dll</RoslynTasksAssembly>
234303
--
235-
2.25.4
304+
2.28.0.windows.1
236305

0 commit comments

Comments
 (0)