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

Improve custom error messages for MSB3644 #2097

Merged
merged 4 commits into from
Feb 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/OmniSharp.MSBuild/Logging/ErrorMessages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ 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 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 } }.";
}
}
36 changes: 29 additions & 7 deletions src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,42 @@ 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 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.ReferenceAssembliesNotFoundNet50Windows : ErrorMessages.ReferenceAssembliesNotFoundNet50Unix;
}
else if (args.Message.Contains(".NETFramework,Version=v6.0"))
{
diagnosticText = Platform.Current.OperatingSystem == Utilities.OperatingSystem.Windows
? ErrorMessages.ReferenceAssembliesNotFoundNet60Windows : ErrorMessages.ReferenceAssembliesNotFoundNet60Unix;
}
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);
}
}
}