From c26111015968f73ba544cc3fdbfefa8432196f97 Mon Sep 17 00:00:00 2001 From: tmat Date: Wed, 8 May 2024 13:12:38 -0700 Subject: [PATCH 1/4] Remove compile-time dependency from Workspace.MSBuild on Workspace.MSBuild.BuildHost --- .../Build/ProjectBuildManager.cs | 3 +- .../Core/MSBuild.BuildHost/BuildHost.cs | 12 +++----- .../CSharp/CSharpCommandLineArgumentReader.cs | 3 +- .../MSBuild/CSharp/CSharpProjectFile.cs | 4 +-- .../MSBuild/CSharp/CSharpProjectFileLoader.cs | 5 +--- .../MSBuild/Logging/DiagnosticLog.cs | 2 +- .../Logging/MSBuildDiagnosticLogItem.cs | 2 +- .../Logging/MSBuildDiagnosticLogger.cs | 2 +- .../MSBuild/ProjectFile/ProjectFile.cs | 4 +-- .../MSBuild/ProjectFile/ProjectFileLoader.cs | 2 -- .../VisualBasicCommandLineArgumentReader.cs | 3 +- .../VisualBasic/VisualBasicProjectFile.cs | 5 +--- .../VisualBasicProjectFileLoader.cs | 5 +--- .../Core/MSBuild.BuildHost/Program.cs | 3 +- .../Contracts}/DiagnosticLogItem.cs | 2 +- .../Contracts}/DocumentFileInfo.cs | 0 .../Rpc/Contracts/IBuildHost.cs | 21 ++++++++++++++ .../Rpc/Contracts/IProjectFile.cs | 28 +++++++++++++++++++ .../Rpc/{ => Contracts}/JsonSettings.cs | 2 +- .../Contracts}/MonoMSBuildDiscovery.cs | 2 +- .../Contracts}/PackageReference.cs | 4 +-- .../Contracts}/ProjectFileInfo.cs | 2 -- .../Contracts}/ProjectFileReference.cs | 2 +- .../Rpc/{ => Contracts}/Request.cs | 2 +- .../Rpc/{ => Contracts}/Response.cs | 2 +- .../{ => Contracts}/TextReaderExtensions.cs | 2 +- .../Core/MSBuild.BuildHost/Rpc/RpcServer.cs | 2 +- .../MSBuild/BuildHostProcessManager.cs | 2 -- .../MSBuild/MSBuild/DiagnosticReporter.cs | 1 - .../MSBuild/MSBuildProjectLoader.Worker.cs | 1 - .../Core/MSBuild/MSBuild/MSBuildWorkspace.cs | 1 - ...oft.CodeAnalysis.Workspaces.MSBuild.csproj | 20 ++++++------- .../Core/MSBuild/Rpc/RemoteBuildHost.cs | 13 ++++----- .../MSBuild/Rpc/RemoteInvocationException.cs | 2 +- .../Core/MSBuild/Rpc/RemoteProjectFile.cs | 28 +++++++++---------- src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs | 4 +-- ...alysis.Workspaces.MSBuild.UnitTests.csproj | 15 +--------- src/Workspaces/MSBuildTest/NetCoreTests.cs | 6 +--- src/Workspaces/MSBuildTest/RpcTests.cs | 2 -- .../VisualStudioMSBuildWorkspaceTests.cs | 4 +-- 40 files changed, 108 insertions(+), 117 deletions(-) rename src/Workspaces/Core/MSBuild.BuildHost/{MSBuild/Logging => Rpc/Contracts}/DiagnosticLogItem.cs (95%) rename src/Workspaces/Core/MSBuild.BuildHost/{MSBuild/ProjectFile => Rpc/Contracts}/DocumentFileInfo.cs (100%) create mode 100644 src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IBuildHost.cs create mode 100644 src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IProjectFile.cs rename src/Workspaces/Core/MSBuild.BuildHost/Rpc/{ => Contracts}/JsonSettings.cs (96%) rename src/Workspaces/Core/MSBuild.BuildHost/{ => Rpc/Contracts}/MonoMSBuildDiscovery.cs (98%) rename src/Workspaces/Core/MSBuild.BuildHost/{MSBuild/ProjectFile => Rpc/Contracts}/PackageReference.cs (74%) rename src/Workspaces/Core/MSBuild.BuildHost/{MSBuild/ProjectFile => Rpc/Contracts}/ProjectFileInfo.cs (99%) rename src/Workspaces/Core/MSBuild.BuildHost/{MSBuild/ProjectFile => Rpc/Contracts}/ProjectFileReference.cs (94%) rename src/Workspaces/Core/MSBuild.BuildHost/Rpc/{ => Contracts}/Request.cs (94%) rename src/Workspaces/Core/MSBuild.BuildHost/Rpc/{ => Contracts}/Response.cs (89%) rename src/Workspaces/Core/MSBuild.BuildHost/Rpc/{ => Contracts}/TextReaderExtensions.cs (97%) diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Build/ProjectBuildManager.cs b/src/Workspaces/Core/MSBuild.BuildHost/Build/ProjectBuildManager.cs index 0cba06c47234c..05ad5789c365a 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Build/ProjectBuildManager.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Build/ProjectBuildManager.cs @@ -11,11 +11,10 @@ using System.Threading.Tasks; using System.Xml; using Microsoft.Build.Framework; -using Microsoft.CodeAnalysis.MSBuild.Logging; using Roslyn.Utilities; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.MSBuild.Build +namespace Microsoft.CodeAnalysis.MSBuild { internal class ProjectBuildManager { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs index 4bfd90f760c37..f5478135d4dd0 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs @@ -4,7 +4,6 @@ extern alias workspaces; using System.Collections.Immutable; -using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; using System.Runtime.CompilerServices; @@ -13,15 +12,12 @@ using Microsoft.Build.Construction; using Microsoft.Build.Locator; using Microsoft.Build.Logging; -using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Rpc; using Microsoft.Extensions.Logging; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost; +namespace Microsoft.CodeAnalysis.MSBuild; -internal sealed class BuildHost +internal sealed class BuildHost : IBuildHost { private readonly ILogger _logger; private readonly ImmutableDictionary _globalMSBuildProperties; @@ -177,8 +173,8 @@ public async Task LoadProjectFileAsync(string projectFilePath, string langu ProjectFileLoader projectLoader = languageName switch { - LanguageNames.CSharp => new CSharp.CSharpProjectFileLoader(), - LanguageNames.VisualBasic => new VisualBasic.VisualBasicProjectFileLoader(), + LanguageNames.CSharp => new CSharpProjectFileLoader(), + LanguageNames.VisualBasic => new VisualBasicProjectFileLoader(), _ => throw ExceptionUtilities.UnexpectedValue(languageName) }; diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpCommandLineArgumentReader.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpCommandLineArgumentReader.cs index 5908aa94455a3..35bd8d2b0a204 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpCommandLineArgumentReader.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpCommandLineArgumentReader.cs @@ -3,10 +3,9 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; -using Microsoft.CodeAnalysis.MSBuild; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.CSharp +namespace Microsoft.CodeAnalysis.MSBuild { internal class CSharpCommandLineArgumentReader : CommandLineArgumentReader { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFile.cs index 91846935a3ae5..cc81848d8f3e4 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFile.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFile.cs @@ -5,11 +5,9 @@ using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.CSharp +namespace Microsoft.CodeAnalysis.MSBuild { internal class CSharpProjectFile : ProjectFile { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFileLoader.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFileLoader.cs index b578b9d1b0ae9..9f7400d847110 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFileLoader.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/CSharp/CSharpProjectFileLoader.cs @@ -2,12 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.CSharp +namespace Microsoft.CodeAnalysis.MSBuild { internal partial class CSharpProjectFileLoader : ProjectFileLoader { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLog.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLog.cs index 9d30cf894f6a3..aa616bc5e3f5e 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLog.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLog.cs @@ -7,7 +7,7 @@ using System.Collections.Generic; using System.Linq; -namespace Microsoft.CodeAnalysis.MSBuild.Logging +namespace Microsoft.CodeAnalysis.MSBuild { internal class DiagnosticLog : IEnumerable { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogItem.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogItem.cs index b0a3710cf91b5..b1edc6c883208 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogItem.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogItem.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.CodeAnalysis.MSBuild.Logging +namespace Microsoft.CodeAnalysis.MSBuild { internal class MSBuildDiagnosticLogItem : DiagnosticLogItem { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogger.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogger.cs index 0454566bdb2f8..43f720925310d 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogger.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/MSBuildDiagnosticLogger.cs @@ -6,7 +6,7 @@ using Roslyn.Utilities; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.MSBuild.Logging +namespace Microsoft.CodeAnalysis.MSBuild { internal class MSBuildDiagnosticLogger : MSB.Framework.ILogger { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs index 92fb55d25e1b1..788b90134bd08 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFile.cs @@ -11,14 +11,12 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using Roslyn.Utilities; using MSB = Microsoft.Build; namespace Microsoft.CodeAnalysis.MSBuild { - internal abstract class ProjectFile + internal abstract class ProjectFile : IProjectFile { private readonly ProjectFileLoader _loader; private readonly MSB.Evaluation.Project? _loadedProject; diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileLoader.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileLoader.cs index d63ccabff51d7..382d61e014f62 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileLoader.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileLoader.cs @@ -5,8 +5,6 @@ using System; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using MSB = Microsoft.Build; namespace Microsoft.CodeAnalysis.MSBuild diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicCommandLineArgumentReader.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicCommandLineArgumentReader.cs index 4264b0dc46efc..829829239183d 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicCommandLineArgumentReader.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicCommandLineArgumentReader.cs @@ -4,11 +4,10 @@ using System; using System.Collections.Immutable; -using Microsoft.CodeAnalysis.MSBuild; using Roslyn.Utilities; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.VisualBasic +namespace Microsoft.CodeAnalysis.MSBuild { internal class VisualBasicCommandLineArgumentReader : CommandLineArgumentReader { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFile.cs index d8f195f136e76..2acfd35e517e1 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFile.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFile.cs @@ -4,12 +4,9 @@ using System.Collections.Generic; using System.Collections.Immutable; -using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.VisualBasic +namespace Microsoft.CodeAnalysis.MSBuild { internal class VisualBasicProjectFile : ProjectFile { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs index 99f82fa28e1e6..0ccc774e167f4 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/VisualBasic/VisualBasicProjectFileLoader.cs @@ -2,12 +2,9 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Build; -using Microsoft.CodeAnalysis.MSBuild.Logging; using MSB = Microsoft.Build; -namespace Microsoft.CodeAnalysis.VisualBasic +namespace Microsoft.CodeAnalysis.MSBuild { internal partial class VisualBasicProjectFileLoader : ProjectFileLoader { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Program.cs b/src/Workspaces/Core/MSBuild.BuildHost/Program.cs index 973f7d5151535..f9ef8bba6243d 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Program.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Program.cs @@ -6,11 +6,10 @@ using System.Collections.Immutable; using System.CommandLine; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.MSBuild.Rpc; using Microsoft.Extensions.Logging; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost; +namespace Microsoft.CodeAnalysis.MSBuild; internal static class Program { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLogItem.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/DiagnosticLogItem.cs similarity index 95% rename from src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLogItem.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/DiagnosticLogItem.cs index 5be36343b592d..7b9d8897001f5 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/Logging/DiagnosticLogItem.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/DiagnosticLogItem.cs @@ -5,7 +5,7 @@ using System; using System.Runtime.Serialization; -namespace Microsoft.CodeAnalysis.MSBuild.Logging +namespace Microsoft.CodeAnalysis.MSBuild { [DataContract] internal class DiagnosticLogItem diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/DocumentFileInfo.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/DocumentFileInfo.cs similarity index 100% rename from src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/DocumentFileInfo.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/DocumentFileInfo.cs diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IBuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IBuildHost.cs new file mode 100644 index 0000000000000..dcc0e48ef2f5d --- /dev/null +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IBuildHost.cs @@ -0,0 +1,21 @@ +// 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. + +using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.CodeAnalysis.MSBuild; + +/// +/// RPC methods. +/// +internal interface IBuildHost +{ + bool HasUsableMSBuild(string projectOrSolutionFilePath); + ImmutableArray<(string ProjectPath, string ProjectGuid)> GetProjectsInSolution(string solutionFilePath); + Task LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken); + Task TryGetProjectOutputPathAsync(string projectFilePath, CancellationToken cancellationToken); + Task ShutdownAsync(); +} diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IProjectFile.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IProjectFile.cs new file mode 100644 index 0000000000000..7d93476b118ef --- /dev/null +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/IProjectFile.cs @@ -0,0 +1,28 @@ +// 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. + +using System.Collections.Immutable; +using System.Threading; +using System.Threading.Tasks; + +namespace Microsoft.CodeAnalysis.MSBuild; + +/// +/// RPC methods. +/// +internal interface IProjectFile +{ + ImmutableArray GetDiagnosticLogItems(); + string GetDocumentExtension(SourceCodeKind kind); + Task> GetProjectFileInfosAsync(CancellationToken cancellationToken); + void AddDocument(string filePath, string? logicalPath); + void RemoveDocument(string filePath); + void AddMetadataReference(string metadataReferenceIdentity, MetadataReferenceProperties properties, string? hintPath); + void RemoveMetadataReference(string shortAssemblyName, string fullAssemblyName, string filePath); + void AddProjectReference(string projectName, ProjectFileReference reference); + void RemoveProjectReference(string projectName, string projectFilePath); + void AddAnalyzerReference(string fullPath); + void RemoveAnalyzerReference(string fullPath); + void Save(); +} diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/JsonSettings.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/JsonSettings.cs similarity index 96% rename from src/Workspaces/Core/MSBuild.BuildHost/Rpc/JsonSettings.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/JsonSettings.cs index a4dee42f83fcf..ee75ca9bf1ca5 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/JsonSettings.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/JsonSettings.cs @@ -6,7 +6,7 @@ using Newtonsoft.Json; using Newtonsoft.Json.Serialization; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal static class JsonSettings { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MonoMSBuildDiscovery.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/MonoMSBuildDiscovery.cs similarity index 98% rename from src/Workspaces/Core/MSBuild.BuildHost/MonoMSBuildDiscovery.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/MonoMSBuildDiscovery.cs index e8f11292cb262..99a376391a654 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MonoMSBuildDiscovery.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/MonoMSBuildDiscovery.cs @@ -9,7 +9,7 @@ using System.Runtime.InteropServices; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost; +namespace Microsoft.CodeAnalysis.MSBuild; internal static class MonoMSBuildDiscovery { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/PackageReference.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/PackageReference.cs similarity index 74% rename from src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/PackageReference.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/PackageReference.cs index a337cfded8bfc..f637b25ff8b32 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/PackageReference.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/PackageReference.cs @@ -1,9 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -using System.Collections.Immutable; -using System.Diagnostics; using System.Runtime.Serialization; namespace Microsoft.CodeAnalysis.MSBuild; diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileInfo.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileInfo.cs similarity index 99% rename from src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileInfo.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileInfo.cs index bd5fbd6371bf6..e5ac67ffd9721 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileInfo.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileInfo.cs @@ -3,9 +3,7 @@ // See the LICENSE file in the project root for more information. using System.Collections.Immutable; -using System.Diagnostics; using System.Runtime.Serialization; -using Microsoft.CodeAnalysis.MSBuild.Logging; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.MSBuild diff --git a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileReference.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileReference.cs similarity index 94% rename from src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileReference.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileReference.cs index fb8d3a216e32a..7a27a20ea17c1 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/MSBuild/ProjectFile/ProjectFileReference.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/ProjectFileReference.cs @@ -28,7 +28,7 @@ internal sealed class ProjectFileReference public ImmutableArray Aliases { get; } /// - /// The value of . + /// The value of "ReferenceOutputAssembly" metadata. /// [DataMember(Order = 2)] public bool ReferenceOutputAssembly { get; } diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Request.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Request.cs similarity index 94% rename from src/Workspaces/Core/MSBuild.BuildHost/Rpc/Request.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Request.cs index 0a7d7beae83e9..4b27b8c022e8a 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Request.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Request.cs @@ -5,7 +5,7 @@ using System.Collections.Immutable; using Newtonsoft.Json.Linq; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class Request { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Response.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Response.cs similarity index 89% rename from src/Workspaces/Core/MSBuild.BuildHost/Rpc/Response.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Response.cs index 2fa7d6e3efe61..ff8a604b80a02 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Response.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/Response.cs @@ -4,7 +4,7 @@ using Newtonsoft.Json.Linq; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class Response { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/TextReaderExtensions.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/TextReaderExtensions.cs similarity index 97% rename from src/Workspaces/Core/MSBuild.BuildHost/Rpc/TextReaderExtensions.cs rename to src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/TextReaderExtensions.cs index 8778e50b619ea..b476ad5a1a105 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/TextReaderExtensions.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/Contracts/TextReaderExtensions.cs @@ -7,7 +7,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal static class TextReaderExtensions { diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/RpcServer.cs b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/RpcServer.cs index 3390c68f5f450..a6a08b8ed3050 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Rpc/RpcServer.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Rpc/RpcServer.cs @@ -13,7 +13,7 @@ using Newtonsoft.Json.Linq; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; /// /// Implements the server side of the RPC channel used to communicate with the build host. diff --git a/src/Workspaces/Core/MSBuild/MSBuild/BuildHostProcessManager.cs b/src/Workspaces/Core/MSBuild/MSBuild/BuildHostProcessManager.cs index 0bdbcd428bba0..928ff407b8b67 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/BuildHostProcessManager.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/BuildHostProcessManager.cs @@ -14,8 +14,6 @@ using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; -using Microsoft.CodeAnalysis.MSBuild.Rpc; -using Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost; using Microsoft.Extensions.Logging; using Roslyn.Utilities; diff --git a/src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporter.cs b/src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporter.cs index b32d95b27ad91..450024049fb33 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporter.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/DiagnosticReporter.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.Immutable; -using Microsoft.CodeAnalysis.MSBuild.Logging; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.MSBuild diff --git a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs index 19c234bb6c285..8a89561728484 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildProjectLoader.Worker.cs @@ -14,7 +14,6 @@ using System.Threading.Tasks; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Host; -using Microsoft.CodeAnalysis.MSBuild.Build; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; diff --git a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildWorkspace.cs b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildWorkspace.cs index 35e8f99bf2704..92b03542374ce 100644 --- a/src/Workspaces/Core/MSBuild/MSBuild/MSBuildWorkspace.cs +++ b/src/Workspaces/Core/MSBuild/MSBuild/MSBuildWorkspace.cs @@ -15,7 +15,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.MSBuild.Rpc; using Microsoft.CodeAnalysis.Shared.Extensions; using Microsoft.CodeAnalysis.Text; using Roslyn.Utilities; diff --git a/src/Workspaces/Core/MSBuild/Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj b/src/Workspaces/Core/MSBuild/Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj index 6fb4366c78c83..9b3e73b619771 100644 --- a/src/Workspaces/Core/MSBuild/Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj +++ b/src/Workspaces/Core/MSBuild/Microsoft.CodeAnalysis.Workspaces.MSBuild.csproj @@ -24,10 +24,7 @@ - - - + @@ -38,7 +35,7 @@ for it. PrivateAssets="all" is needed to prevent this reference from becoming a package reference in the package, as a workaround for https://github.com/NuGet/Home/issues/3891. --> - + true @@ -50,12 +47,7 @@ InternalUtilities\GlobalAssemblyCache.cs - - - - - - + @@ -63,6 +55,12 @@ + + + + + + diff --git a/src/Workspaces/Core/MSBuild/Rpc/RemoteBuildHost.cs b/src/Workspaces/Core/MSBuild/Rpc/RemoteBuildHost.cs index 808d2885e646a..5a457f05da7e8 100644 --- a/src/Workspaces/Core/MSBuild/Rpc/RemoteBuildHost.cs +++ b/src/Workspaces/Core/MSBuild/Rpc/RemoteBuildHost.cs @@ -6,9 +6,8 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class RemoteBuildHost { @@ -23,22 +22,22 @@ public RemoteBuildHost(RpcClient client) } public Task HasUsableMSBuildAsync(string projectOrSolutionFilePath, CancellationToken cancellationToken) - => _client.InvokeAsync(BuildHostTargetObject, nameof(BuildHost.HasUsableMSBuild), parameters: [projectOrSolutionFilePath], cancellationToken); + => _client.InvokeAsync(BuildHostTargetObject, nameof(IBuildHost.HasUsableMSBuild), parameters: [projectOrSolutionFilePath], cancellationToken); public Task> GetProjectsInSolutionAsync(string solutionFilePath, CancellationToken cancellationToken) - => _client.InvokeAsync>(BuildHostTargetObject, nameof(BuildHost.GetProjectsInSolution), parameters: [solutionFilePath], cancellationToken); + => _client.InvokeAsync>(BuildHostTargetObject, nameof(IBuildHost.GetProjectsInSolution), parameters: [solutionFilePath], cancellationToken); public async Task LoadProjectFileAsync(string projectFilePath, string languageName, CancellationToken cancellationToken) { - var remoteProjectFileTargetObject = await _client.InvokeAsync(BuildHostTargetObject, nameof(BuildHost.LoadProjectFileAsync), parameters: [projectFilePath, languageName], cancellationToken).ConfigureAwait(false); + var remoteProjectFileTargetObject = await _client.InvokeAsync(BuildHostTargetObject, nameof(IBuildHost.LoadProjectFileAsync), parameters: [projectFilePath, languageName], cancellationToken).ConfigureAwait(false); return new RemoteProjectFile(_client, remoteProjectFileTargetObject); } public Task TryGetProjectOutputPathAsync(string projectFilePath, CancellationToken cancellationToken) - => _client.InvokeNullableAsync(BuildHostTargetObject, nameof(BuildHost.TryGetProjectOutputPathAsync), parameters: [projectFilePath], cancellationToken); + => _client.InvokeNullableAsync(BuildHostTargetObject, nameof(IBuildHost.TryGetProjectOutputPathAsync), parameters: [projectFilePath], cancellationToken); public Task ShutdownAsync(CancellationToken cancellationToken) - => _client.InvokeAsync(BuildHostTargetObject, nameof(BuildHost.ShutdownAsync), parameters: [], cancellationToken); + => _client.InvokeAsync(BuildHostTargetObject, nameof(IBuildHost.ShutdownAsync), parameters: [], cancellationToken); } diff --git a/src/Workspaces/Core/MSBuild/Rpc/RemoteInvocationException.cs b/src/Workspaces/Core/MSBuild/Rpc/RemoteInvocationException.cs index 0e3d803737ceb..61fde83b8a63c 100644 --- a/src/Workspaces/Core/MSBuild/Rpc/RemoteInvocationException.cs +++ b/src/Workspaces/Core/MSBuild/Rpc/RemoteInvocationException.cs @@ -4,7 +4,7 @@ using System; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class RemoteInvocationException : Exception { diff --git a/src/Workspaces/Core/MSBuild/Rpc/RemoteProjectFile.cs b/src/Workspaces/Core/MSBuild/Rpc/RemoteProjectFile.cs index a2ce680237812..59b91fbb346c2 100644 --- a/src/Workspaces/Core/MSBuild/Rpc/RemoteProjectFile.cs +++ b/src/Workspaces/Core/MSBuild/Rpc/RemoteProjectFile.cs @@ -5,10 +5,8 @@ using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Logging; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class RemoteProjectFile { @@ -22,38 +20,38 @@ public RemoteProjectFile(RpcClient client, int remoteProjectFileTargetObject) } public Task> GetDiagnosticLogItemsAsync(CancellationToken cancellationToken) - => _client.InvokeAsync>(_remoteProjectFileTargetObject, nameof(ProjectFile.GetDiagnosticLogItems), parameters: [], cancellationToken); + => _client.InvokeAsync>(_remoteProjectFileTargetObject, nameof(IProjectFile.GetDiagnosticLogItems), parameters: [], cancellationToken); public Task GetDocumentExtensionAsync(SourceCodeKind sourceCodeKind, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.GetDocumentExtension), parameters: [sourceCodeKind], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.GetDocumentExtension), parameters: [sourceCodeKind], cancellationToken); public Task> GetProjectFileInfosAsync(CancellationToken cancellationToken) - => _client.InvokeAsync>(_remoteProjectFileTargetObject, nameof(ProjectFile.GetProjectFileInfosAsync), parameters: [], cancellationToken); + => _client.InvokeAsync>(_remoteProjectFileTargetObject, nameof(IProjectFile.GetProjectFileInfosAsync), parameters: [], cancellationToken); public Task AddDocumentAsync(string filePath, string? logicalPath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.AddDocument), parameters: [filePath, logicalPath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.AddDocument), parameters: [filePath, logicalPath], cancellationToken); public Task RemoveDocumentAsync(string filePath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.RemoveDocument), parameters: [filePath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.RemoveDocument), parameters: [filePath], cancellationToken); public Task AddMetadataReferenceAsync(string metadataReferenceIdentity, MetadataReferenceProperties properties, string? hintPath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.AddMetadataReference), parameters: [metadataReferenceIdentity, properties, hintPath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.AddMetadataReference), parameters: [metadataReferenceIdentity, properties, hintPath], cancellationToken); public Task RemoveMetadataReferenceAsync(string shortAssemblyName, string fullAssemblyName, string filePath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.RemoveMetadataReference), parameters: [shortAssemblyName, fullAssemblyName, filePath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.RemoveMetadataReference), parameters: [shortAssemblyName, fullAssemblyName, filePath], cancellationToken); public Task AddProjectReferenceAsync(string projectName, ProjectFileReference projectFileReference, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.AddProjectReference), parameters: [projectName, projectFileReference], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.AddProjectReference), parameters: [projectName, projectFileReference], cancellationToken); public Task RemoveProjectReferenceAsync(string projectName, string projectFilePath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.RemoveProjectReference), parameters: [projectName, projectFilePath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.RemoveProjectReference), parameters: [projectName, projectFilePath], cancellationToken); public Task AddAnalyzerReferenceAsync(string fullPath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.AddAnalyzerReference), parameters: [fullPath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.AddAnalyzerReference), parameters: [fullPath], cancellationToken); public Task RemoveAnalyzerReferenceAsync(string fullPath, CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.RemoveAnalyzerReference), parameters: [fullPath], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.RemoveAnalyzerReference), parameters: [fullPath], cancellationToken); public Task SaveAsync(CancellationToken cancellationToken) - => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(ProjectFile.Save), parameters: [], cancellationToken); + => _client.InvokeAsync(_remoteProjectFileTargetObject, nameof(IProjectFile.Save), parameters: [], cancellationToken); } diff --git a/src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs b/src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs index 76873433c4c38..83d1a7b43c068 100644 --- a/src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs +++ b/src/Workspaces/Core/MSBuild/Rpc/RpcClient.cs @@ -13,10 +13,10 @@ using Newtonsoft.Json.Linq; using Roslyn.Utilities; -namespace Microsoft.CodeAnalysis.MSBuild.Rpc; +namespace Microsoft.CodeAnalysis.MSBuild; /// -/// Implements the client side of the RPC channel used to communicate with the build host, which is using . +/// Implements the client side of the RPC channel used to communicate with the build host, which is using RpcServer. /// /// /// The RPC system implemented here is pretty close to something like JSON-RPC; however since we need the Build Host to be usable in Source Build diff --git a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj index 0908804fdba4a..fb8224323dc55 100644 --- a/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj +++ b/src/Workspaces/MSBuildTest/Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests.csproj @@ -7,29 +7,16 @@ $(NetRoslyn);net472 - - - - - - - - - - - - - - + diff --git a/src/Workspaces/MSBuildTest/NetCoreTests.cs b/src/Workspaces/MSBuildTest/NetCoreTests.cs index d58776c25f9d9..1af40888ed5e5 100644 --- a/src/Workspaces/MSBuildTest/NetCoreTests.cs +++ b/src/Workspaces/MSBuildTest/NetCoreTests.cs @@ -6,15 +6,11 @@ using System; using System.Collections.Generic; -using System.Collections.Immutable; using System.IO; using System.Linq; -using System.Threading; using System.Threading.Tasks; using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.MSBuild.Build; using Microsoft.CodeAnalysis.Test.Utilities; -using Microsoft.CodeAnalysis.UnitTests; using Microsoft.CodeAnalysis.UnitTests.TestFiles; using Microsoft.CodeAnalysis.VisualBasic; using Roslyn.Test.Utilities; @@ -443,7 +439,7 @@ public async Task TestOpenProject_OverrideTFM() DotNetRestore(@"Library\Library.csproj"); // Override the TFM properties defined in the file - using (var workspace = CreateMSBuildWorkspace((PropertyNames.TargetFramework, ""), (PropertyNames.TargetFrameworks, "net6;net5"))) + using (var workspace = CreateMSBuildWorkspace(("TargetFramework", ""), ("TargetFrameworks", "net6;net5"))) { await workspace.OpenProjectAsync(projectFilePath); diff --git a/src/Workspaces/MSBuildTest/RpcTests.cs b/src/Workspaces/MSBuildTest/RpcTests.cs index ef05081a1ddd9..fd0e2a55f18ae 100644 --- a/src/Workspaces/MSBuildTest/RpcTests.cs +++ b/src/Workspaces/MSBuildTest/RpcTests.cs @@ -6,8 +6,6 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using Microsoft.CodeAnalysis.MSBuild.Rpc; -using Microsoft.VisualStudio.Telemetry; using Nerdbank.Streams; using Xunit; diff --git a/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs index 230b95db8ef1b..ea9cf6ad02c76 100644 --- a/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs +++ b/src/Workspaces/MSBuildTest/VisualStudioMSBuildWorkspaceTests.cs @@ -17,7 +17,6 @@ using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Host; using Microsoft.CodeAnalysis.Host.Mef; -using Microsoft.CodeAnalysis.MSBuild.Build; using Microsoft.CodeAnalysis.Test.Utilities; using Microsoft.CodeAnalysis.Text; using Microsoft.CodeAnalysis.UnitTests; @@ -3116,7 +3115,6 @@ public async Task TestOpenProject_CommandLineArgsHaveNoErrors() CreateFiles(GetSimpleCSharpSolutionFiles()); using var workspace = CreateMSBuildWorkspace(); - var loader = new CSharpProjectFileLoader(); var projectFilePath = GetSolutionFileName(@"CSharpProject\CSharpProject.csproj"); @@ -3127,7 +3125,7 @@ public async Task TestOpenProject_CommandLineArgsHaveNoErrors() var projectFileInfo = (await projectFile.GetProjectFileInfosAsync(CancellationToken.None)).Single(); var commandLineParser = workspace.Services - .GetLanguageServices(loader.Language) + .GetLanguageServices(LanguageNames.CSharp) .GetRequiredService(); var projectDirectory = Path.GetDirectoryName(projectFilePath); From f7dc81b29ff76cd1bbe5bb64997cfeaa71880d90 Mon Sep 17 00:00:00 2001 From: tmat Date: Wed, 8 May 2024 13:30:23 -0700 Subject: [PATCH 2/4] Remove dependency on Microsoft.Extensions.Logging.Console from MSBuild.BuildHost --- .../Core/MSBuild.BuildHost/BuildHost.cs | 7 +++---- .../Core/MSBuild.BuildHost/BuildHostLogger.cs | 16 ++++++++++++++++ ...nalysis.Workspaces.MSBuild.BuildHost.csproj | 1 - .../Core/MSBuild.BuildHost/Program.cs | 18 ++---------------- 4 files changed, 21 insertions(+), 21 deletions(-) create mode 100644 src/Workspaces/Core/MSBuild.BuildHost/BuildHostLogger.cs diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs index f5478135d4dd0..f5f574bfa167b 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs @@ -12,23 +12,22 @@ using Microsoft.Build.Construction; using Microsoft.Build.Locator; using Microsoft.Build.Logging; -using Microsoft.Extensions.Logging; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.MSBuild; internal sealed class BuildHost : IBuildHost { - private readonly ILogger _logger; + private readonly BuildHostLogger _logger; private readonly ImmutableDictionary _globalMSBuildProperties; private readonly string? _binaryLogPath; private readonly RpcServer _server; private readonly object _gate = new object(); private ProjectBuildManager? _buildManager; - public BuildHost(ILoggerFactory loggerFactory, ImmutableDictionary globalMSBuildProperties, string? binaryLogPath, RpcServer server) + public BuildHost(BuildHostLogger logger, ImmutableDictionary globalMSBuildProperties, string? binaryLogPath, RpcServer server) { - _logger = loggerFactory.CreateLogger(); + _logger = logger; _globalMSBuildProperties = globalMSBuildProperties; _binaryLogPath = binaryLogPath; _server = server; diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHostLogger.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHostLogger.cs new file mode 100644 index 0000000000000..c58341779c7f8 --- /dev/null +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHostLogger.cs @@ -0,0 +1,16 @@ +// 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. + +using System.IO; + +namespace Microsoft.CodeAnalysis.MSBuild; + +internal sealed class BuildHostLogger(TextWriter output) +{ + public void LogInformation(string message) + => output.WriteLine(message); + + public void LogCritical(string message) + => output.WriteLine(message); +} diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj b/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj index 9fe22620bdb1c..a7b366475e9f2 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj +++ b/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj @@ -29,7 +29,6 @@ - diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Program.cs b/src/Workspaces/Core/MSBuild.BuildHost/Program.cs index f9ef8bba6243d..18b67f5d7e705 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Program.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/Program.cs @@ -6,7 +6,6 @@ using System.Collections.Immutable; using System.CommandLine; using System.Threading.Tasks; -using Microsoft.Extensions.Logging; using Roslyn.Utilities; namespace Microsoft.CodeAnalysis.MSBuild; @@ -30,26 +29,13 @@ internal static async Task Main(string[] args) propertiesBuilder.Add(propertyParts[0], propertyParts[1]); } - // Create a console logger that logs everything to standard error instead of standard out; by setting the threshold to Trace - // everything will go to standard error. - var loggerFactory = LoggerFactory.Create(builder => - builder.AddConsole(configure => - { - // DisableColors is deprecated in favor of us moving to simple console, but that loses the LogToStandardErrorThreshold - // which we also need -#pragma warning disable CS0618 - configure.DisableColors = true; -#pragma warning restore CS0618 - configure.LogToStandardErrorThreshold = LogLevel.Trace; - })); - - var logger = loggerFactory.CreateLogger(typeof(Program)); + var logger = new BuildHostLogger(Console.Error); logger.LogInformation($"BuildHost Runtime Version: {System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription}"); var server = new RpcServer(sendingStream: Console.OpenStandardOutput(), receivingStream: Console.OpenStandardInput()); - var targetObject = server.AddTarget(new BuildHost(loggerFactory, propertiesBuilder.ToImmutable(), binaryLogPath, server)); + var targetObject = server.AddTarget(new BuildHost(logger, propertiesBuilder.ToImmutable(), binaryLogPath, server)); Contract.ThrowIfFalse(targetObject == 0, "The first object registered should have target 0, which is assumed by the client."); await server.RunAsync().ConfigureAwait(false); From 8b4fa540769e5c72872e5fe631402ab3c0d08ca7 Mon Sep 17 00:00:00 2001 From: tmat Date: Wed, 8 May 2024 14:16:34 -0700 Subject: [PATCH 3/4] Remove other dependencies on BuildHost --- .../HostWorkspace/LanguageServerProjectSystem.cs | 1 - .../Microsoft.CodeAnalysis.LanguageServer.csproj | 1 - ...nalysis.LanguageServerIndexFormat.Generator.csproj | 10 ---------- .../VS.ExternalAPIs.Roslyn.Package.csproj | 1 - src/Tools/AnalyzerRunner/AnalyzerRunner.csproj | 1 - .../Setup/Roslyn.VisualStudio.Setup.csproj | 11 ----------- 6 files changed, 25 deletions(-) diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs index f68f4a7e7d536..30e61e87b462c 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/HostWorkspace/LanguageServerProjectSystem.cs @@ -12,7 +12,6 @@ using Microsoft.CodeAnalysis.Host.Mef; using Microsoft.CodeAnalysis.LanguageServer.HostWorkspace.ProjectTelemetry; using Microsoft.CodeAnalysis.MSBuild; -using Microsoft.CodeAnalysis.MSBuild.Logging; using Microsoft.CodeAnalysis.Options; using Microsoft.CodeAnalysis.ProjectSystem; using Microsoft.CodeAnalysis.Shared.TestHooks; diff --git a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj index fa42a2d113562..c3e8ab62d162f 100644 --- a/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj +++ b/src/Features/LanguageServer/Microsoft.CodeAnalysis.LanguageServer/Microsoft.CodeAnalysis.LanguageServer.csproj @@ -62,7 +62,6 @@ - diff --git a/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj b/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj index 20ba57b5f5573..6aefd270a5757 100644 --- a/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj +++ b/src/Features/Lsif/Generator/Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator.csproj @@ -81,19 +81,9 @@ - - - - - - - - - diff --git a/src/NuGet/VS.ExternalAPIs.Roslyn.Package/VS.ExternalAPIs.Roslyn.Package.csproj b/src/NuGet/VS.ExternalAPIs.Roslyn.Package/VS.ExternalAPIs.Roslyn.Package.csproj index d62e1c2961bef..6ec1177df567e 100644 --- a/src/NuGet/VS.ExternalAPIs.Roslyn.Package/VS.ExternalAPIs.Roslyn.Package.csproj +++ b/src/NuGet/VS.ExternalAPIs.Roslyn.Package/VS.ExternalAPIs.Roslyn.Package.csproj @@ -49,7 +49,6 @@ - diff --git a/src/Tools/AnalyzerRunner/AnalyzerRunner.csproj b/src/Tools/AnalyzerRunner/AnalyzerRunner.csproj index d3e2de0ff5753..e76457a1358fc 100644 --- a/src/Tools/AnalyzerRunner/AnalyzerRunner.csproj +++ b/src/Tools/AnalyzerRunner/AnalyzerRunner.csproj @@ -22,7 +22,6 @@ - diff --git a/src/VisualStudio/Setup/Roslyn.VisualStudio.Setup.csproj b/src/VisualStudio/Setup/Roslyn.VisualStudio.Setup.csproj index d739438f4952f..7b49bf81a0c9a 100644 --- a/src/VisualStudio/Setup/Roslyn.VisualStudio.Setup.csproj +++ b/src/VisualStudio/Setup/Roslyn.VisualStudio.Setup.csproj @@ -167,17 +167,6 @@ TargetFramework=net472 BindingRedirect - - Workspaces.MSBuild - BuiltProjectOutputGroup;SatelliteDllsProjectOutputGroup - true - TargetFramework=net472 - BindingRedirect - - false - CSharpWorkspace BuiltProjectOutputGroup;SatelliteDllsProjectOutputGroup From d9610ad722e29c7982f66dbbcf584f0baa73321a Mon Sep 17 00:00:00 2001 From: tmat Date: Wed, 8 May 2024 15:17:20 -0700 Subject: [PATCH 4/4] Fix source build --- src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs | 2 +- .../Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs index f5f574bfa167b..bc1e0320e7e40 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs +++ b/src/Workspaces/Core/MSBuild.BuildHost/BuildHost.cs @@ -104,7 +104,7 @@ private bool TryEnsureMSBuildLoaded(string projectOrSolutionFilePath) #if NET472 || NET6_0 // If we're compiling against net472 or net6.0, we get our MemberNotNull from the workspaces assembly. It has it in the net6.0 case since we're consuming the netstandard2.0 version of Workspaces. [workspaces::System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_buildManager))] #else // If we're compiling against net7.0 or higher, then we're getting it staright from the framework. - [MemberNotNull(nameof(_buildManager))] + [System.Diagnostics.CodeAnalysis.MemberNotNull(nameof(_buildManager))] #endif [MethodImpl(MethodImplOptions.NoInlining)] // Do not inline this, since this creates MSBuild types which are being loaded by the caller private void CreateBuildManager() diff --git a/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj b/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj index a7b366475e9f2..c895b665da4dc 100644 --- a/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj +++ b/src/Workspaces/Core/MSBuild.BuildHost/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.csproj @@ -39,8 +39,8 @@ - +