From 53683f51b709dd33150f8da8fe4aaea44eb642f8 Mon Sep 17 00:00:00 2001 From: filipw Date: Fri, 19 Feb 2021 15:57:06 +0100 Subject: [PATCH 1/4] updated error message for .net 5.0 --- .../Logging/ErrorMessages.cs | 4 +++ .../Logging/MSBuildDiagnostic.cs | 31 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs index 8e35c38a16..169931399e 100644 --- a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -3,5 +3,9 @@ namespace OmniSharp.MSBuild.Logging internal class ErrorMessages { internal const string ReferenceAssembliesNotFoundUnix = "This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. 'omnisharp.useGlobalMono':'always' in C# Extension for VS Code)."; + + internal const string ReferenceAssembliesNotFoundNet50Unix = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { 'msbuild': { 'useBundledOnly': true } }."; + + internal const string ReferenceAssembliesNotFoundNet50Windows = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { 'msbuild': { 'useBundledOnly': true } }."; } } diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs index 92769ad7cf..65511cc9a2 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs @@ -36,20 +36,37 @@ private MSBuildDiagnostic( public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildErrorEventArgs args) { + string diagnosticText = null; + // https://github.com/dotnet/msbuild/blob/v16.8.3/src/Tasks/Resources/Strings.resx#L2155-L2158 // for MSB3644, we should print a different message on Unix because the default one is Windows-specific - var diagnosticText = args.Code.Equals("MSB3644", StringComparison.OrdinalIgnoreCase) - && Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows - ? ErrorMessages.ReferenceAssembliesNotFoundUnix : args.Message; + if (args.Code.Equals("MSB3644", StringComparison.OrdinalIgnoreCase)) + { + // https://github.com/dotnet/msbuild/issues/5820 + // older versions of MSBuild incorrecttly treat 'net5.0' moniker as ".NETFramework 5.0" + // this creates a confusing error message which we convert into a more helpful one + if (args.Message.Contains(".NETFramework 5.0")) + { + diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows + ? ErrorMessages.ReferenceAssembliesNotFoundNet50Unix : ErrorMessages.ReferenceAssembliesNotFoundNet50Windows; + } + else + { + diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows + ? ErrorMessages.ReferenceAssembliesNotFoundUnix : args.Message; + } + } return new MSBuildDiagnostic(MSBuildDiagnosticSeverity.Error, - diagnosticText, args.File, args.ProjectFile, args.Subcategory, args.Code, + diagnosticText ?? args.Message, args.File, args.ProjectFile, args.Subcategory, args.Code, args.LineNumber, args.ColumnNumber, args.EndLineNumber, args.EndColumnNumber); } public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildWarningEventArgs args) - => new MSBuildDiagnostic(MSBuildDiagnosticSeverity.Error, - args.Message, args.File, args.ProjectFile, args.Subcategory, args.Code, - args.LineNumber, args.ColumnNumber, args.EndLineNumber, args.EndColumnNumber); + { + return new(MSBuildDiagnosticSeverity.Error, + args.Message, args.File, args.ProjectFile, args.Subcategory, args.Code, + args.LineNumber, args.ColumnNumber, args.EndLineNumber, args.EndColumnNumber); + } } } From cc75861ff5f069c2791723780bca2f6694bd85da Mon Sep 17 00:00:00 2001 From: filipw Date: Fri, 19 Feb 2021 17:39:30 +0100 Subject: [PATCH 2/4] improve .net 5.0 error handling --- src/OmniSharp.MSBuild/Logging/ErrorMessages.cs | 6 +++--- src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs index 169931399e..68681fe8d0 100644 --- a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -2,10 +2,10 @@ namespace OmniSharp.MSBuild.Logging { internal class ErrorMessages { - internal const string ReferenceAssembliesNotFoundUnix = "This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. 'omnisharp.useGlobalMono':'always' in C# Extension for VS Code)."; + internal const string ReferenceAssembliesNotFoundUnix = "This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. \"omnisharp.useGlobalMono\":\"always\" in C# Extension for VS Code)."; - internal const string ReferenceAssembliesNotFoundNet50Unix = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { 'msbuild': { 'useBundledOnly': true } }."; + internal const string ReferenceAssembliesNotFoundNet50Unix = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; - internal const string ReferenceAssembliesNotFoundNet50Windows = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { 'msbuild': { 'useBundledOnly': true } }."; + internal const string ReferenceAssembliesNotFoundNet50Windows = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; } } diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs index 65511cc9a2..74114e4f9f 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs @@ -43,9 +43,9 @@ public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildErrorE if (args.Code.Equals("MSB3644", StringComparison.OrdinalIgnoreCase)) { // https://github.com/dotnet/msbuild/issues/5820 - // older versions of MSBuild incorrecttly treat 'net5.0' moniker as ".NETFramework 5.0" + // older versions of MSBuild incorrectly treat 'net5.0' moniker as ".NETFramework,Version=v5.0" // this creates a confusing error message which we convert into a more helpful one - if (args.Message.Contains(".NETFramework 5.0")) + if (args.Message.Contains(".NETFramework,Version=v5.0")) { diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows ? ErrorMessages.ReferenceAssembliesNotFoundNet50Unix : ErrorMessages.ReferenceAssembliesNotFoundNet50Windows; From 19116de32384cd662965996357c4b904a1c97ef9 Mon Sep 17 00:00:00 2001 From: filipw Date: Tue, 23 Feb 2021 15:53:06 +0100 Subject: [PATCH 3/4] include .NET 6.0 in the special cases of errors --- src/OmniSharp.MSBuild/Logging/ErrorMessages.cs | 4 ++-- src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs index 68681fe8d0..67d8becf02 100644 --- a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -4,8 +4,8 @@ internal class ErrorMessages { internal const string ReferenceAssembliesNotFoundUnix = "This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. \"omnisharp.useGlobalMono\":\"always\" in C# Extension for VS Code)."; - internal const string ReferenceAssembliesNotFoundNet50Unix = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + internal const string ReferenceAssembliesNotFoundNet50OrHigherUnix = "This project targets {0} but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; - internal const string ReferenceAssembliesNotFoundNet50Windows = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + internal const string ReferenceAssembliesNotFoundNet50OrHigherWindows = "This project targets {0} but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; } } diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs index 74114e4f9f..64845c4516 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs @@ -43,12 +43,17 @@ public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildErrorE if (args.Code.Equals("MSB3644", StringComparison.OrdinalIgnoreCase)) { // https://github.com/dotnet/msbuild/issues/5820 - // older versions of MSBuild incorrectly treat 'net5.0' moniker as ".NETFramework,Version=v5.0" + // older versions of MSBuild incorrectly treat 'net5.0'/'net6.0' moniker as ".NETFramework,Version=v5.0/6.0" // this creates a confusing error message which we convert into a more helpful one if (args.Message.Contains(".NETFramework,Version=v5.0")) { diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows - ? ErrorMessages.ReferenceAssembliesNotFoundNet50Unix : ErrorMessages.ReferenceAssembliesNotFoundNet50Windows; + ? string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherUnix, "NET 5.0") : string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherWindows, "NET 5.0"); + } + else if (args.Message.Contains(".NETFramework,Version=v6.0")) + { + diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows + ? string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherUnix, "NET 6.0") : string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherWindows, "NET 6.0"); } else { From 0f19b0ef10360edea15903e0a954e563c1aa1e8b Mon Sep 17 00:00:00 2001 From: filipw Date: Tue, 23 Feb 2021 15:56:15 +0100 Subject: [PATCH 4/4] further improvements --- src/OmniSharp.MSBuild/Logging/ErrorMessages.cs | 8 ++++++-- src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs | 8 ++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs index 67d8becf02..1358a2debf 100644 --- a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -4,8 +4,12 @@ internal class ErrorMessages { internal const string ReferenceAssembliesNotFoundUnix = "This project targets .NET version that requires reference assemblies that do not ship with OmniSharp out of the box (e.g. .NET Framework). The most common solution is to make sure Mono is installed on your machine (https://mono-project.com/download/) and that OmniSharp is started with that Mono installation (e.g. \"omnisharp.useGlobalMono\":\"always\" in C# Extension for VS Code)."; - internal const string ReferenceAssembliesNotFoundNet50OrHigherUnix = "This project targets {0} but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + internal const string ReferenceAssembliesNotFoundNet50Unix = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code) or, if running on global Mono installation, make sure at least Mono 6.13 is installed on your machine (https://mono-project.com/download/). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; - internal const string ReferenceAssembliesNotFoundNet50OrHigherWindows = "This project targets {0} but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + internal const string ReferenceAssembliesNotFoundNet60Unix = "This project targets .NET 6.0 but the currently used MSBuild is not compatible with it - MSBuild 16.9+ is required. To solve this, run OmniSharp on its embedded Mono (e.g. 'omnisharp.useGlobalMono':'never' in C# Extension for VS Code). Alternatively, add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + + internal const string ReferenceAssembliesNotFoundNet50Windows = "This project targets .NET 5.0 but the currently used MSBuild is not compatible with it - MSBuild 16.8+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.8 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; + + internal const string ReferenceAssembliesNotFoundNet60Windows = "This project targets .NET 6.0 but the currently used MSBuild is not compatible with it - MSBuild 16.9+ is required. To solve this, if you have Visual Studio 2019 installed on your machine, make sure it is updated to version 16.9 or add 'omnisharp.json' to your project root with the setting { \"msbuild\": { \"useBundledOnly\": true } }."; } } diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs index 64845c4516..11f48f0d9a 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs @@ -47,13 +47,13 @@ public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildErrorE // this creates a confusing error message which we convert into a more helpful one if (args.Message.Contains(".NETFramework,Version=v5.0")) { - diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows - ? string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherUnix, "NET 5.0") : string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherWindows, "NET 5.0"); + diagnosticText = Platform.Current.OperatingSystem == Utilities.OperatingSystem.Windows + ? ErrorMessages.ReferenceAssembliesNotFoundNet50Windows : ErrorMessages.ReferenceAssembliesNotFoundNet50Unix; } else if (args.Message.Contains(".NETFramework,Version=v6.0")) { - diagnosticText = Platform.Current.OperatingSystem != Utilities.OperatingSystem.Windows - ? string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherUnix, "NET 6.0") : string.Format(ErrorMessages.ReferenceAssembliesNotFoundNet50OrHigherWindows, "NET 6.0"); + diagnosticText = Platform.Current.OperatingSystem == Utilities.OperatingSystem.Windows + ? ErrorMessages.ReferenceAssembliesNotFoundNet60Windows : ErrorMessages.ReferenceAssembliesNotFoundNet60Unix; } else {