diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs new file mode 100644 index 0000000000..8e35c38a16 --- /dev/null +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -0,0 +1,7 @@ +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)."; + } +} diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs index 8cc9cf1baf..92769ad7cf 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs @@ -1,5 +1,9 @@ -namespace OmniSharp.MSBuild.Logging +using System; +using OmniSharp.Utilities; + +namespace OmniSharp.MSBuild.Logging { + public class MSBuildDiagnostic { public MSBuildDiagnosticSeverity Severity { get; } @@ -31,9 +35,17 @@ private MSBuildDiagnostic( } public static MSBuildDiagnostic CreateFrom(Microsoft.Build.Framework.BuildErrorEventArgs args) - => new MSBuildDiagnostic(MSBuildDiagnosticSeverity.Error, - args.Message, args.File, args.ProjectFile, args.Subcategory, args.Code, + { + // 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; + + return new MSBuildDiagnostic(MSBuildDiagnosticSeverity.Error, + diagnosticText, 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, diff --git a/src/OmniSharp.MSBuild/Logging/MSBuildLogger.cs b/src/OmniSharp.MSBuild/Logging/MSBuildLogger.cs index 12a652a731..3050a1e270 100644 --- a/src/OmniSharp.MSBuild/Logging/MSBuildLogger.cs +++ b/src/OmniSharp.MSBuild/Logging/MSBuildLogger.cs @@ -26,8 +26,9 @@ public ImmutableArray GetDiagnostics() => private void OnError(object sender, Microsoft.Build.Framework.BuildErrorEventArgs args) { - _logger.LogError(args.Message); - _diagnostics.Add(MSBuildDiagnostic.CreateFrom(args)); + var msBuildDiagnostic = MSBuildDiagnostic.CreateFrom(args); + _logger.LogError(msBuildDiagnostic.Message); + _diagnostics.Add(msBuildDiagnostic); } private void OnWarning(object sender, Microsoft.Build.Framework.BuildWarningEventArgs args) diff --git a/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs new file mode 100644 index 0000000000..a590a51ac8 --- /dev/null +++ b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs @@ -0,0 +1,25 @@ +using Microsoft.Build.Framework; +using OmniSharp.MSBuild.Logging; +using OmniSharp.Utilities; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.MSBuild.Tests +{ + public class MSBuildDiagnosticTests : AbstractMSBuildTestFixture + { + public MSBuildDiagnosticTests(ITestOutputHelper output) : base(output) + { + } + + [Fact] + public void MSB3644_CustomMessage() + { + var sourceDiagnostic = new BuildErrorEventArgs("test-subcategory", "MSB3644", "foo.cs", 1, 1, 1, 1, "Reference assemblies not found!", "help-keyword", "dummy-sender"); + var msbuildDiagnostic = MSBuildDiagnostic.CreateFrom(sourceDiagnostic); + + Assert.Equal(Platform.Current.OperatingSystem != OperatingSystem.Windows + ? ErrorMessages.ReferenceAssembliesNotFoundUnix : sourceDiagnostic.Message, msbuildDiagnostic.Message); + } + } +} diff --git a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj index 7b3bf2de24..3bb59609d7 100644 --- a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj +++ b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj @@ -12,6 +12,7 @@ +