From aaff726daa69c2b688be2bff4540c068049b8fe4 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Wed, 7 Oct 2020 12:28:04 -0700 Subject: [PATCH 1/6] Upgrade our .NET SDK to 5.0 RC 1 --- global.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/global.json b/global.json index a19643d24f773..aaa923904fb3c 100644 --- a/global.json +++ b/global.json @@ -1,11 +1,11 @@ { "sdk": { - "version": "5.0.100-preview.8.20417.9", + "version": "5.0.100-rc.1.20452.10", "allowPrerelease": true, "rollForward": "major" }, "tools": { - "dotnet": "5.0.100-preview.8.20417.9", + "dotnet": "5.0.100-rc.1.20452.10", "vs": { "version": "16.8" }, From c756744877d89d9c083c5e8665b67b5bfccaac99 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 7 Oct 2020 13:19:57 -0700 Subject: [PATCH 2/6] Use SupportedOSPlatformAttribute where necessary --- .../InternalUtilities/PlatformAttributes.cs | 94 +++++++++++++++++++ .../HostProcess/InteractiveHost32.csproj | 4 + .../HostProcess/InteractiveHost64.csproj | 4 + .../HostProcess/InteractiveHostEntryPoint.cs | 4 + 4 files changed, 106 insertions(+) create mode 100644 src/Compilers/Core/Portable/InternalUtilities/PlatformAttributes.cs diff --git a/src/Compilers/Core/Portable/InternalUtilities/PlatformAttributes.cs b/src/Compilers/Core/Portable/InternalUtilities/PlatformAttributes.cs new file mode 100644 index 0000000000000..4990bae8264d3 --- /dev/null +++ b/src/Compilers/Core/Portable/InternalUtilities/PlatformAttributes.cs @@ -0,0 +1,94 @@ +// 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. + +#nullable enable + +#if !NET5_0 + +namespace System.Runtime.Versioning +{ + /// + /// Base type for all platform-specific API attributes. + /// + internal abstract class OSPlatformAttribute : Attribute + { + private protected OSPlatformAttribute(string platformName) + { + PlatformName = platformName; + } + + public string PlatformName { get; } + } + + /// + /// Records the platform that the project targeted. + /// + [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = false, Inherited = false)] + internal sealed class TargetPlatformAttribute : OSPlatformAttribute + { + public TargetPlatformAttribute(string platformName) + : base(platformName) + { + } + } + + /// + /// Records the operating system (and minimum version) that supports an API. Multiple attributes can be + /// applied to indicate support on multiple operating systems. + /// + /// + /// Callers can apply a + /// or use guards to prevent calls to APIs on unsupported operating systems. + /// + /// A given platform should only be specified once. + /// + [AttributeUsage( + AttributeTargets.Assembly + | AttributeTargets.Class + | AttributeTargets.Constructor + | AttributeTargets.Enum + | AttributeTargets.Event + | AttributeTargets.Field + | AttributeTargets.Method + | AttributeTargets.Module + | AttributeTargets.Property + | AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] + internal sealed class SupportedOSPlatformAttribute : OSPlatformAttribute + { + public SupportedOSPlatformAttribute(string platformName) + : base(platformName) + { + } + } + + /// + /// Marks APIs that were removed in a given operating system version. + /// + /// + /// Primarily used by OS bindings to indicate APIs that are only available in + /// earlier versions. + /// + [AttributeUsage( + AttributeTargets.Assembly + | AttributeTargets.Class + | AttributeTargets.Constructor + | AttributeTargets.Enum + | AttributeTargets.Event + | AttributeTargets.Field + | AttributeTargets.Method + | AttributeTargets.Module + | AttributeTargets.Property + | AttributeTargets.Struct, + AllowMultiple = true, Inherited = false)] + internal sealed class UnsupportedOSPlatformAttribute : OSPlatformAttribute + { + public UnsupportedOSPlatformAttribute(string platformName) + : base(platformName) + { + } + } +} + +#endif diff --git a/src/Interactive/HostProcess/InteractiveHost32.csproj b/src/Interactive/HostProcess/InteractiveHost32.csproj index ca1a0ee3144fb..5d501a10f47b7 100644 --- a/src/Interactive/HostProcess/InteractiveHost32.csproj +++ b/src/Interactive/HostProcess/InteractiveHost32.csproj @@ -16,6 +16,10 @@ + + + + diff --git a/src/Interactive/HostProcess/InteractiveHostEntryPoint.cs b/src/Interactive/HostProcess/InteractiveHostEntryPoint.cs index 4ad2601964870..6fcf537f64707 100644 --- a/src/Interactive/HostProcess/InteractiveHostEntryPoint.cs +++ b/src/Interactive/HostProcess/InteractiveHostEntryPoint.cs @@ -6,6 +6,7 @@ using System; using System.Runtime.InteropServices; +using System.Runtime.Versioning; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -15,6 +16,7 @@ namespace Microsoft.CodeAnalysis.Interactive { internal static class InteractiveHostEntryPoint { + [SupportedOSPlatform("windows")] private static async Task Main(string[] args) { FatalError.Handler = FailFast.OnFatalException; @@ -53,9 +55,11 @@ private static async Task Main(string[] args) } } + [SupportedOSPlatform("windows")] [DllImport("kernel32", PreserveSig = true)] internal static extern ErrorMode SetErrorMode(ErrorMode mode); + [SupportedOSPlatform("windows")] [DllImport("kernel32", PreserveSig = true)] internal static extern ErrorMode GetErrorMode(); From 81457f23bba814285217af4806b6b2cb11650592 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 7 Oct 2020 13:23:45 -0700 Subject: [PATCH 3/6] Fix IDE0044 (Make field readonly) --- .../VisualBasic/Portable/Semantics/OverloadResolution.vb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb b/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb index 5509d712336c6..5dbbf1f4bf96b 100644 --- a/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb +++ b/src/Compilers/VisualBasic/Portable/Semantics/OverloadResolution.vb @@ -502,12 +502,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic #If DEBUG Then ' Compile time asserts. Private Const s_delegateRelaxationLevelMask_AssertZero = SmallFieldMask.DelegateRelaxationLevelMask - ConversionKind.DelegateRelaxationLevelMask - Private _delegateRelaxationLevelMask_Assert1(s_delegateRelaxationLevelMask_AssertZero) As Boolean - Private _delegateRelaxationLevelMask_Assert2(-s_delegateRelaxationLevelMask_AssertZero) As Boolean + Private ReadOnly _delegateRelaxationLevelMask_Assert1(s_delegateRelaxationLevelMask_AssertZero) As Boolean + Private ReadOnly _delegateRelaxationLevelMask_Assert2(-s_delegateRelaxationLevelMask_AssertZero) As Boolean Private Const s_inferenceLevelMask_AssertZero = CByte((SmallFieldMask.InferenceLevelMask >> SmallFieldMask.InferenceLevelShift) <> ((TypeArgumentInference.InferenceLevel.Invalid << 1) - 1)) - Private _inferenceLevelMask_Assert1(s_inferenceLevelMask_AssertZero) As Boolean - Private _inferenceLevelMask_Assert2(-s_inferenceLevelMask_AssertZero) As Boolean + Private ReadOnly _inferenceLevelMask_Assert1(s_inferenceLevelMask_AssertZero) As Boolean + Private ReadOnly _inferenceLevelMask_Assert2(-s_inferenceLevelMask_AssertZero) As Boolean #End If Public Structure OptionalArgument Public ReadOnly DefaultValue As BoundExpression From d95d41181ab6b80360afb38a59f47361542e219e Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 7 Oct 2020 13:24:19 -0700 Subject: [PATCH 4/6] Suppress nullability false positives --- .../CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs index ddbeb5d2775f5..e1bdc7185adbb 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/FunctionPointerTests.cs @@ -1614,7 +1614,7 @@ public static void M() .OfType() .Select(s => model.GetSymbolInfo(s).CandidateSymbols.Single()) .Cast() - .Select(m => m.TypeArguments.Single().ToTestDisplayString()) + .Select(m => m!.TypeArguments.Single().ToTestDisplayString()) .ToList(); var expectedTypes = new string[] { @@ -1676,7 +1676,7 @@ public static void M() return symbolInfo.Symbol ?? symbolInfo.CandidateSymbols.Single(); }) .Cast() - .Select(m => m.TypeArguments.Single().ToTestDisplayString()) + .Select(m => m!.TypeArguments.Single().ToTestDisplayString()) .ToList(); var expectedTypes = new string[] { @@ -1749,7 +1749,7 @@ public static void M() return symbolInfo.Symbol ?? symbolInfo.CandidateSymbols.Single(); }) .Cast() - .Select(m => m.TypeArguments.Single().ToTestDisplayString()) + .Select(m => m!.TypeArguments.Single().ToTestDisplayString()) .ToList(); var expectedTypes = new string[] { From a30757d80b238dcf459059339660d7cc683f169e Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 7 Oct 2020 13:24:55 -0700 Subject: [PATCH 5/6] Conditionally mark InitializeLifetimeService obsolete for .NET 5 --- .../CoreTestUtilities/Remote/InProcRemostHostClient.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs b/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs index eae3747ec9a67..c3fae5cb512c0 100644 --- a/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs +++ b/src/Workspaces/CoreTestUtilities/Remote/InProcRemostHostClient.cs @@ -259,6 +259,9 @@ public override int WriteTimeout public override Task CopyToAsync(Stream destination, int bufferSize, CancellationToken cancellationToken) => _stream.CopyToAsync(destination, bufferSize, cancellationToken); +#if NET5_0 + [Obsolete] +#endif public override object InitializeLifetimeService() => throw new NotSupportedException(); From d9f64653ee7a5ff27f975ce832d18610f1688f55 Mon Sep 17 00:00:00 2001 From: Jason Malinowski Date: Wed, 7 Oct 2020 14:36:51 -0700 Subject: [PATCH 6/6] Work around https://github.com/dotnet/sdk/issues/13427 --- eng/targets/Imports.targets | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/eng/targets/Imports.targets b/eng/targets/Imports.targets index f1d6ee86ea9cb..d91c8cdc39726 100644 --- a/eng/targets/Imports.targets +++ b/eng/targets/Imports.targets @@ -404,4 +404,10 @@ + + + <_MicrosoftWindowsDesktopSdkImported>false + +