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

use an OmniSharp specific message for MSB3644 #2069

Merged
merged 4 commits into from
Jan 24, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 7 additions & 0 deletions src/OmniSharp.MSBuild/Logging/ErrorMessages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace OmniSharp.MSBuild.Logging
{
internal class ErrorMessages
{
internal static 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).";
}
}
18 changes: 15 additions & 3 deletions src/OmniSharp.MSBuild/Logging/MSBuildDiagnostic.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
namespace OmniSharp.MSBuild.Logging
using System;
using OmniSharp.Utilities;

namespace OmniSharp.MSBuild.Logging
{

public class MSBuildDiagnostic
{
public MSBuildDiagnosticSeverity Severity { get; }
Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions src/OmniSharp.MSBuild/Logging/MSBuildLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public ImmutableArray<MSBuildDiagnostic> 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)
Expand Down
25 changes: 25 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\OmniSharp.MSBuild\OmniSharp.MSBuild.csproj" />
<ProjectReference Include="..\..\src\OmniSharp.Shared\OmniSharp.Shared.csproj" />
<ProjectReference Include="..\TestUtility\TestUtility.csproj" />
</ItemGroup>

Expand Down