From cd4de6d4bd86c29c8dcb0ec96b1c78bb3c32f2a1 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sat, 19 Feb 2022 12:48:45 -0800 Subject: [PATCH 01/24] Remove MSBuild and Mono from release packages --- build.cake | 476 +----------------- build.json | 4 - build.ps1 | 4 + mono-packaging/copy-mono.sh | 301 ----------- mono-packaging/run | 28 -- scripts/common.cake | 38 +- .../MSBuild/Discovery/DiscoveryType.cs | 5 +- .../MSBuild/Discovery/Extensions.cs | 30 +- .../Discovery/MSBuildInstanceProvider.cs | 36 -- .../MSBuild/Discovery/MSBuildLocator.cs | 55 +- .../Providers/MonoInstanceProvider.cs | 8 - .../Providers/StandAloneInstanceProvider.cs | 58 --- .../Providers/UserOverrideInstanceProvider.cs | 2 +- .../AbstractMSBuildTestFixture.cs | 12 +- .../LoadProjectsOnDemandTests.cs | 4 +- .../MSBuildDiagnosticTests.cs | 4 +- .../MSBuildSelectionTests.cs | 121 +---- .../NotificationTests.cs | 4 +- .../ProjectLoadListenerTests.cs | 3 +- .../ProjectWithAdditionalFilesTests.cs | 4 +- .../ProjectWithAnalyzersTests.cs | 4 +- .../ProjectWithComplexAnalyzersTests.cs | 3 +- .../WorkspaceInformationTests.cs | 4 +- tests/TestUtility/TestServiceProvider.cs | 7 +- tools/packages.config | 74 --- 25 files changed, 72 insertions(+), 1217 deletions(-) delete mode 100755 mono-packaging/copy-mono.sh delete mode 100644 mono-packaging/run delete mode 100644 src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs diff --git a/build.cake b/build.cake index 8ffe383bbc..f836fe4ee1 100644 --- a/build.cake +++ b/build.cake @@ -60,9 +60,7 @@ Task("GitVersion") /// Task("Setup") .IsDependentOn("ValidateMono") - .IsDependentOn("InstallDotNetCoreSdk") - .IsDependentOn("InstallMonoAssets") - .IsDependentOn("CreateMSBuildFolder"); + .IsDependentOn("InstallDotNetCoreSdk"); void InstallDotNetSdk(BuildEnvironment env, BuildPlan plan, string version, string installFolder, bool sharedRuntime = false, bool noPath = false) { @@ -144,382 +142,6 @@ Task("ValidateMono") ValidateMonoVersion(buildPlan); }); -Task("CleanUpMonoAssets") - .WithCriteria(() => !Platform.Current.IsWindows) - .Does(() => -{ - if (DirectoryHelper.Exists(env.Folders.Mono)) - { - DirectoryHelper.Delete(env.Folders.Mono, recursive: true); - } -}); - -Task("InstallMonoAssets") - .WithCriteria(() => !Platform.Current.IsWindows) - .Does(() => -{ - if (DirectoryHelper.Exists(env.Folders.Mono) && !publishAll) - { - Information("Skipping Mono assets installation, because they already exist."); - return; - } - Information("Acquiring Mono runtimes and framework..."); - - DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoRuntimeMacOS}", env.Folders.MonoRuntimeMacOS); - DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoRuntimeLinuxX86}", env.Folders.MonoRuntimeLinuxX86); - DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoRuntimeLinuxX64}", env.Folders.MonoRuntimeLinuxX64); - DownloadFileAndUnzip($"{buildPlan.DownloadURL}/{buildPlan.MonoRuntimeLinuxArm64}", env.Folders.MonoRuntimeLinuxArm64); - - var runScriptFile = CombinePaths(env.Folders.MonoPackaging, "run"); - FileHelper.Copy(runScriptFile, CombinePaths(env.Folders.MonoRuntimeMacOS, "run"), overwrite: true); - FileHelper.Copy(runScriptFile, CombinePaths(env.Folders.MonoRuntimeLinuxX86, "run"), overwrite: true); - FileHelper.Copy(runScriptFile, CombinePaths(env.Folders.MonoRuntimeLinuxX64, "run"), overwrite: true); - FileHelper.Copy(runScriptFile, CombinePaths(env.Folders.MonoRuntimeLinuxArm64, "run"), overwrite: true); - - var monoInstallFolder = env.CurrentMonoRuntime.InstallFolder; - var monoRuntimeFile = env.CurrentMonoRuntime.RuntimeFile; - - DirectoryHelper.ForceCreate(env.Folders.Mono); - DirectoryHelper.Copy(monoInstallFolder, env.Folders.Mono); - - var frameworkFolder = CombinePaths(env.Folders.Mono, "framework"); - DirectoryHelper.ForceCreate(frameworkFolder); - - Run("chmod", $"+x '{CombinePaths(env.Folders.Mono, "bin", monoRuntimeFile)}'"); - Run("chmod", $"+x '{CombinePaths(env.Folders.Mono, "run")}'"); -}); - -void CopyDotNetHostResolver(BuildEnvironment env, string os, string arch, string hostFileName, string targetFolderBase, bool copyToArchSpecificFolder) -{ - var source = CombinePaths( - env.Folders.Tools, - $"runtime.{os}-{arch}.Microsoft.NETCore.DotNetHostResolver", - "runtimes", - $"{os}-{arch}", - "native", - hostFileName); - - var targetFolder = targetFolderBase; - - if (copyToArchSpecificFolder) - { - targetFolder = CombinePaths(targetFolderBase, arch); - DirectoryHelper.ForceCreate(targetFolder); - } - - FileHelper.Copy(source, CombinePaths(targetFolder, hostFileName)); -} - -/// -/// Create '.msbuild' folder and copy content to it. -/// -Task("CreateMSBuildFolder") - .IsDependentOn("InstallMonoAssets") - .Does(() => -{ - DirectoryHelper.ForceCreate(env.Folders.MSBuild); - - var msbuildCurrentTargetFolder = CombinePaths(env.Folders.MSBuild, "Current"); - var msbuildCurrentBinTargetFolder = CombinePaths(msbuildCurrentTargetFolder, "Bin"); - - DirectoryHelper.ForceCreate(msbuildCurrentTargetFolder); - DirectoryHelper.ForceCreate(msbuildCurrentBinTargetFolder); - - var msbuildLibraries = new [] - { - "Microsoft.Build", - "Microsoft.Build.Framework", - "Microsoft.Build.Tasks.Core", - "Microsoft.Build.Utilities.Core" - }; - - var msbuildRefLibraries = new [] - { - "Microsoft.Build.Tasks.v4.0", - "Microsoft.Build.Tasks.v12.0", - "Microsoft.Build.Utilities.v4.0", - "Microsoft.Build.Utilities.v12.0", - }; - - // These dependencies are not included in the Microsoft.NET.Sdk package - // but are necessary for some build tasks. - var msBuildDependencies = new [] - { - "Microsoft.Deployment.DotNet.Releases", - "Microsoft.NET.StringTools", - "Newtonsoft.Json", - "System.Threading.Tasks.Dataflow", - "System.Resources.Extensions" - }; - - // These dependencies are all copied from the Microsoft.NET.Sdk package since - // we are trying to model a particular SDK's build tools. - var msBuildSdkDependencies = new [] - { - "Microsoft.Bcl.AsyncInterfaces", - "NuGet.Common", - "NuGet.Configuration", - "NuGet.DependencyResolver.Core", - "NuGet.LibraryModel", - "NuGet.Packaging", - "NuGet.ProjectModel", - "NuGet.Protocol", - "NuGet.Versioning", - "System.Buffers", - "System.Collections.Immutable", - "System.Memory", - "System.Numerics.Vectors", - "System.Runtime.CompilerServices.Unsafe", - "System.Text.Encodings.Web", - "System.Text.Json", - "System.Threading.Tasks.Extensions", - }; - - var msbuildRuntimeFiles = new [] - { - "Microsoft.Common.CrossTargeting.targets", - "Microsoft.Common.CurrentVersion.targets", - "Microsoft.Common.Mono.targets", - "Microsoft.Common.overridetasks", - "Microsoft.Common.targets", - "Microsoft.Common.tasks", - "Microsoft.CSharp.CrossTargeting.targets", - "Microsoft.CSharp.CurrentVersion.targets", - "Microsoft.CSharp.Mono.targets", - "Microsoft.CSharp.targets", - "Microsoft.Data.Entity.targets", - "Microsoft.Managed.After.targets", - "Microsoft.Managed.targets", - "Microsoft.Managed.Before.targets", - "Microsoft.NET.props", - "Microsoft.NETFramework.CurrentVersion.props", - "Microsoft.NETFramework.CurrentVersion.targets", - "Microsoft.NETFramework.props", - "Microsoft.NETFramework.targets", - "Microsoft.ServiceModel.targets", - "Microsoft.VisualBasic.CrossTargeting.targets", - "Microsoft.VisualBasic.CurrentVersion.targets", - "Microsoft.VisualBasic.Mono.targets", - "Microsoft.VisualBasic.targets", - "Microsoft.WinFx.targets", - "Microsoft.WorkflowBuildExtensions.targets", - "Microsoft.Xaml.targets", - "MSBuild.dll", - "MSBuild.dll.config", - "Workflow.VisualBasic.targets", - "Workflow.targets", - }; - - if (!Platform.Current.IsWindows) - { - // Copy Mono MSBuild files before overwriting with the latest MSBuild from NuGet since Mono requires - // some extra targets and ref assemblies not present in the NuGet packages. - - var monoBasePath = Platform.Current.IsMacOS - ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" - : "/usr/lib/mono"; - var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; - var monoXBuildPath = $"{monoBasePath}/xbuild/Current"; - - Information("Copying Mono MSBuild runtime..."); - - var commonTargetsSourcePath = CombinePaths(monoXBuildPath, "Microsoft.Common.props"); - var commonTargetsTargetPath = CombinePaths(msbuildCurrentTargetFolder, "Microsoft.Common.props"); - FileHelper.Copy(commonTargetsSourcePath, commonTargetsTargetPath); - - foreach (var runtimeFileName in msbuildRuntimeFiles) - { - var runtimeSourcePath = CombinePaths(monoMSBuildPath, runtimeFileName); - var runtimeTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, runtimeFileName); - if (FileHelper.Exists(runtimeSourcePath)) - { - FileHelper.Copy(runtimeSourcePath, runtimeTargetPath); - } - } - - Information("Copying Mono MSBuild Ref Libraries..."); - - foreach (var refLibrary in msbuildRefLibraries) - { - var refLibraryFileName = refLibrary + ".dll"; - - // copy MSBuild Ref Libraries from current Mono - var refLibrarySourcePath = CombinePaths(monoMSBuildPath, refLibraryFileName); - var refLibraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, refLibraryFileName); - if (FileHelper.Exists(refLibrarySourcePath)) - { - FileHelper.Copy(refLibrarySourcePath, refLibraryTargetPath); - } - } - } - - Information("Copying MSBuild runtime..."); - - var msbuildSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Build.Runtime", "contentFiles", "any", "net472"); - DirectoryHelper.Copy(msbuildSourceFolder, msbuildCurrentBinTargetFolder, copySubDirectories: false); - - var msbuild15SourceFolder = CombinePaths(msbuildSourceFolder, "Current"); - DirectoryHelper.Copy(msbuild15SourceFolder, msbuildCurrentTargetFolder); - - Information("Copying MSBuild libraries..."); - - foreach (var library in msbuildLibraries) - { - var libraryFileName = library + ".dll"; - var librarySourcePath = CombinePaths(env.Folders.Tools, library, "lib", "net472", libraryFileName); - var libraryTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, libraryFileName); - if (FileHelper.Exists(librarySourcePath)) - { - FileHelper.Copy(librarySourcePath, libraryTargetPath); - } - } - - Information("Copying MSBuild dependencies..."); - - foreach (var dependency in msBuildDependencies) - { - var dependencyFileName = dependency + ".dll"; - var dependencySourcePath = CombinePaths(env.Folders.Tools, dependency, "lib", "netstandard2.0", dependencyFileName); - var dependencyTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, dependencyFileName); - if (FileHelper.Exists(dependencySourcePath)) - { - FileHelper.Copy(dependencySourcePath, dependencyTargetPath); - } - } - - Information("Copying MSBuild SDK dependencies..."); - - var sdkToolsSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.NET.Sdk", "tools", "net472"); - foreach (var dependency in msBuildSdkDependencies) - { - var dependencyFileName = dependency + ".dll"; - var dependencySourcePath = CombinePaths(sdkToolsSourceFolder, dependencyFileName); - var dependencyTargetPath = CombinePaths(msbuildCurrentBinTargetFolder, dependencyFileName); - if (FileHelper.Exists(dependencySourcePath)) - { - FileHelper.Copy(dependencySourcePath, dependencyTargetPath); - } - } - - // Copy MSBuild SDK Resolver and DotNetHostResolver - Information("Copying MSBuild SDK resolver..."); - var msbuildSdkResolverSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.DotNet.MSBuildSdkResolver", "lib", "net472"); - var msbuildSdkResolverTargetFolder = CombinePaths(msbuildCurrentBinTargetFolder, "SdkResolvers", "Microsoft.DotNet.MSBuildSdkResolver"); - DirectoryHelper.ForceCreate(msbuildSdkResolverTargetFolder); - FileHelper.Copy( - source: CombinePaths(msbuildSdkResolverSourceFolder, "Microsoft.DotNet.MSBuildSdkResolver.dll"), - destination: CombinePaths(msbuildSdkResolverTargetFolder, "Microsoft.DotNet.MSBuildSdkResolver.dll")); - - // Add sentinel file to enable workload resolver - FileHelper.WriteAllLines( - path: CombinePaths(msbuildSdkResolverTargetFolder, "EnableWorkloadResolver.sentinel"), - contents: new string[0] - ); - - if (Platform.Current.IsWindows) - { - CopyDotNetHostResolver(env, "win", "x86", "hostfxr.dll", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: true); - CopyDotNetHostResolver(env, "win", "x64", "hostfxr.dll", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: true); - CopyDotNetHostResolver(env, "win", "arm64", "hostfxr.dll", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: true); - } - else if (Platform.Current.IsMacOS) - { - CopyDotNetHostResolver(env, "osx", "x64", "libhostfxr.dylib", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false); - } - else if (Platform.Current.IsLinux) - { - if (Platform.Current.IsArm64) - { - CopyDotNetHostResolver(env, "linux", "arm64", "libhostfxr.so", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false); - } - else - { - CopyDotNetHostResolver(env, "linux", "x64", "libhostfxr.so", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false); - } - } - - Information("Copying NuGet SDK resolver..."); - var nugetSdkResolverSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Build.NuGetSdkResolver", "lib", "net472"); - var nugetSdkResolverTargetFolder = CombinePaths(msbuildCurrentBinTargetFolder, "SdkResolvers", "Microsoft.Build.NuGetSdkResolver"); - DirectoryHelper.ForceCreate(nugetSdkResolverTargetFolder); - FileHelper.Copy( - source: CombinePaths(nugetSdkResolverSourceFolder, "Microsoft.Build.NuGetSdkResolver.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "Microsoft.Build.NuGetSdkResolver.dll")); - FileHelper.WriteAllLines( - path: CombinePaths(nugetSdkResolverTargetFolder, "Microsoft.Build.NuGetSdkResolver.xml"), - contents: new [] { - "", - " ../../Microsoft.Build.NuGetSdkResolver.dll", - "" - } - ); - - // Copy content of NuGet.Build.Tasks - var nugetBuildTasksFolder = CombinePaths(env.Folders.Tools, "NuGet.Build.Tasks"); - var nugetBuildTasksBinariesFolder = CombinePaths(nugetBuildTasksFolder, "lib", "net472"); - var nugetBuildTasksTargetsFolder = CombinePaths(nugetBuildTasksFolder, "runtimes", "any", "native"); - - FileHelper.Copy( - source: CombinePaths(nugetBuildTasksBinariesFolder, "NuGet.Build.Tasks.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "NuGet.Build.Tasks.dll")); - - FileHelper.Copy( - source: CombinePaths(nugetBuildTasksTargetsFolder, "NuGet.targets"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "NuGet.targets")); - - // Copy dependencies of NuGet.Build.Tasks & Microsoft.Build.NuGetSdkResolver - var nugetPackages = new [] - { - "NuGet.Commands", - "NuGet.Credentials", - "NuGet.Frameworks" - }; - - foreach (var nugetPackage in nugetPackages) - { - var binaryName = nugetPackage + ".dll"; - - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, nugetPackage, "lib", "net472", binaryName), - destination: CombinePaths(msbuildCurrentBinTargetFolder, binaryName)); - } - - // Copy content of Microsoft.Net.Compilers.Toolset - Information("Copying Microsoft.Net.Compilers.Toolset..."); - var compilersSourceFolder = CombinePaths(env.Folders.Tools, "Microsoft.Net.Compilers.Toolset", "tasks", "net472"); - var compilersTargetFolder = CombinePaths(msbuildCurrentBinTargetFolder, "Roslyn"); - - DirectoryHelper.Copy(compilersSourceFolder, compilersTargetFolder); - - // Delete unnecessary files - FileHelper.Delete(CombinePaths(compilersTargetFolder, "Microsoft.CodeAnalysis.VisualBasic.dll")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "Microsoft.VisualBasic.Core.targets")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "VBCSCompiler.exe")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "VBCSCompiler.exe.config")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "vbc.exe")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "vbc.exe.config")); - FileHelper.Delete(CombinePaths(compilersTargetFolder, "vbc.rsp")); - - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "netstandard2.0", "SQLitePCLRaw.core.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "SQLitePCLRaw.core.dll"), - overwrite: true); - - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.provider.e_sqlite3", "lib", "netstandard2.0", "SQLitePCLRaw.provider.e_sqlite3.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "SQLitePCLRaw.provider.e_sqlite3.dll"), - overwrite: true); - - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "netstandard2.0", "SQLitePCLRaw.batteries_v2.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "SQLitePCLRaw.batteries_v2.dll"), - overwrite: true); - - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "Microsoft.IO.Redist", "lib", "net472", "Microsoft.IO.Redist.dll"), - destination: CombinePaths(msbuildCurrentBinTargetFolder, "Microsoft.IO.Redist.dll")); -}); - /// /// Prepare test assets. /// @@ -707,15 +329,7 @@ Task("Test") } else { - // Copy the Mono-built Microsoft.Build.* binaries to the test folder. - // This is necessary to work around a Mono bug that is exasperated by xUnit. - DirectoryHelper.Copy($"{env.Folders.MSBuild}/Current/Bin", instanceFolder); - - var runScript = CombinePaths(env.Folders.Mono, "run"); - - // By default, the run script launches OmniSharp. To launch our Mono runtime - // with xUnit rather than OmniSharp, we pass '--no-omnisharp' - Run(runScript, $"--no-omnisharp \"{xunitInstancePath}\" {arguments}", instanceFolder) + Run("mono", $"\"{xunitInstancePath}\" {arguments}", instanceFolder) .ExceptionOnError($"Test {testProject} failed for net472"); } } @@ -725,57 +339,6 @@ Task("Test") void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolder, string platformName = null) { DirectoryHelper.Copy(sourceFolder, outputFolder, copySubDirectories: false); - - var msbuildFolder = CombinePaths(outputFolder, ".msbuild"); - - // Copy MSBuild runtime and libraries - DirectoryHelper.Copy($"{env.Folders.MSBuild}", msbuildFolder); - - var msbuildBinFolder = CombinePaths(msbuildFolder, "Current", "Bin"); - EnsureDirectoryExists(msbuildBinFolder); - - if (platformName == null) - { - return; - } - - // We built the .msbuild folder initially based on the current platform. - // We are now copying Mono for a particular platform and need to ensure that - // we are including the appropriate hostfxr library. - - var platformParts = platformName.Split('-'); - var platform = platformParts[0]; - var architecture = platformParts.Length > 1 ? platformParts[1] : "x64"; - - var msbuildSdkResolverTargetFolder = CombinePaths(msbuildBinFolder, "SdkResolvers", "Microsoft.DotNet.MSBuildSdkResolver"); - var hostfxrDylibPath = CombinePaths(msbuildSdkResolverTargetFolder, "libhostfxr.dylib"); - var hostfxrSoPath = CombinePaths(msbuildSdkResolverTargetFolder, "libhostfxr.so"); - - if (FileHelper.Exists(hostfxrSoPath)) - { - // Remove the Linux hostfxr library. - FileHelper.Delete(hostfxrSoPath); - } - else if (FileHelper.Exists(hostfxrDylibPath)) - { - // Remove the MacOS hostfxr library. - FileHelper.Delete(hostfxrDylibPath); - } - - if (platform == "osx") - { - CopyDotNetHostResolver(env, "osx", "x64", "libhostfxr.dylib", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false); - } - else if (platform == "linux") - { - if (architecture == "x86") - { - // There is no x86 hostfxr use x64 instead. - architecture = "x64"; - } - - CopyDotNetHostResolver(env, "linux", architecture, "libhostfxr.so", msbuildSdkResolverTargetFolder, copyToArchSpecificFolder: false); - } } void CopyExtraDependencies(BuildEnvironment env, string outputFolder) @@ -844,25 +407,11 @@ string PublishMonoBuild(string project, BuildEnvironment env, BuildPlan plan, st var buildFolder = CombinePaths(env.Folders.Bin, configuration, project, "net472"); - CopyMonoBuild(env, buildFolder, outputFolder); + DirectoryHelper.Copy(buildFolder, outputFolder, copySubDirectories: false); CopyExtraDependencies(env, outputFolder); AddOmniSharpBindingRedirects(outputFolder); - // Copy dependencies of Mono build - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "netstandard2.0", "SQLitePCLRaw.core.dll"), - destination: CombinePaths(outputFolder, "SQLitePCLRaw.core.dll"), - overwrite: true); - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.provider.e_sqlite3", "lib", "netstandard2.0", "SQLitePCLRaw.provider.e_sqlite3.dll"), - destination: CombinePaths(outputFolder, "SQLitePCLRaw.provider.e_sqlite3.dll"), - overwrite: true); - FileHelper.Copy( - source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "netstandard2.0", "SQLitePCLRaw.batteries_v2.dll"), - destination: CombinePaths(outputFolder, "SQLitePCLRaw.batteries_v2.dll"), - overwrite: true); - Package(project, "mono", outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage); return outputFolder; @@ -874,18 +423,8 @@ string PublishMonoBuildForPlatform(string project, MonoRuntime monoRuntime, Buil var outputFolder = CombinePaths(env.Folders.ArtifactsPublish, project, monoRuntime.PlatformName); - DirectoryHelper.Copy(monoRuntime.InstallFolder, outputFolder); - - Run("chmod", $"+x '{CombinePaths(outputFolder, "bin", monoRuntime.RuntimeFile)}'"); - Run("chmod", $"+x '{CombinePaths(outputFolder, "run")}'"); - - var sourceFolder = CombinePaths(env.Folders.ArtifactsPublish, project, "mono"); - var omnisharpFolder = CombinePaths(outputFolder, "omnisharp"); - - CopyMonoBuild(env, sourceFolder, omnisharpFolder, monoRuntime.PlatformName); - CopyExtraDependencies(env, outputFolder); - AddOmniSharpBindingRedirects(omnisharpFolder); + AddOmniSharpBindingRedirects(outputFolder); Package(project, monoRuntime.PlatformName, outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage); @@ -1015,11 +554,6 @@ string PublishBuild(string project, BuildEnvironment env, BuildPlan plan, string FileHelper.Delete(filePath); } } - else - { - // Copy MSBuild to output - DirectoryHelper.Copy($"{env.Folders.MSBuild}", CombinePaths(outputFolder, ".msbuild")); - } CopyExtraDependencies(env, outputFolder); AddOmniSharpBindingRedirects(outputFolder); @@ -1171,7 +705,6 @@ Task("Install") /// Task("All") .IsDependentOn("Cleanup") - .IsDependentOn("CleanUpMonoAssets") .IsDependentOn("Build") .IsDependentOn("Test") .IsDependentOn("Publish") @@ -1188,7 +721,6 @@ Task("Default") /// Task("CI") .IsDependentOn("Cleanup") - .IsDependentOn("CleanUpMonoAssets") .IsDependentOn("Build") .IsDependentOn("Publish") .IsDependentOn("ExecuteRunScript"); diff --git a/build.json b/build.json index 6fafc58176..cd047b5b14 100644 --- a/build.json +++ b/build.json @@ -8,10 +8,6 @@ ], "RequiredMonoVersion": "6.6.0", "DownloadURL": "https://roslynomnisharp.blob.core.windows.net/ext", - "MonoRuntimeMacOS": "mono.macOS-6.12.0.122.zip", - "MonoRuntimeLinuxX86": "mono.linux-x86-6.12.0.122.zip", - "MonoRuntimeLinuxX64": "mono.linux-x86_64-6.12.0.122.zip", - "MonoRuntimeLinuxArm64": "mono.linux-arm64-6.12.0.122.zip", "HostProjects": [ "OmniSharp.Stdio.Driver", "OmniSharp.Http.Driver" diff --git a/build.ps1 b/build.ps1 index 855846c844..2ef7cd8585 100644 --- a/build.ps1 +++ b/build.ps1 @@ -31,6 +31,8 @@ Uses the nightly builds of the Roslyn script engine. Uses the Mono Compiler rather than the Roslyn script engine. .PARAMETER SkipToolPackageRestore Skips restoring of packages. +.PARAMETER UseDotNetTest +Run tests against the .NET SDK build of OmniSharp .PARAMETER ScriptArgs Remaining arguments are added here. @@ -53,6 +55,7 @@ Param( [switch]$Experimental, [switch]$Mono, [switch]$SkipToolPackageRestore, + [switch]$UseDotNetTest, [Parameter(Position=0,Mandatory=$false,ValueFromRemainingArguments=$true)] [string[]]$ScriptArgs ) @@ -227,6 +230,7 @@ if ($ShowDescription) { $cakeArguments += "--showdescription" } if ($DryRun) { $cakeArguments += "--dryrun" } if ($Experimental) { $cakeArguments += "--experimental" } if ($Mono) { $cakeArguments += "--mono" } +if ($UseDotNetTest) { $cakeArguments += "--use-dotnet-test" } $cakeArguments += $ScriptArgs # Start Cake diff --git a/mono-packaging/copy-mono.sh b/mono-packaging/copy-mono.sh deleted file mode 100755 index 553579a91b..0000000000 --- a/mono-packaging/copy-mono.sh +++ /dev/null @@ -1,301 +0,0 @@ -#!/usr/bin/env bash - -# Copies Mono assets needed to run OmniSharp. - -# Arguments: -# $1: output directory - -output_path=$1 - -if [ "$output_path" = "" ]; then - output_path=`pwd -P` - echo "No output directory specified. Using $output_path" -fi - -script_path="$(cd "$(dirname "$0")" && pwd -P)" - -target_path="" - -_create_target_path() { - _cleanup_target_path - - target_path=`mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir'` - echo "Using temporary path: $target_path" -} - -# deletes the temp directory -_cleanup_target_path() { - if [ -d "$target_path" ]; then - rm -rf "$target_path" - echo "Deleted temp directory: $target_path" - fi -} - -trap _cleanup_target_path EXIT - -readonly OS_MAC="macOS" -readonly OS_Linux_x86="linux-x86" -readonly OS_Linux_x64="linux-x86_64" -readonly OS_Linux_arm64="linux-arm64" - -os="" - -case `uname` in - "Darwin") - os=$OS_MAC - ;; - "Linux") - case `uname -m` in - "x86" | "i386" | "i686") - os=$OS_Linux_x86 - ;; - "x86_64") - os=$OS_Linux_x64 - ;; - "aarch64" | "arm64") - os=$OS_Linux_arm64 - ;; - esac - ;; - *) - echo "This operating system is not supported." - exit 1 - ;; -esac - -mono_version=`mono --version | head -n 1 | sed 's/[^0-9.]*\([0-9.]*\).*/\1/'` - -gac_assemblies=( - "Microsoft.Build.Engine/4.0.0.0__b03f5f7f11d50a3a/Microsoft.Build.Engine.dll" - "Mono.Data.Tds/4.0.0.0__0738eb9f132ed756/Mono.Data.Tds.dll" - "Mono.Posix/4.0.0.0__0738eb9f132ed756/Mono.Posix.dll" - "Mono.Security/4.0.0.0__0738eb9f132ed756/Mono.Security.dll" - "System/4.0.0.0__b77a5c561934e089/System.dll" - "System.ComponentModel.Composition/4.0.0.0__b77a5c561934e089/System.ComponentModel.Composition.dll" - "System.ComponentModel.DataAnnotations/4.0.0.0__31bf3856ad364e35/System.ComponentModel.DataAnnotations.dll" - "System.Configuration/4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll" - "System.Core/4.0.0.0__b77a5c561934e089/System.Core.dll" - "System.Data/4.0.0.0__b77a5c561934e089/System.Data.dll" - "System.EnterpriseServices/4.0.0.0__b03f5f7f11d50a3a/System.EnterpriseServices.dll" - "System.IO.Compression/4.0.0.0__b77a5c561934e089/System.IO.Compression.dll" - "System.IO.Compression.FileSystem/4.0.0.0__b77a5c561934e089/System.IO.Compression.FileSystem.dll" - "System.Net.Http/4.0.0.0__b03f5f7f11d50a3a/System.Net.Http.dll" - "System.Numerics/4.0.0.0__b77a5c561934e089/System.Numerics.dll" - "System.Numerics.Vectors/4.0.0.0__b03f5f7f11d50a3a/System.Numerics.Vectors.dll" - "System.Runtime.Serialization/4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll" - "System.Security/4.0.0.0__b03f5f7f11d50a3a/System.Security.dll" - "System.ServiceModel.Internals/0.0.0.0__b77a5c561934e089/System.ServiceModel.Internals.dll" - "System.Threading.Tasks.Dataflow/4.0.0.0__b77a5c561934e089/System.Threading.Tasks.Dataflow.dll" - "System.Transactions/4.0.0.0__b77a5c561934e089/System.Transactions.dll" - "System.Xaml/4.0.0.0__b77a5c561934e089/System.Xaml.dll" - "System.Xml/4.0.0.0__b77a5c561934e089/System.Xml.dll" - "System.Xml.Linq/4.0.0.0__b77a5c561934e089/System.Xml.Linq.dll" -) - -framework_facades=( - "netstandard.dll" - "System.AppContext.dll" - "System.Collections.dll" - "System.Collections.Concurrent.dll" - "System.ComponentModel.dll" - "System.ComponentModel.Annotations.dll" - "System.ComponentModel.EventBasedAsync.dll" - "System.ComponentModel.Primitives.dll" - "System.ComponentModel.TypeConverter.dll" - "System.Console.dll" - "System.Diagnostics.Contracts.dll" - "System.Diagnostics.Debug.dll" - "System.Diagnostics.Tools.dll" - "System.Diagnostics.Tracing.dll" - "System.Dynamic.Runtime.dll" - "System.Globalization.dll" - "System.IO.dll" - "System.IO.FileSystem.dll" - "System.IO.FileSystem.Primitives.dll" - "System.Linq.dll" - "System.Linq.Expressions.dll" - "System.Linq.Parallel.dll" - "System.ObjectModel.dll" - "System.Reflection.dll" - "System.Reflection.Extensions.dll" - "System.Reflection.Emit.ILGeneration.dll" - "System.Reflection.Emit.Lightweight.dll" - "System.Reflection.Emit.dll" - "System.Reflection.Primitives.dll" - "System.Resources.ResourceManager.dll" - "System.Runtime.dll" - "System.Runtime.Extensions.dll" - "System.Runtime.InteropServices.dll" - "System.Runtime.InteropServices.RuntimeInformation.dll" - "System.Runtime.Numerics.dll" - "System.Security.Cryptography.Encoding.dll" - "System.Security.Cryptography.Primitives.dll" - "System.Security.Cryptography.X509Certificates.dll" - "System.Text.Encoding.dll" - "System.Text.Encoding.Extensions.dll" - "System.Text.RegularExpressions.dll" - "System.Threading.dll" - "System.Threading.Tasks.dll" - "System.Threading.Tasks.Parallel.dll" - "System.Threading.Thread.dll" - "System.Xml.ReaderWriter.dll" - "System.Xml.XDocument.dll" -) - -_verify_file() { - local file_path=$1 - - if [ ! -f "$file_path" ]; then - echo "File does not exist: $file_path" - exit 1 - fi -} - -_copy_file() { - local file_path=$1 - local target_path=$2 - - _verify_file $file_path - - mkdir -p "$(dirname "$target_path")" - - cp "$file_path" "$target_path" -} - -_create_archive() { - local name=$1 - - pushd "$target_path" - zip -r "$output_path/$name" . - popd -} - -_copy_runtime_assets() { - local mono_runtime_path="" - local mono_lib_path="" - local mono_etc_path="" - local libMonoPosixHelper_name="" - local libMonoBtlsShared_name="" - local libMonoNative_name="" - local libMonoNative_target_name="" - local libMonoNative2_name="" - local libMonoNative2_target_name="" - - if [ "$os" = "$OS_MAC" ]; then - mono_base_path=/Library/Frameworks/Mono.framework/Versions/Current - - mono_runtime_path=$mono_base_path/bin/mono-sgen64 - mono_lib_path=$mono_base_path/lib - mono_etc_path=$mono_base_path/etc/mono - libMonoPosixHelper_name=libMonoPosixHelper.dylib - libMonoBtlsShared_name=libmono-btls-shared.dylib - libMonoNative_name=libmono-native-unified.0.dylib - libMonoNative_target_name=libmono-native-unified.dylib - libMonoNative2_name=libmono-native-compat.0.dylib - libMonoNative2_target_name=libmono-native-compat.dylib - else # Linux - mono_runtime_path=/usr/bin/mono-sgen - mono_lib_path=/usr/lib - mono_etc_path=/etc/mono - libMonoPosixHelper_name=libMonoPosixHelper.so - libMonoBtlsShared_name=libmono-btls-shared.so - libMonoNative_name=libmono-native.so.0.0.0 - libMonoNative_target_name=libmono-native.so - fi - - local mono_libMonoNative_path=$mono_lib_path/$libMonoNative_name - local mono_libMonoNative2_path=$mono_lib_path/$libMonoNative2_name - local mono_libMonoPosixHelper_path=$mono_lib_path/$libMonoPosixHelper_name - local mono_libMonoBtlsShared_path=$mono_lib_path/$libMonoBtlsShared_name - local mono_config_path=$mono_etc_path/config - local mono_machine_config_path=$mono_etc_path/4.5/machine.config - - _verify_file "$mono_runtime_path" - _verify_file "$mono_libMonoPosixHelper_path" - _verify_file "$mono_libMonoNative_path" - - _verify_file "$mono_libMonoBtlsShared_path" - _verify_file "$mono_config_path" - _verify_file "$mono_machine_config_path" - - if [ -d "$target_path" ]; then - rm -rf "$target_path" - fi - - target_bin_path=$target_path/bin - target_lib_path=$target_path/lib - target_etc_path=$target_path/etc - - mkdir -p "$target_bin_path" - mkdir -p "$target_lib_path" - mkdir -p "$target_etc_path" - mkdir -p "$target_etc_path/mono/4.5" - - target_runtime_path=$target_bin_path/mono - target_libMonoPosixHelper_path=$target_lib_path/$libMonoPosixHelper_name - target_libMonoNative_path=$target_lib_path/$libMonoNative_target_name - - target_libMonoBtlsShared_path=$target_lib_path/$libMonoBtlsShared_name - target_config_path=$target_etc_path/config - target_machine_config_path=$target_etc_path/mono/4.5/machine.config - - cp "$mono_runtime_path" "$target_runtime_path" - cp "$mono_libMonoPosixHelper_path" "$target_libMonoPosixHelper_path" - cp "$mono_libMonoNative_path" "$target_libMonoNative_path" - - if [ "$os" = "$OS_MAC" ]; then - _verify_file "$mono_libMonoNative2_path" - - target_libMonoNative2_path=$target_lib_path/$libMonoNative2_target_name - - cp "$mono_libMonoNative2_path" "$target_libMonoNative2_path" - fi - - cp "$mono_libMonoBtlsShared_path" "$target_libMonoBtlsShared_path" - cp "$mono_config_path" "$target_config_path" - cp "$mono_machine_config_path" "$target_machine_config_path" - - # copy run script - cp "$script_path/run" "$target_path/run" - chmod 755 "$target_path/run" -} - -_copy_framework_assets() { - local mono_gac_path="" - local mono_45_path="" - local mono_45_facades_path="" - - if [ "$os" = "$OS_MAC" ]; then - mono_base_path=/Library/Frameworks/Mono.framework/Versions/Current - - mono_gac_path=$mono_base_path/lib/mono/gac - mono_45_path=$mono_base_path/lib/mono/4.5 - mono_45_facades_path=$mono_base_path/lib/mono/4.5/Facades - else # Linux - mono_gac_path=/usr/lib/mono/gac - mono_45_path=/usr/lib/mono/4.5 - mono_45_facades_path=/usr/lib/mono/4.5/Facades - fi - - target_gac_path=$target_path/lib/mono/gac - target_45_path=$target_path/lib/mono/4.5 - target_45_facades_path=$target_45_path/Facades - - mkdir -p "$target_gac_path" - mkdir -p "$target_45_facades_path" - - _copy_file "$mono_45_path/mscorlib.dll" "$target_45_path/mscorlib.dll" - - for file in "${gac_assemblies[@]}"; do - _copy_file "$mono_gac_path/$file" "$target_gac_path/$file" - done - - for file in "${framework_facades[@]}"; do - _copy_file "$mono_45_facades_path/$file" "$target_45_facades_path/$file" - done -} - -_create_target_path -_copy_runtime_assets -_copy_framework_assets -_create_archive "mono.$os-$mono_version.zip" diff --git a/mono-packaging/run b/mono-packaging/run deleted file mode 100644 index e23ae81dea..0000000000 --- a/mono-packaging/run +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -base_dir="$(cd "$(dirname "$0")" && pwd -P)" -bin_dir=${base_dir}/bin -etc_dir=${base_dir}/etc -omnisharp_dir=${base_dir}/omnisharp - -mono_cmd=${bin_dir}/mono -omnisharp_cmd=${omnisharp_dir}/OmniSharp.exe -config_file=${etc_dir}/config - -chmod 755 "${mono_cmd}" - -no_omnisharp=false - -if [ "$1" = "--no-omnisharp" ]; then - shift - no_omnisharp=true -fi - -export MONO_CFG_DIR=${etc_dir} -export MONO_ENV_OPTIONS="--assembly-loader=strict --config \"${config_file}\"" - -if [ "$no_omnisharp" = true ]; then - "${mono_cmd}" "$@" -else - "${mono_cmd}" "${omnisharp_cmd}" "$@" -fi diff --git a/scripts/common.cake b/scripts/common.cake index cc6df20938..7815af3866 100644 --- a/scripts/common.cake +++ b/scripts/common.cake @@ -137,15 +137,12 @@ void DownloadFileAndUnzip(string url, string folder) public class Folders { public string DotNetSdk { get; } - public string Mono { get; } - public string MSBuild { get; } public string Tools { get; } public string Bin { get; } public string Source { get; } public string Tests { get; } public string TestAssets { get; } - public string MonoPackaging { get; } public string Artifacts { get; } public string ArtifactsPublish { get; } @@ -154,25 +151,15 @@ public class Folders public string DeploymentPackage { get; } public string ArtifactsScripts { get; } - public string MonoRuntimeMacOS { get; } - public string MonoRuntimeLinuxX86 { get; } - public string MonoRuntimeLinuxX64 { get; } - public string MonoRuntimeLinuxArm64 { get; } - public string MonoMSBuildRuntime { get; } - public string MonoMSBuildLib { get; } - public Folders(string workingDirectory) { this.DotNetSdk = PathHelper.Combine(workingDirectory, ".dotnet"); - this.Mono = PathHelper.Combine(workingDirectory, ".mono"); - this.MSBuild = PathHelper.Combine(workingDirectory, ".msbuild"); this.Tools = PathHelper.Combine(workingDirectory, "tools"); this.Bin = PathHelper.Combine(workingDirectory, "bin"); this.Source = PathHelper.Combine(workingDirectory, "src"); this.Tests = PathHelper.Combine(workingDirectory, "tests"); this.TestAssets = PathHelper.Combine(workingDirectory, "test-assets"); - this.MonoPackaging = PathHelper.Combine(workingDirectory, "mono-packaging"); this.Artifacts = PathHelper.Combine(workingDirectory, "artifacts"); this.ArtifactsPublish = PathHelper.Combine(this.Artifacts, "publish"); @@ -180,26 +167,17 @@ public class Folders this.ArtifactsPackage = PathHelper.Combine(this.Artifacts, "package"); this.DeploymentPackage = PathHelper.Combine(this.Artifacts, "deployment"); this.ArtifactsScripts = PathHelper.Combine(this.Artifacts, "scripts"); - - this.MonoRuntimeMacOS = PathHelper.Combine(this.Tools, "Mono.Runtime.MacOS"); - this.MonoRuntimeLinuxX86 = PathHelper.Combine(this.Tools, "Mono.Runtime.Linux-x86"); - this.MonoRuntimeLinuxX64 = PathHelper.Combine(this.Tools, "Mono.Runtime.Linux-x64"); - this.MonoRuntimeLinuxArm64 = PathHelper.Combine(this.Tools, "Mono.Runtime.Linux-arm64"); - this.MonoMSBuildRuntime = PathHelper.Combine(this.Tools, "Microsoft.Build.Runtime.Mono"); - this.MonoMSBuildLib = PathHelper.Combine(this.Tools, "Microsoft.Build.Lib.Mono"); } } public class MonoRuntime { public string PlatformName { get; } - public string InstallFolder { get; } public string RuntimeFile { get; } - public MonoRuntime(string platformName, string installFolder, string runtimeFile) + public MonoRuntime(string platformName, string runtimeFile) { this.PlatformName = platformName; - this.InstallFolder = installFolder; this.RuntimeFile = runtimeFile; } } @@ -236,10 +214,10 @@ public class BuildEnvironment this.ShellScriptFileExtension = Platform.Current.IsWindows ? "ps1" : "sh"; this.MonoRuntimes = new [] { - new MonoRuntime("osx", this.Folders.MonoRuntimeMacOS, "mono"), - new MonoRuntime("linux-x86", this.Folders.MonoRuntimeLinuxX86, "mono"), - new MonoRuntime("linux-x64", this.Folders.MonoRuntimeLinuxX64, "mono"), - new MonoRuntime("linux-arm64", this.Folders.MonoRuntimeLinuxArm64, "mono") + new MonoRuntime("osx", "mono"), + new MonoRuntime("linux-x86", "mono"), + new MonoRuntime("linux-x64", "mono"), + new MonoRuntime("linux-arm64", "mono") }; if (Platform.Current.IsMacOS) @@ -375,12 +353,6 @@ public class BuildPlan public string[] DotNetVersions { get; set; } public string RequiredMonoVersion { get; set; } public string DownloadURL { get; set; } - public string MonoRuntimeMacOS { get; set; } - public string MonoRuntimeLinuxX86 { get; set; } - public string MonoRuntimeLinuxX64 { get; set; } - public string MonoRuntimeLinuxArm64 { get; set; } - public string MonoMSBuildRuntime { get; set; } - public string MonoMSBuildLib { get; set; } public string[] HostProjects { get; set; } public string[] TestProjects { get; set; } public string[] TestAssets { get; set; } diff --git a/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs b/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs index 1b4bf00231..ae360f31ad 100644 --- a/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs +++ b/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs @@ -1,7 +1,10 @@ -namespace OmniSharp.MSBuild.Discovery +using System; + +namespace OmniSharp.MSBuild.Discovery { public enum DiscoveryType { + [Obsolete("The StandAlone type is no longer supported.")] StandAlone = 0, DeveloperConsole = 1, VisualStudioSetup = 2, diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Extensions.cs b/src/OmniSharp.Host/MSBuild/Discovery/Extensions.cs index e3bf685c94..dc967bad72 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Extensions.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Extensions.cs @@ -18,34 +18,9 @@ public static void RegisterDefaultInstance(this IMSBuildLocator msbuildLocator, if (bestInstanceFound != null) { - // Did we end up choosing the standalone MSBuild because there was an invalid Visual Studio? - // If so, provide a helpful message to the user. - if (invalidVSFound && bestInstanceFound.DiscoveryType == DiscoveryType.StandAlone) - { - logger.LogWarning( - $@"It looks like you have Visual Studio lower than VS 2019 {s_minimumMSBuildVersion} installed. - Try updating Visual Studio to the most recent release to enable better MSBuild support." - ); - } - - if (vsWithoutSdkResolver && bestInstanceFound.DiscoveryType == DiscoveryType.StandAlone) - { - logger.LogWarning( - @"It looks like you have Visual Studio 2019 installed without .NET Core SDK support which is required by OmniSharp. - Try updating Visual Studio 2019 installation with .NET Core SDK to enable better MSBuild support." - ); - } - if (bestInstanceFound.Version < minimumMSBuildVersion) { - if (bestInstanceFound.DiscoveryType == DiscoveryType.StandAlone) - { - logger.LogWarning( - $@"It looks like the included version of MSBuild is lower than {minimumMSBuildVersion} which is the minimum supported by the configured .NET Core Sdk. - Try installing MSBuild version {minimumMSBuildVersion} or higher to enable better .NET Core Sdk support." - ); - } - else if (bestInstanceFound.DiscoveryType == DiscoveryType.Mono) + if (bestInstanceFound.DiscoveryType == DiscoveryType.Mono) { logger.LogWarning( $@"It looks like you have Mono installed which contains a MSBuild lower than {minimumMSBuildVersion} which is the minimum supported by the configured .NET Core Sdk. @@ -146,9 +121,6 @@ private static int GetInstanceFeatureScore(MSBuildInstance i, Version minimumMSB else return int.MinValue; - if (i.DiscoveryType == DiscoveryType.StandAlone) - score--; - return score; } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs index 0c82600fff..9d50247c5e 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildInstanceProvider.cs @@ -62,42 +62,6 @@ bool TryGetToolsPath(string versionPath, string binPath, out string toolsPath) } } - protected static string FindLocalMSBuildDirectory() - { - // If OmniSharp is running normally, MSBuild is located in an '.msbuild' folder beneath OmniSharp.exe. - var msbuildDirectory = Path.Combine(AppContext.BaseDirectory, ".msbuild"); - - if (!Directory.Exists(msbuildDirectory)) - { - // If the 'msbuild' folder does not exists beneath "OmniSharp.exe", this is likely a development scenario, - // such as debugging or running unit tests. In that case, we try to locate the ".msbuild" folder at the - // solution level. - msbuildDirectory = FindLocalMSBuildFromSolution(); - } - - return msbuildDirectory; - } - - private static string FindLocalMSBuildFromSolution() - { - // Try to locate the .msbuild folder by search for the OmniSharp solution relative to the current folder. - var current = AppContext.BaseDirectory; - while (!File.Exists(Path.Combine(current, "OmniSharp.sln"))) - { - current = Path.GetDirectoryName(current); - if (Path.GetPathRoot(current) == current) - { - break; - } - } - - var result = Path.Combine(current, ".msbuild"); - - return Directory.Exists(result) - ? result - : null; - } - protected static Version GetMSBuildVersion(string microsoftBuildPath) { var msbuildVersionInfo = FileVersionInfo.GetVersionInfo(microsoftBuildPath); diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 2b35d2d0c1..68ed78f563 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Immutable; using System.IO; +using System.Reflection; +//using System.Runtime.Loader; using System.Text; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -13,6 +15,16 @@ namespace OmniSharp.MSBuild.Discovery { internal class MSBuildLocator : DisposableObject, IMSBuildLocator { + private const string MSBuildPublicKeyToken = "b03f5f7f11d50a3a"; + + private static readonly string[] s_msBuildAssemblies = + { + "Microsoft.Build", + "Microsoft.Build.Framework", + "Microsoft.Build.Tasks.Core", + "Microsoft.Build.Utilities.Core", + }; + private readonly ILogger _logger; private readonly ImmutableArray _providers; @@ -34,33 +46,15 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { - var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); - if (useBundledOnly) - { - var logger = loggerFactory.CreateLogger(); - logger.LogInformation("Because 'UseBundledOnly' is enabled in the configuration, OmniSharp will only use the bundled MSBuild."); - return CreateStandAlone(loggerFactory, assemblyLoader); - } - return new MSBuildLocator(loggerFactory, assemblyLoader, ImmutableArray.Create( new MicrosoftBuildLocatorInstanceProvider(loggerFactory), #if !NETCOREAPP new MonoInstanceProvider(loggerFactory), - new StandAloneInstanceProvider(loggerFactory), #endif new UserOverrideInstanceProvider(loggerFactory, msbuildConfiguration))); } - public static MSBuildLocator CreateStandAlone(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader) - => new MSBuildLocator(loggerFactory, assemblyLoader, - ImmutableArray.Create( -#if NETCOREAPP - new MicrosoftBuildLocatorInstanceProvider(loggerFactory))); -#else - new StandAloneInstanceProvider(loggerFactory))); -#endif - public void RegisterInstance(MSBuildInstance instance) { if (RegisteredInstance != null) @@ -70,17 +64,6 @@ public void RegisterInstance(MSBuildInstance instance) RegisteredInstance = instance ?? throw new ArgumentNullException(nameof(instance)); - if (instance.DiscoveryType == DiscoveryType.StandAlone) - { - // MSBuild began relying on the Microsoft.IO.Redist library which does not work - // on MacOS or Linux platforms. Disabling the 17.0 feature wave opts us in to the - // earlier behavior of using System.IO. - - // This issue only affects the MSBuild tools shipped with O# as Mono does not ship - // with a version of MSBuild that includes this change. - Environment.SetEnvironmentVariable("MSBUILDDISABLEFEATURESFROMVERSION", "17.0"); - } - if (instance.SetMSBuildExePathVariable) { var msbuildExePath = Path.Combine(instance.MSBuildPath, "MSBuild.exe"); @@ -117,12 +100,20 @@ public void RegisterInstance(MSBuildInstance instance) _logger.LogInformation(builder.ToString()); - if (!MicrosoftBuildLocator.CanRegister) + if (MicrosoftBuildLocator.CanRegister) { - return; + MicrosoftBuildLocator.RegisterMSBuildPath(instance.MSBuildPath); } - MicrosoftBuildLocator.RegisterMSBuildPath(instance.MSBuildPath); + foreach (var msBuildAssemblyName in s_msBuildAssemblies) + { + var assembly = Assembly.Load($"{msBuildAssemblyName}, Version=15.1.0.0, Culture=neutral, PublicKeyToken={MSBuildPublicKeyToken}"); + if (assembly is null) + { + throw new Exception($"Unable to load {msBuildAssemblyName}'"); + } + _logger.LogInformation($"Loaded {msBuildAssemblyName} from '{assembly.Location}'"); + } } public ImmutableArray GetInstances() diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs index 63a3352bc6..7d67a30b1d 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MonoInstanceProvider.cs @@ -100,14 +100,6 @@ public override ImmutableArray GetInstances() var propertyOverrides = ImmutableDictionary.CreateBuilder(StringComparer.OrdinalIgnoreCase); - var localMSBuildPath = FindLocalMSBuildDirectory(); - if (localMSBuildPath != null) - { - var localRoslynPath = Path.Combine(localMSBuildPath, "Current", "Bin", "Roslyn"); - propertyOverrides.Add("CscToolPath", localRoslynPath); - propertyOverrides.Add("CscToolExe", "csc.exe"); - } - var version = GetMSBuildVersion(microsoftBuildPath); return ImmutableArray.Create( diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs deleted file mode 100644 index a57f9d166e..0000000000 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/StandAloneInstanceProvider.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Immutable; -using System.Diagnostics; -using System.IO; -using Microsoft.Extensions.Logging; -using OmniSharp.Utilities; - -namespace OmniSharp.MSBuild.Discovery.Providers -{ - internal class StandAloneInstanceProvider : MSBuildInstanceProvider - { - public StandAloneInstanceProvider(ILoggerFactory loggerFactory) - : base(loggerFactory) - { - } - - public override ImmutableArray GetInstances() - { - var path = FindLocalMSBuildDirectory(); - if (path == null) - { - return NoInstances; - } - - var extensionsPath = path; - var toolsPath = Path.Combine(extensionsPath, "Current", "Bin"); - var roslynPath = Path.Combine(toolsPath, "Roslyn"); - - var version = GetMSBuildVersion(Path.Combine(toolsPath, "Microsoft.Build.dll")); - - var propertyOverrides = ImmutableDictionary.CreateBuilder(StringComparer.OrdinalIgnoreCase); - - if (PlatformHelper.IsMono) - { - // This disables a hack in the "GetReferenceAssemblyPaths" task which attempts - // guarantee that .NET Framework SP1 is installed when the target framework is - // .NET Framework, but the version is less than 4.0. The hack attempts to locate - // a particular assembly in the GAC as a "guarantee". However, we don't include that - // in our Mono package. So, we'll just bypass the check. - propertyOverrides.Add("BypassFrameworkInstallChecks", "true"); - } - - propertyOverrides.Add("MSBuildToolsPath", toolsPath); - propertyOverrides.Add("MSBuildExtensionsPath", extensionsPath); - propertyOverrides.Add("CscToolPath", roslynPath); - propertyOverrides.Add("CscToolExe", "csc.exe"); - - return ImmutableArray.Create( - new MSBuildInstance( - nameof(DiscoveryType.StandAlone), - toolsPath, - version, - DiscoveryType.StandAlone, - propertyOverrides.ToImmutable(), - setMSBuildExePathVariable: true)); - } - } -} diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs index a10a6194ba..c7b3deedcf 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs @@ -14,7 +14,7 @@ internal class UserOverrideInstanceProvider : MSBuildInstanceProvider public UserOverrideInstanceProvider(ILoggerFactory loggerFactory, IConfiguration configuration) : base(loggerFactory) { - _options = configuration.GetSection("msbuildoverride").Get(); + _options = configuration?.GetSection("msbuildoverride").Get(); } public override ImmutableArray GetInstances() diff --git a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs index 96ce829924..8f750b4cb1 100644 --- a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs +++ b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs @@ -3,6 +3,7 @@ using System.Composition.Hosting.Core; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using OmniSharp.MSBuild.Discovery; using OmniSharp.Roslyn.Utilities; @@ -18,16 +19,19 @@ public abstract class AbstractMSBuildTestFixture : AbstractTestFixture, IDisposa private readonly IMSBuildLocator _msbuildLocator; private readonly IAnalyzerAssemblyLoader _analyzerAssemblyLoader; - public AbstractMSBuildTestFixture(ITestOutputHelper output) - : base(output) + public AbstractMSBuildTestFixture(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { _assemblyLoader = new AssemblyLoader(this.LoggerFactory); _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; - _msbuildLocator = MSBuildLocator.CreateStandAlone(this.LoggerFactory, _assemblyLoader); + _msbuildLocator = this.SharedOmniSharpTestHost.ServiceProvider.GetRequiredService(); + //if (_msbuildLocator.RegisteredInstance is null) + //{ // Some tests require MSBuild to be discovered early // to ensure that the Microsoft.Build.* assemblies can be located - _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null); + // _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null); + //} } public void Dispose() diff --git a/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs b/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs index 7a8222545c..507931979f 100644 --- a/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs @@ -17,8 +17,8 @@ namespace OmniSharp.MSBuild.Tests { public class LoadProjectsOnDemandTests : AbstractMSBuildTestFixture { - public LoadProjectsOnDemandTests(ITestOutputHelper output) - : base(output) + public LoadProjectsOnDemandTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs index a590a51ac8..2e3cfd4f50 100644 --- a/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs @@ -1,6 +1,7 @@ using Microsoft.Build.Framework; using OmniSharp.MSBuild.Logging; using OmniSharp.Utilities; +using TestUtility; using Xunit; using Xunit.Abstractions; @@ -8,7 +9,8 @@ namespace OmniSharp.MSBuild.Tests { public class MSBuildDiagnosticTests : AbstractMSBuildTestFixture { - public MSBuildDiagnosticTests(ITestOutputHelper output) : base(output) + public MSBuildDiagnosticTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/MSBuildSelectionTests.cs b/tests/OmniSharp.MSBuild.Tests/MSBuildSelectionTests.cs index 6a76e4eea1..871ccdfb89 100644 --- a/tests/OmniSharp.MSBuild.Tests/MSBuildSelectionTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/MSBuildSelectionTests.cs @@ -1,9 +1,5 @@ using System; -using System.Collections.Generic; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; using OmniSharp.MSBuild.Discovery; -using OmniSharp.Services; using TestUtility; using Xunit; using Xunit.Abstractions; @@ -30,7 +26,6 @@ public void RegisterDefaultInstanceFindsTheBestInstanceAvailable() Version.Parse("16.3.2.3"), DiscoveryType.VisualStudioSetup ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance() }; var msbuildLocator = new MSFakeLocator(msBuildInstances); @@ -66,7 +61,6 @@ public void RegisterDefaultInstanceFindsTheBestInstanceAvailableEvenWithOtherVal Version.Parse("16.3.2.1"), DiscoveryType.VisualStudioSetup ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance() }; var msbuildLocator = new MSFakeLocator(msBuildInstances); @@ -106,7 +100,6 @@ public void RegisterDefaultInstanceFindsTheNewestInstanceAvailableEvenWithOtherV Version.Parse("16.6.1.0"), DiscoveryType.VisualStudioSetup ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance() }; var msbuildLocator = new MSFakeLocator(msBuildInstances); @@ -145,7 +138,6 @@ public void RegisterDefaultInstanceFindsUserOverrideAvailableEvenWithOtherValidI Version.Parse("16.1.2.3"), DiscoveryType.VisualStudioSetup ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance(), // user override new MSBuildInstance( @@ -166,123 +158,12 @@ public void RegisterDefaultInstanceFindsUserOverrideAvailableEvenWithOtherValidI msbuildLocator.RegisterDefaultInstance(logger, dotNetInfo: null); Assert.NotNull(msbuildLocator.RegisteredInstance); - Assert.Same(msBuildInstances[4], msbuildLocator.RegisteredInstance); + Assert.Same(msBuildInstances[3], msbuildLocator.RegisteredInstance); // clean up msbuildLocator.DeleteFakeInstancesFolders(); } - [Fact] - public void RegisterDefaultInstancePrefersSupportedVSLowerVersionInstanceOverStandAlone() - { - var msBuildInstances = new[] - { - new MSBuildInstance( - "Test Instance", - TestIO.GetRandomTempFolderPath(), - Version.Parse("16.3.2.3"), - DiscoveryType.VisualStudioSetup - ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance() - }; - - var msbuildLocator = new MSFakeLocator(msBuildInstances); - var logger = LoggerFactory.CreateLogger(nameof(RegisterDefaultInstancePrefersSupportedVSLowerVersionInstanceOverStandAlone)); - - // test - msbuildLocator.RegisterDefaultInstance(logger, dotNetInfo: null); - - Assert.NotNull(msbuildLocator.RegisteredInstance); - Assert.Same(msBuildInstances[0], msbuildLocator.RegisteredInstance); - - // clean up - msbuildLocator.DeleteFakeInstancesFolders(); - } - - [Theory] - [InlineData("16.2.2.3")] // lower than standalone - [InlineData("16.6.2.3")] // higher than standalone - public void RegisterDefaultInstancePrefersStandAloneOverSupportedVSInstanceWithoutDotnetCore(string vsVersion) - { - var msBuildInstances = new[] - { - new MSBuildInstance( - "Test Instance", - TestIO.GetRandomTempFolderPath(), - Version.Parse(vsVersion), - DiscoveryType.VisualStudioSetup - ), - GetStandAloneMSBuildInstance() - }; - - var msbuildLocator = new MSFakeLocator(msBuildInstances); - var logger = LoggerFactory.CreateLogger(nameof(RegisterDefaultInstancePrefersStandAloneOverSupportedVSInstanceWithoutDotnetCore)); - - // test - msbuildLocator.RegisterDefaultInstance(logger, dotNetInfo: null); - - Assert.NotNull(msbuildLocator.RegisteredInstance); - Assert.Same(msBuildInstances[1], msbuildLocator.RegisteredInstance); - - // clean up - msbuildLocator.DeleteFakeInstancesFolders(); - } - - [Theory] - [InlineData("15.1.2.3")] - [InlineData("15.9.2.3")] - [InlineData("16.1.2.3")] - [InlineData("16.2.2.3")] - public void StandAloneIsPreferredOverUnsupportedVS(string vsVersion) - { - var msBuildInstances = new[] - { - new MSBuildInstance( - "Test Instance", - TestIO.GetRandomTempFolderPath(), - Version.Parse(vsVersion), - DiscoveryType.VisualStudioSetup - ).AddDotNetCoreToFakeInstance(), - GetStandAloneMSBuildInstance() - }; - - var msbuildLocator = new MSFakeLocator(msBuildInstances); - var logger = LoggerFactory.CreateLogger(nameof(StandAloneIsPreferredOverUnsupportedVS)); - - // test - msbuildLocator.RegisterDefaultInstance(logger, dotNetInfo: null); - - Assert.NotNull(msbuildLocator.RegisteredInstance); - Assert.Same(msBuildInstances[1], msbuildLocator.RegisteredInstance); - - // clean up - msbuildLocator.DeleteFakeInstancesFolders(); - } - - [ConditionalFact(typeof(DesktopRuntimeOnly))] - public void CreateDefault_UseBundledOnly_True_LocatesOnlyStandAloneInstance() - { - var configBuilder = new Microsoft.Extensions.Configuration.ConfigurationBuilder().AddInMemoryCollection(new Dictionary() - { - ["useBundledOnly"] = "true" - }); - var loggerFactory = new LoggerFactory(); - var locator = MSBuildLocator.CreateDefault(loggerFactory, new AssemblyLoader(loggerFactory), configBuilder.Build()); - var instances = locator.GetInstances(); - Assert.Single(instances); - Assert.Equal(DiscoveryType.StandAlone, instances[0].DiscoveryType); - } - - private static MSBuildInstance GetStandAloneMSBuildInstance() - { - return new MSBuildInstance( - "Stand Alone :(", - TestIO.GetRandomTempFolderPath(), - Version.Parse("16.4.0.0"), - DiscoveryType.StandAlone - ).AddDotNetCoreToFakeInstance(); - } - private static MSBuildInstance GetInvalidMsBuildInstance() { return new MSBuildInstance( diff --git a/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs b/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs index f7c01ec35d..739da50cb0 100644 --- a/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs @@ -12,8 +12,8 @@ namespace OmniSharp.MSBuild.Tests { public class NotificationTests : AbstractMSBuildTestFixture { - public NotificationTests(ITestOutputHelper output) - : base(output) + public NotificationTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 3bd5902ae1..74e86f52bf 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -17,7 +17,8 @@ public partial class ProjectLoadListenerTests : AbstractMSBuildTestFixture private readonly VsTfmAndFileExtHashingAlgorithm _tfmAndFileHashingAlgorithm; private readonly VsReferenceHashingAlgorithm _referenceHashingAlgorithm; - public ProjectLoadListenerTests(ITestOutputHelper output) : base(output) + public ProjectLoadListenerTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { _tfmAndFileHashingAlgorithm = new VsTfmAndFileExtHashingAlgorithm(); _referenceHashingAlgorithm = new VsReferenceHashingAlgorithm(); diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs index 03bab1be78..0a01c28839 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs @@ -9,8 +9,8 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithAdditionalFilesTests : AbstractMSBuildTestFixture { - public ProjectWithAdditionalFilesTests(ITestOutputHelper output) - : base(output) + public ProjectWithAdditionalFilesTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs index bed546131e..6eb100ab47 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs @@ -20,8 +20,8 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithAnalyzersTests : AbstractMSBuildTestFixture { - public ProjectWithAnalyzersTests(ITestOutputHelper output) - : base(output) + public ProjectWithAnalyzersTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs index 96665d4537..f40ef76dd1 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs @@ -11,7 +11,8 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithComplexAnalyzersTests : AbstractMSBuildTestFixture { - public ProjectWithComplexAnalyzersTests(ITestOutputHelper output) : base(output) + public ProjectWithComplexAnalyzersTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs index d4303e386a..880ae9f1ce 100644 --- a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs @@ -14,8 +14,8 @@ namespace OmniSharp.MSBuild.Tests { public class WorkspaceInformationTests : AbstractMSBuildTestFixture { - public WorkspaceInformationTests(ITestOutputHelper output) - : base(output) + public WorkspaceInformationTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) + : base(output, sharedOmniSharpHostFixture) { } diff --git a/tests/TestUtility/TestServiceProvider.cs b/tests/TestUtility/TestServiceProvider.cs index 1cd6771ce3..63f00ed1e3 100644 --- a/tests/TestUtility/TestServiceProvider.cs +++ b/tests/TestUtility/TestServiceProvider.cs @@ -85,7 +85,7 @@ public static IServiceProvider Create( var assemblyLoader = CreateAssemblyLoader(loggerFactory); var dotNetCliService = CreateDotNetCliService(dotNetCliVersion, loggerFactory, environment, eventEmitter); var configuration = CreateConfiguration(configurationData); - var msbuildLocator = CreateMSBuildLocator(loggerFactory, assemblyLoader); + var msbuildLocator = CreateMSBuildLocator(loggerFactory, assemblyLoader, configurationData); var sharedTextWriter = CreateSharedTextWriter(testOutput); var analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; @@ -166,8 +166,9 @@ private static IDotNetCliService CreateDotNetCliService( } private static IMSBuildLocator CreateMSBuildLocator(ILoggerFactory loggerFactory, - IAssemblyLoader assemblyLoader) - => MSBuildLocator.CreateStandAlone(loggerFactory, assemblyLoader); + IAssemblyLoader assemblyLoader, + IConfiguration configurationData) + => MSBuildLocator.CreateDefault(loggerFactory, assemblyLoader, configurationData); private static ISharedTextWriter CreateSharedTextWriter(ITestOutputHelper testOutput) => new TestSharedTextWriter(testOutput); diff --git a/tools/packages.config b/tools/packages.config index 46b7b28f87..f7d3f41d15 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -3,78 +3,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From bfa5b552fa1316efdeabf0a1a677b7cc418c3045 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 16:49:16 -0700 Subject: [PATCH 02/24] Fix publishing errors. --- build.cake | 26 ++++++++++++++++++++------ tools/packages.config | 5 +++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/build.cake b/build.cake index f836fe4ee1..dd2979b95c 100644 --- a/build.cake +++ b/build.cake @@ -336,11 +336,6 @@ Task("Test") } }); -void CopyMonoBuild(BuildEnvironment env, string sourceFolder, string outputFolder, string platformName = null) -{ - DirectoryHelper.Copy(sourceFolder, outputFolder, copySubDirectories: false); -} - void CopyExtraDependencies(BuildEnvironment env, string outputFolder) { // copy license @@ -412,6 +407,20 @@ string PublishMonoBuild(string project, BuildEnvironment env, BuildPlan plan, st CopyExtraDependencies(env, outputFolder); AddOmniSharpBindingRedirects(outputFolder); + // Copy dependencies of Mono build + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "netstandard2.0", "SQLitePCLRaw.core.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.core.dll"), + overwrite: true); + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.provider.e_sqlite3", "lib", "netstandard2.0", "SQLitePCLRaw.provider.e_sqlite3.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.provider.e_sqlite3.dll"), + overwrite: true); + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "netstandard2.0", "SQLitePCLRaw.batteries_v2.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.batteries_v2.dll"), + overwrite: true); + Package(project, "mono", outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage); return outputFolder; @@ -423,8 +432,13 @@ string PublishMonoBuildForPlatform(string project, MonoRuntime monoRuntime, Buil var outputFolder = CombinePaths(env.Folders.ArtifactsPublish, project, monoRuntime.PlatformName); + var sourceFolder = CombinePaths(env.Folders.ArtifactsPublish, project, "mono"); + var omnisharpFolder = CombinePaths(outputFolder, "omnisharp"); + + DirectoryHelper.Copy(sourceFolder, omnisharpFolder, copySubDirectories: false); + CopyExtraDependencies(env, outputFolder); - AddOmniSharpBindingRedirects(outputFolder); + AddOmniSharpBindingRedirects(omnisharpFolder); Package(project, monoRuntime.PlatformName, outputFolder, env.Folders.ArtifactsPackage, env.Folders.DeploymentPackage); diff --git a/tools/packages.config b/tools/packages.config index f7d3f41d15..5d2af6ad97 100644 --- a/tools/packages.config +++ b/tools/packages.config @@ -3,4 +3,9 @@ + + + + + From 468975824727b7688e660e170417c826342410ec Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 17:28:48 -0700 Subject: [PATCH 03/24] Update vm images used in CI --- .github/workflows/tests.yml | 74 ++++++++++++++++++++++++++++++++----- azure-pipelines.yml | 6 +-- 2 files changed, 67 insertions(+), 13 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b0e77add3b..3db16ef715 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,9 +25,11 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-18.04, windows-2019, macos-10.15] + # TODO: mono 6.12 is installed on ubuntu and macos images, but ships with MSBuild 16.6. + # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md + os: [ubuntu-20.04, windows-2022, macos-11] testProjects: - - OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests + - OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests - OmniSharp.DotNetTest.Tests name: 'Test' steps: @@ -37,14 +39,6 @@ jobs: clean: 'false' fetch-depth: '0' - # TODO: Need to figure out the correct way to install mono on linux / mac - # Currently the latest image has mono 6.12 - # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md - # - name: 🔨 Use Mono ${{ env.MonoVersion }} SDK - # uses: maxim-lobanov/setup-xamarin@v1 - # with: - # mono-version: ${{ env.MonoVersion }} - - name: Setup NuGet.exe uses: nuget/setup-nuget@v1 with: @@ -108,3 +102,63 @@ jobs: with: name: 'logs - ${{ github.workflow }} ${{ matrix.os }}' path: '${{ env.Artifacts }}/logs/' + + test-msbuild: + # Limit the .NET Framework OmniSharp.MSBuild.Tests to the Windows Platform, + # since we have access to a MSBuild newer than version 16.6. + runs-on: windows-2022 + strategy: + fail-fast: false + matrix: + testProjects: + - OmniSharp.MSBuild.Tests + name: 'Test' + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + clean: 'false' + fetch-depth: '0' + + - name: Setup NuGet.exe + uses: nuget/setup-nuget@v1 + with: + nuget-version: ${{ env.NuGetVersion }} + + - name: 🔨 Use .NET Core ${{ env.DotNetVersion2 }} SDK + uses: actions/setup-dotnet@v1.7.2 + with: + dotnet-version: ${{ env.DotNetVersion2 }} + + - name: 🔨 Use .NET Core ${{ env.DotNetVersion }} SDK + uses: actions/setup-dotnet@v1.7.2 + with: + dotnet-version: ${{ env.DotNetVersion }} + + - name: 🎁 dotnet tool restore + run: | + dotnet tool restore + + - name: 🎁 nuget install + run: | + nuget install tools/packages.config -ExcludeVersion -OutputDirectory tools + + - name: 🍰 Run Cake + uses: nick-invision/retry@v2 + with: + shell: powershell + timeout_minutes: 40 + max_attempts: 3 + retry_on: error + command: | + .\build.ps1 -configuration Release -verbosity Verbose -target Test --test-project="$ENV:TEST_PROJECT" + env: + TEST_PROJECT: ${{ matrix.testProjects }} + + - name: ⬆ Publish Logs + uses: actions/upload-artifact@v2 + continue-on-error: true + if: ${{ always() }} + with: + name: 'logs - ${{ github.workflow }} ${{ matrix.os }}' + path: '${{ env.Artifacts }}/logs/' diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 6119b8b5b2..b7d4be996d 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -53,7 +53,7 @@ jobs: - job: macOS pool: - vmImage: "macOS-10.15" + vmImage: "macOS-11" dependsOn: GitVersion steps: - template: ./.pipelines/init.yml @@ -74,7 +74,7 @@ jobs: - job: Linux pool: - vmImage: "ubuntu-18.04" + vmImage: "ubuntu-20.04" dependsOn: GitVersion steps: - template: ./.pipelines/init.yml @@ -94,7 +94,7 @@ jobs: - job: Windows pool: - vmImage: "windows-2019" + vmImage: "windows-2022" dependsOn: GitVersion steps: - template: ./.pipelines/init.yml From 6e017f877edf165a0b3f6b88911344d74b544c23 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 17:39:42 -0700 Subject: [PATCH 04/24] Remove reference to `omnisharp.useGlobalMono` from messages --- src/OmniSharp.MSBuild/Logging/ErrorMessages.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs index 1358a2debf..76a3a26f67 100644 --- a/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs +++ b/src/OmniSharp.MSBuild/Logging/ErrorMessages.cs @@ -2,14 +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 are not installed (e.g. .NET Framework). The most common solution is to make sure Mono is fully updated on your machine (https://mono-project.com/download/) and that you are running the .NET Framework build of OmniSharp (e.g. 'omnisharp.useModernNet': false 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 the net6.0 build of OmniSharp on the .NET SDK. (e.g. 'omnisharp.useModernNet': true in C# Extension for VS Code)."; - 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 ReferenceAssembliesNotFoundNet60Unix = "This project targets .NET 6.0 but the currently used MSBuild is not compatible with it - MSBuild 17.0+ is required. To solve this, run the net6.0 build of OmniSharp on the .NET SDK. (e.g. 'omnisharp.useModernNet': true in C# Extension for VS Code)."; - 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."; - 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 } }."; + internal const string ReferenceAssembliesNotFoundNet60Windows = "This project targets .NET 6.0 but the currently used MSBuild is not compatible with it - MSBuild 17.0+ is required. To solve this, if you have Visual Studio 2022 installed on your machine, make sure it is updated to version 17.0."; } } From 1be42f3c93ad5b49ba5677677918f74044da7016 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 17:40:11 -0700 Subject: [PATCH 05/24] Remove `UseBundledOnly` MSBuild Option. --- src/OmniSharp.MSBuild/Options/MSBuildOptions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OmniSharp.MSBuild/Options/MSBuildOptions.cs b/src/OmniSharp.MSBuild/Options/MSBuildOptions.cs index d0cdbe7f50..3fb0491ae0 100644 --- a/src/OmniSharp.MSBuild/Options/MSBuildOptions.cs +++ b/src/OmniSharp.MSBuild/Options/MSBuildOptions.cs @@ -2,7 +2,6 @@ namespace OmniSharp.Options { public class MSBuildOptions { - public bool UseBundledOnly { get; set; } = false; public string ToolsVersion { get; set; } public string VisualStudioVersion { get; set; } public string Configuration { get; set; } From b1fe1e6999138c51b6812ccbd8f8e4a5e7322667 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 17:56:36 -0700 Subject: [PATCH 06/24] Adjust project capabilities test --- tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 74e86f52bf..7f49ff746a 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -2,6 +2,7 @@ using Microsoft.Build.Execution; using Microsoft.CodeAnalysis; using OmniSharp.Services; +using Roslyn.Test.Utilities; using System.Collections.Immutable; using System.IO; using System.Linq; @@ -186,7 +187,7 @@ public async Task The_correct_project_capablities_is_emitted() using var testProject = await TestAssets.Instance.GetTestProjectAsync("NetCore31Project"); using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); Assert.Single(emitter.ReceivedMessages); - Assert.Equal("GenerateDocumentationFile CSharp Managed ReferencesFolder LanguageService RelativePathDerivedDefaultNamespace AssemblyReferences COMReferences ProjectReferences SharedProjectReferences OutputGroups AllTargetOutputGroups VisualStudioWellKnownOutputGroups SingleFileGenerators DeclaredSourceItems UserSourceItems BuildWindowsDesktopTarget CrossPlatformExecutable Pack", string.Join(" ", emitter.ReceivedMessages[0].ProjectCapabilities)); + AssertEx.SetEqual("GenerateDocumentationFile CSharp Managed ReferencesFolder LanguageService RelativePathDerivedDefaultNamespace AssemblyReferences COMReferences ProjectReferences SharedProjectReferences OutputGroups AllTargetOutputGroups VisualStudioWellKnownOutputGroups SingleFileGenerators DeclaredSourceItems UserSourceItems BuildWindowsDesktopTarget CrossPlatformExecutable Pack".Split(" "), emitter.ReceivedMessages[0].ProjectCapabilities); } [Fact] From 556b29fb2569530706c99ca2a505a3dc4fec68a6 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 18:05:10 -0700 Subject: [PATCH 07/24] Include SQLitePCLRaw in .NET Framework test output --- .../OmniSharp.DotNetTest.Tests.csproj | 7 +++++++ tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj | 10 ++++++++-- .../OmniSharp.MSBuild.Tests.csproj | 8 +++++++- .../OmniSharp.Roslyn.CSharp.Tests.csproj | 8 +++++++- .../OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj | 8 +++++++- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj index b8faeb721c..08307558b0 100644 --- a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj +++ b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj @@ -21,6 +21,13 @@ + + + diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj index 311a5f99d3..5d20beb4d2 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj +++ b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj @@ -17,12 +17,18 @@ - + - + + + diff --git a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj index 9200ec8d1d..8084815226 100644 --- a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj +++ b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj @@ -23,7 +23,13 @@ - + + + diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj b/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj index a134f22a5a..cabd3cae36 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj @@ -21,7 +21,13 @@ - + + + diff --git a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj index df100568dc..52677fe437 100644 --- a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj +++ b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj @@ -19,7 +19,13 @@ - + + + From bd23d5a630edf966212ea318b4f3abab4216a3c5 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 17 Mar 2022 19:56:42 -0700 Subject: [PATCH 08/24] Fix test --- .../ProjectLoadListenerTests.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 7f49ff746a..1d8d932f9a 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -2,7 +2,7 @@ using Microsoft.Build.Execution; using Microsoft.CodeAnalysis; using OmniSharp.Services; -using Roslyn.Test.Utilities; +using System.Collections.Generic; using System.Collections.Immutable; using System.IO; using System.Linq; @@ -183,11 +183,31 @@ public async Task The_correct_project_capablities_is_emitted() { // Arrange var emitter = new ProjectLoadTestEventEmitter(); + var expectedCapabilities = new HashSet() + { + "GenerateDocumentationFile", + "CSharp", + "Managed", + "RelativePathDerivedDefaultNamespace", + "AssemblyReferences", + "COMReferences", + "ProjectReferences", + "SharedProjectReferences", + "OutputGroups", + "AllTargetOutputGroups", + "VisualStudioWellKnownOutputGroups", + "SingleFileGenerators", + "DeclaredSourceItems", + "UserSourceItems", + "CrossPlatformExecutable", + "Pack", + }; using var testProject = await TestAssets.Instance.GetTestProjectAsync("NetCore31Project"); using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); Assert.Single(emitter.ReceivedMessages); - AssertEx.SetEqual("GenerateDocumentationFile CSharp Managed ReferencesFolder LanguageService RelativePathDerivedDefaultNamespace AssemblyReferences COMReferences ProjectReferences SharedProjectReferences OutputGroups AllTargetOutputGroups VisualStudioWellKnownOutputGroups SingleFileGenerators DeclaredSourceItems UserSourceItems BuildWindowsDesktopTarget CrossPlatformExecutable Pack".Split(" "), emitter.ReceivedMessages[0].ProjectCapabilities); + + Assert.ProperSuperset(expectedCapabilities, emitter.ReceivedMessages[0].ProjectCapabilities.ToHashSet()); } [Fact] From c0cdf55ce2e10ae163378d70f56eeeb6ac41bafd Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sat, 19 Mar 2022 23:42:42 -0700 Subject: [PATCH 09/24] Simplify getting MSBuildLocator in tests --- .../MSBuild/Discovery/MSBuildLocator.cs | 25 +++---------------- .../OmniSharp.DotNetTest.Tests.csproj | 4 +-- .../OmniSharp.Lsp.Tests.csproj | 4 +-- .../AbstractMSBuildTestFixture.cs | 11 +++----- .../LoadProjectsOnDemandTests.cs | 5 ++-- .../MSBuildDiagnosticTests.cs | 4 +-- .../NotificationTests.cs | 4 +-- .../OmniSharp.MSBuild.Tests.csproj | 4 +-- .../ProjectLoadListenerTests.cs | 3 +-- .../ProjectWithAdditionalFilesTests.cs | 4 +-- .../ProjectWithAnalyzersTests.cs | 4 +-- .../ProjectWithComplexAnalyzersTests.cs | 3 +-- .../WorkspaceInformationTests.cs | 4 +-- .../OmniSharp.Roslyn.CSharp.Tests.csproj | 4 +-- .../OmniSharp.Stdio.Tests.csproj | 4 +-- tests/TestUtility/TestServiceProvider.cs | 2 +- 16 files changed, 31 insertions(+), 58 deletions(-) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 68ed78f563..8984745fa7 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -2,7 +2,6 @@ using System.Collections.Immutable; using System.IO; using System.Reflection; -//using System.Runtime.Loader; using System.Text; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -15,16 +14,6 @@ namespace OmniSharp.MSBuild.Discovery { internal class MSBuildLocator : DisposableObject, IMSBuildLocator { - private const string MSBuildPublicKeyToken = "b03f5f7f11d50a3a"; - - private static readonly string[] s_msBuildAssemblies = - { - "Microsoft.Build", - "Microsoft.Build.Framework", - "Microsoft.Build.Tasks.Core", - "Microsoft.Build.Utilities.Core", - }; - private readonly ILogger _logger; private readonly ImmutableArray _providers; @@ -100,20 +89,12 @@ public void RegisterInstance(MSBuildInstance instance) _logger.LogInformation(builder.ToString()); - if (MicrosoftBuildLocator.CanRegister) + if (!MicrosoftBuildLocator.CanRegister) { - MicrosoftBuildLocator.RegisterMSBuildPath(instance.MSBuildPath); + return; } - foreach (var msBuildAssemblyName in s_msBuildAssemblies) - { - var assembly = Assembly.Load($"{msBuildAssemblyName}, Version=15.1.0.0, Culture=neutral, PublicKeyToken={MSBuildPublicKeyToken}"); - if (assembly is null) - { - throw new Exception($"Unable to load {msBuildAssemblyName}'"); - } - _logger.LogInformation($"Loaded {msBuildAssemblyName} from '{assembly.Location}'"); - } + MicrosoftBuildLocator.RegisterMSBuildPath(instance.MSBuildPath); } public ImmutableArray GetInstances() diff --git a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj index 08307558b0..c4f0377231 100644 --- a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj +++ b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj @@ -23,8 +23,8 @@ diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj index 5d20beb4d2..705ec5db8b 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj +++ b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj @@ -24,8 +24,8 @@ diff --git a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs index 8f750b4cb1..ff90378ec8 100644 --- a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs +++ b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs @@ -19,19 +19,16 @@ public abstract class AbstractMSBuildTestFixture : AbstractTestFixture, IDisposa private readonly IMSBuildLocator _msbuildLocator; private readonly IAnalyzerAssemblyLoader _analyzerAssemblyLoader; - public AbstractMSBuildTestFixture(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public AbstractMSBuildTestFixture(ITestOutputHelper output) + : base(output) { _assemblyLoader = new AssemblyLoader(this.LoggerFactory); _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; - _msbuildLocator = this.SharedOmniSharpTestHost.ServiceProvider.GetRequiredService(); + _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, msbuildConfiguration: null); - //if (_msbuildLocator.RegisteredInstance is null) - //{ // Some tests require MSBuild to be discovered early // to ensure that the Microsoft.Build.* assemblies can be located - // _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null); - //} + _msbuildLocator.RegisterDefaultInstance(this.LoggerFactory.CreateLogger("MSBuildTests"), dotNetInfo: null); } public void Dispose() diff --git a/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs b/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs index 507931979f..dc7f518e5f 100644 --- a/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/LoadProjectsOnDemandTests.cs @@ -4,7 +4,6 @@ using OmniSharp.Models; using OmniSharp.Models.MembersTree; using OmniSharp.Models.V2.CodeActions; -using OmniSharp.Models.V2.CodeStructure; using OmniSharp.MSBuild.Models; using OmniSharp.Options; using OmniSharp.Roslyn.CSharp.Services.Refactoring.V2; @@ -17,8 +16,8 @@ namespace OmniSharp.MSBuild.Tests { public class LoadProjectsOnDemandTests : AbstractMSBuildTestFixture { - public LoadProjectsOnDemandTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public LoadProjectsOnDemandTests(ITestOutputHelper output) + : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs index 2e3cfd4f50..a590a51ac8 100644 --- a/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/MSBuildDiagnosticTests.cs @@ -1,7 +1,6 @@ using Microsoft.Build.Framework; using OmniSharp.MSBuild.Logging; using OmniSharp.Utilities; -using TestUtility; using Xunit; using Xunit.Abstractions; @@ -9,8 +8,7 @@ namespace OmniSharp.MSBuild.Tests { public class MSBuildDiagnosticTests : AbstractMSBuildTestFixture { - public MSBuildDiagnosticTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public MSBuildDiagnosticTests(ITestOutputHelper output) : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs b/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs index 739da50cb0..f7c01ec35d 100644 --- a/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/NotificationTests.cs @@ -12,8 +12,8 @@ namespace OmniSharp.MSBuild.Tests { public class NotificationTests : AbstractMSBuildTestFixture { - public NotificationTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public NotificationTests(ITestOutputHelper output) + : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj index 8084815226..37a3d4d3bd 100644 --- a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj +++ b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj @@ -25,8 +25,8 @@ diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 1d8d932f9a..3bb571fe71 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -18,8 +18,7 @@ public partial class ProjectLoadListenerTests : AbstractMSBuildTestFixture private readonly VsTfmAndFileExtHashingAlgorithm _tfmAndFileHashingAlgorithm; private readonly VsReferenceHashingAlgorithm _referenceHashingAlgorithm; - public ProjectLoadListenerTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public ProjectLoadListenerTests(ITestOutputHelper output) : base(output) { _tfmAndFileHashingAlgorithm = new VsTfmAndFileExtHashingAlgorithm(); _referenceHashingAlgorithm = new VsReferenceHashingAlgorithm(); diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs index 0a01c28839..03bab1be78 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithAdditionalFilesTests.cs @@ -9,8 +9,8 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithAdditionalFilesTests : AbstractMSBuildTestFixture { - public ProjectWithAdditionalFilesTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public ProjectWithAdditionalFilesTests(ITestOutputHelper output) + : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs index 6eb100ab47..bed546131e 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithAnalyzersTests.cs @@ -20,8 +20,8 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithAnalyzersTests : AbstractMSBuildTestFixture { - public ProjectWithAnalyzersTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public ProjectWithAnalyzersTests(ITestOutputHelper output) + : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs index f40ef76dd1..96665d4537 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectWithComplexAnalyzersTests.cs @@ -11,8 +11,7 @@ namespace OmniSharp.MSBuild.Tests { public class ProjectWithComplexAnalyzersTests : AbstractMSBuildTestFixture { - public ProjectWithComplexAnalyzersTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public ProjectWithComplexAnalyzersTests(ITestOutputHelper output) : base(output) { } diff --git a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs index 880ae9f1ce..d4303e386a 100644 --- a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs @@ -14,8 +14,8 @@ namespace OmniSharp.MSBuild.Tests { public class WorkspaceInformationTests : AbstractMSBuildTestFixture { - public WorkspaceInformationTests(ITestOutputHelper output, SharedOmniSharpHostFixture sharedOmniSharpHostFixture) - : base(output, sharedOmniSharpHostFixture) + public WorkspaceInformationTests(ITestOutputHelper output) + : base(output) { } diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj b/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj index cabd3cae36..70f171f7d5 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj @@ -23,8 +23,8 @@ diff --git a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj index 52677fe437..865ba7a150 100644 --- a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj +++ b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj @@ -21,8 +21,8 @@ diff --git a/tests/TestUtility/TestServiceProvider.cs b/tests/TestUtility/TestServiceProvider.cs index 63f00ed1e3..c14088dac5 100644 --- a/tests/TestUtility/TestServiceProvider.cs +++ b/tests/TestUtility/TestServiceProvider.cs @@ -167,7 +167,7 @@ private static IDotNetCliService CreateDotNetCliService( private static IMSBuildLocator CreateMSBuildLocator(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, - IConfiguration configurationData) + IConfiguration configurationData = null) => MSBuildLocator.CreateDefault(loggerFactory, assemblyLoader, configurationData); private static ISharedTextWriter CreateSharedTextWriter(ITestOutputHelper testOutput) From d34a431e31144149bff7329ff292ba6d6683b469 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 00:02:06 -0700 Subject: [PATCH 10/24] Restore Mono test behavior --- build.cake | 11 +++++++++++ .../MSBuild/Discovery/MSBuildLocator.cs | 1 - 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/build.cake b/build.cake index dd2979b95c..efb8474cc3 100644 --- a/build.cake +++ b/build.cake @@ -329,6 +329,17 @@ Task("Test") } else { + if (!Platform.Current.IsWindows) + { + // Copy the Mono-built Microsoft.Build.* binaries to the test folder. + // This is necessary to work around a Mono bug that is exasperated by xUnit. + var monoBasePath = Platform.Current.IsMacOS + ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" + : "/usr/lib/mono"; + var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; + DirectoryHelper.Copy(monoMSBuildPath, instanceFolder); + } + Run("mono", $"\"{xunitInstancePath}\" {arguments}", instanceFolder) .ExceptionOnError($"Test {testProject} failed for net472"); } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 8984745fa7..742f23a78b 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Immutable; using System.IO; -using System.Reflection; using System.Text; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; From ca1a590014cb7c75b3d71fe4f66df0fba7b90d05 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 00:41:07 -0700 Subject: [PATCH 11/24] Copy only the necessary MSBuild libraries --- build.cake | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/build.cake b/build.cake index efb8474cc3..8711b83180 100644 --- a/build.cake +++ b/build.cake @@ -329,16 +329,9 @@ Task("Test") } else { - if (!Platform.Current.IsWindows) - { - // Copy the Mono-built Microsoft.Build.* binaries to the test folder. - // This is necessary to work around a Mono bug that is exasperated by xUnit. - var monoBasePath = Platform.Current.IsMacOS - ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" - : "/usr/lib/mono"; - var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; - DirectoryHelper.Copy(monoMSBuildPath, instanceFolder); - } + // Copy the Mono-built Microsoft.Build.* binaries to the test folder. + // This is necessary to work around a Mono bug that is exasperated by xUnit. + CopyMonoMSBuildBinaries(instanceFolder); Run("mono", $"\"{xunitInstancePath}\" {arguments}", instanceFolder) .ExceptionOnError($"Test {testProject} failed for net472"); @@ -347,6 +340,26 @@ Task("Test") } }); +void CopyMonoMSBuildBinaries(string outputFolder) +{ + var monoBasePath = Platform.Current.IsMacOS + ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" + : "/usr/lib/mono"; + var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; + var msBuildAssemblies = new string[] + { + "Microsoft.Build.dll", + "Microsoft.Build.Framework.dll", + "Microsoft.Build.Tasks.Core.dll", + "Microsoft.Build.Utilities.Core.dll", + "Microsoft.NET.StringTools.dll", + }; + foreach (var msBuildAssembly in msBuildAssemblies) + { + FileHelper.Copy(CombinePaths(monoMSBuildPath, msBuildAssembly), CombinePaths(outputFolder, msBuildAssembly), overwrite: true); + } +} + void CopyExtraDependencies(BuildEnvironment env, string outputFolder) { // copy license From b0eb7d64c182bc5fb1533f57e4d4b75751d836d0 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 11:25:39 -0700 Subject: [PATCH 12/24] Copy Mono MSBuild files when testing but do not overwrite --- build.cake | 26 +++++--------------------- scripts/common.cake | 9 ++++++--- 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/build.cake b/build.cake index 8711b83180..222984a566 100644 --- a/build.cake +++ b/build.cake @@ -331,7 +331,11 @@ Task("Test") { // Copy the Mono-built Microsoft.Build.* binaries to the test folder. // This is necessary to work around a Mono bug that is exasperated by xUnit. - CopyMonoMSBuildBinaries(instanceFolder); + var monoBasePath = Platform.Current.IsMacOS + ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" + : "/usr/lib/mono"; + var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; + DirectoryHelper.Copy(monoMSBuildPath, instanceFolder, replaceFiles: false); Run("mono", $"\"{xunitInstancePath}\" {arguments}", instanceFolder) .ExceptionOnError($"Test {testProject} failed for net472"); @@ -340,26 +344,6 @@ Task("Test") } }); -void CopyMonoMSBuildBinaries(string outputFolder) -{ - var monoBasePath = Platform.Current.IsMacOS - ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" - : "/usr/lib/mono"; - var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; - var msBuildAssemblies = new string[] - { - "Microsoft.Build.dll", - "Microsoft.Build.Framework.dll", - "Microsoft.Build.Tasks.Core.dll", - "Microsoft.Build.Utilities.Core.dll", - "Microsoft.NET.StringTools.dll", - }; - foreach (var msBuildAssembly in msBuildAssemblies) - { - FileHelper.Copy(CombinePaths(monoMSBuildPath, msBuildAssembly), CombinePaths(outputFolder, msBuildAssembly), overwrite: true); - } -} - void CopyExtraDependencies(BuildEnvironment env, string outputFolder) { // copy license diff --git a/scripts/common.cake b/scripts/common.cake index 7815af3866..2aaf04e6cc 100644 --- a/scripts/common.cake +++ b/scripts/common.cake @@ -46,7 +46,7 @@ public static class DirectoryHelper return System.IO.Directory.GetFiles(path, searchPattern); } - public static void Copy(string source, string destination, bool copySubDirectories = true) + public static void Copy(string source, string destination, bool copySubDirectories = true, bool replaceFiles = true) { var files = GetFiles(source); var subDirectories = System.IO.Directory.GetDirectories(source); @@ -59,7 +59,10 @@ public static class DirectoryHelper foreach (var file in files) { var newFile = PathHelper.Combine(destination, PathHelper.GetFileName(file)); - FileHelper.Copy(file, newFile, overwrite: true); + if (replaceFiles || !FileHelper.Exists(newFile)) + { + FileHelper.Copy(file, newFile, overwrite: true); + } } if (copySubDirectories) @@ -67,7 +70,7 @@ public static class DirectoryHelper foreach (var subDirectory in subDirectories) { var newSubDirectory = PathHelper.Combine(destination, PathHelper.GetFileName(subDirectory)); - Copy(subDirectory, newSubDirectory); + Copy(subDirectory, newSubDirectory, copySubDirectories, replaceFiles); } } } From 78bdcc41ad6740dfa0098766d266400f90763062 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 12:00:42 -0700 Subject: [PATCH 13/24] Copy SQLite libraries during Mono tests --- build.cake | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/build.cake b/build.cake index 222984a566..0e933ad656 100644 --- a/build.cake +++ b/build.cake @@ -331,11 +331,7 @@ Task("Test") { // Copy the Mono-built Microsoft.Build.* binaries to the test folder. // This is necessary to work around a Mono bug that is exasperated by xUnit. - var monoBasePath = Platform.Current.IsMacOS - ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" - : "/usr/lib/mono"; - var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; - DirectoryHelper.Copy(monoMSBuildPath, instanceFolder, replaceFiles: false); + CopyMonoMSBuildBinaries(instanceFolder); Run("mono", $"\"{xunitInstancePath}\" {arguments}", instanceFolder) .ExceptionOnError($"Test {testProject} failed for net472"); @@ -344,6 +340,29 @@ Task("Test") } }); +void CopyMonoMSBuildBinaries(string outputFolder) +{ + var monoBasePath = Platform.Current.IsMacOS + ? "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono" + : "/usr/lib/mono"; + var monoMSBuildPath = $"{monoBasePath}/msbuild/Current/bin"; + DirectoryHelper.Copy(monoMSBuildPath, outputFolder, replaceFiles: false); + + // Copy dependencies of Mono build + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.core", "lib", "netstandard2.0", "SQLitePCLRaw.core.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.core.dll"), + overwrite: true); + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.provider.e_sqlite3", "lib", "netstandard2.0", "SQLitePCLRaw.provider.e_sqlite3.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.provider.e_sqlite3.dll"), + overwrite: true); + FileHelper.Copy( + source: CombinePaths(env.Folders.Tools, "SQLitePCLRaw.bundle_green", "lib", "netstandard2.0", "SQLitePCLRaw.batteries_v2.dll"), + destination: CombinePaths(outputFolder, "SQLitePCLRaw.batteries_v2.dll"), + overwrite: true); +} + void CopyExtraDependencies(BuildEnvironment env, string outputFolder) { // copy license From 3ccc284e69345bd29f8fe11474801045b3114c20 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 15:14:12 -0700 Subject: [PATCH 14/24] Run OmniSharpMSBuild.Tests on Mono in CI --- .github/workflows/tests-net6.yml | 2 +- .github/workflows/tests.yml | 72 ++++---------------------------- 2 files changed, 10 insertions(+), 64 deletions(-) diff --git a/.github/workflows/tests-net6.yml b/.github/workflows/tests-net6.yml index c9d66b10ad..d77576b6fc 100644 --- a/.github/workflows/tests-net6.yml +++ b/.github/workflows/tests-net6.yml @@ -26,7 +26,7 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-18.04, windows-2019, macos-10.15] + os: [ubuntu-20.04, windows-2022, macos-11] testProjects: - OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests - OmniSharp.DotNetTest.Tests diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3db16ef715..77bc274575 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -25,11 +25,9 @@ jobs: strategy: fail-fast: false matrix: - # TODO: mono 6.12 is installed on ubuntu and macos images, but ships with MSBuild 16.6. - # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md os: [ubuntu-20.04, windows-2022, macos-11] testProjects: - - OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests + - OmniSharp.MSBuild.Tests,OmniSharp.Roslyn.CSharp.Tests,OmniSharp.Cake.Tests,OmniSharp.Script.Tests,OmniSharp.Stdio.Tests,OmniSharp.Http.Tests,OmniSharp.Tests,OmniSharp.Lsp.Tests - OmniSharp.DotNetTest.Tests name: 'Test' steps: @@ -39,6 +37,14 @@ jobs: clean: 'false' fetch-depth: '0' + # TODO: Need to figure out the correct way to install mono on linux / mac + # Currently the latest image has mono 6.12 + # https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu1804-README.md + # - name: 🔨 Use Mono ${{ env.MonoVersion }} SDK + # uses: maxim-lobanov/setup-xamarin@v1 + # with: + # mono-version: ${{ env.MonoVersion }} + - name: Setup NuGet.exe uses: nuget/setup-nuget@v1 with: @@ -102,63 +108,3 @@ jobs: with: name: 'logs - ${{ github.workflow }} ${{ matrix.os }}' path: '${{ env.Artifacts }}/logs/' - - test-msbuild: - # Limit the .NET Framework OmniSharp.MSBuild.Tests to the Windows Platform, - # since we have access to a MSBuild newer than version 16.6. - runs-on: windows-2022 - strategy: - fail-fast: false - matrix: - testProjects: - - OmniSharp.MSBuild.Tests - name: 'Test' - steps: - - name: Checkout - uses: actions/checkout@v2 - with: - clean: 'false' - fetch-depth: '0' - - - name: Setup NuGet.exe - uses: nuget/setup-nuget@v1 - with: - nuget-version: ${{ env.NuGetVersion }} - - - name: 🔨 Use .NET Core ${{ env.DotNetVersion2 }} SDK - uses: actions/setup-dotnet@v1.7.2 - with: - dotnet-version: ${{ env.DotNetVersion2 }} - - - name: 🔨 Use .NET Core ${{ env.DotNetVersion }} SDK - uses: actions/setup-dotnet@v1.7.2 - with: - dotnet-version: ${{ env.DotNetVersion }} - - - name: 🎁 dotnet tool restore - run: | - dotnet tool restore - - - name: 🎁 nuget install - run: | - nuget install tools/packages.config -ExcludeVersion -OutputDirectory tools - - - name: 🍰 Run Cake - uses: nick-invision/retry@v2 - with: - shell: powershell - timeout_minutes: 40 - max_attempts: 3 - retry_on: error - command: | - .\build.ps1 -configuration Release -verbosity Verbose -target Test --test-project="$ENV:TEST_PROJECT" - env: - TEST_PROJECT: ${{ matrix.testProjects }} - - - name: ⬆ Publish Logs - uses: actions/upload-artifact@v2 - continue-on-error: true - if: ${{ always() }} - with: - name: 'logs - ${{ github.workflow }} ${{ matrix.os }}' - path: '${{ env.Artifacts }}/logs/' From 985568744a23a298bbbf7394db997907e41afbeb Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 15:25:11 -0700 Subject: [PATCH 15/24] Remove unused code --- .../MSBuild/Discovery/DiscoveryType.cs | 6 +-- .../Utilities/PlatformHelper.cs | 54 ------------------- 2 files changed, 1 insertion(+), 59 deletions(-) diff --git a/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs b/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs index ae360f31ad..88d4446175 100644 --- a/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs +++ b/src/OmniSharp.Abstractions/MSBuild/Discovery/DiscoveryType.cs @@ -1,11 +1,7 @@ -using System; - -namespace OmniSharp.MSBuild.Discovery +namespace OmniSharp.MSBuild.Discovery { public enum DiscoveryType { - [Obsolete("The StandAlone type is no longer supported.")] - StandAlone = 0, DeveloperConsole = 1, VisualStudioSetup = 2, Mono = 3, diff --git a/src/OmniSharp.Shared/Utilities/PlatformHelper.cs b/src/OmniSharp.Shared/Utilities/PlatformHelper.cs index cc17979ec7..a635365b98 100644 --- a/src/OmniSharp.Shared/Utilities/PlatformHelper.cs +++ b/src/OmniSharp.Shared/Utilities/PlatformHelper.cs @@ -167,59 +167,5 @@ public static string GetMonoMSBuildDirPath() ? monoMSBuildDirPath : null; } - - public static string GetMonoXBuildDirPath() - { - if (IsWindows) - { - return null; - } - - const string DefaultMonoXBuildDirPath = "/usr/lib/mono/xbuild"; - if (Directory.Exists(DefaultMonoXBuildDirPath)) - { - return DefaultMonoXBuildDirPath; - } - - var monoLibDirPath = GetMonoLibDirPath(); - if (monoLibDirPath == null) - { - return null; - } - - var monoXBuildDirPath = Path.Combine(monoLibDirPath, "xbuild"); - monoXBuildDirPath = Path.GetFullPath(monoXBuildDirPath); - - return Directory.Exists(monoXBuildDirPath) - ? monoXBuildDirPath - : null; - } - - public static string GetMonoXBuildFrameworksDirPath() - { - if (IsWindows) - { - return null; - } - - const string DefaultMonoXBuildFrameworksDirPath = "/usr/lib/mono/xbuild-frameworks"; - if (Directory.Exists(DefaultMonoXBuildFrameworksDirPath)) - { - return DefaultMonoXBuildFrameworksDirPath; - } - - var monoLibDirPath = GetMonoLibDirPath(); - if (monoLibDirPath == null) - { - return null; - } - - var monoXBuildFrameworksDirPath = Path.Combine(monoLibDirPath, "xbuild-frameworks"); - monoXBuildFrameworksDirPath = Path.GetFullPath(monoXBuildFrameworksDirPath); - - return Directory.Exists(monoXBuildFrameworksDirPath) - ? monoXBuildFrameworksDirPath - : null; - } } } From 1bb8c93fb0354461515d1dfe4fab0c4e9c54ac62 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 16:12:26 -0700 Subject: [PATCH 16/24] Skip NET5+ MSBuild tests against Mono --- test-assets/test-projects/ExternAlias/global.json | 4 ++-- .../ProjectLoadListenerTests.cs | 4 ++-- .../WorkspaceInformationTests.cs | 4 ++-- tests/TestUtility/ConditionalFactAttribute.cs | 15 +++++++++++++++ 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/test-assets/test-projects/ExternAlias/global.json b/test-assets/test-projects/ExternAlias/global.json index d131a2620b..eca148f377 100644 --- a/test-assets/test-projects/ExternAlias/global.json +++ b/test-assets/test-projects/ExternAlias/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "5.0.403" + "version": "3.1.415" } -} +} \ No newline at end of file diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 3bb571fe71..c3725a23ec 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -221,7 +221,7 @@ public async Task The_correct_sdk_version_is_emitted_NETCore3_1() Assert.Equal(GetHashedFileExtension("3.1.415"), emitter.ReceivedMessages[0].SdkVersion); } - [Fact] + [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task The_correct_sdk_version_is_emitted_NET5() { // Arrange @@ -233,7 +233,7 @@ public async Task The_correct_sdk_version_is_emitted_NET5() Assert.Equal(GetHashedFileExtension("5.0.403"), emitter.ReceivedMessages[0].SdkVersion); } - [ConditionalFact(typeof(DesktopRuntimeOnly))] + [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task The_correct_sdk_version_is_emitted_NET6() { // Arrange diff --git a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs index d4303e386a..d93eaedbd7 100644 --- a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs @@ -87,7 +87,7 @@ public async Task ProjectAndSolutionWithProjectSection() Assert.Equal("netcoreapp3.1", project.TargetFrameworks[0].ShortName); } - [Fact] + [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task Net50Solution() { using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net50Project"); @@ -106,7 +106,7 @@ public async Task Net50Solution() Assert.Contains(libProject.TargetFrameworks[0].ShortName, new[] { "net50", "net5.0" }); } - [ConditionalFact(typeof(DesktopRuntimeOnly))] + [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task Net60Project() { using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net60Project"); diff --git a/tests/TestUtility/ConditionalFactAttribute.cs b/tests/TestUtility/ConditionalFactAttribute.cs index 00b1c06134..a1c1ad587b 100644 --- a/tests/TestUtility/ConditionalFactAttribute.cs +++ b/tests/TestUtility/ConditionalFactAttribute.cs @@ -69,4 +69,19 @@ public class DesktopRuntimeOnly : SkipCondition #endif public override string SkipReason => "Can only be run on Desktop runtime"; } + + public class NonMonoRuntimeOnly : SkipCondition + { + public override bool ShouldSkip => +#if NET472 + !PlatformHelper.IsWindows; +#elif NETCOREAPP + false; +#elif NETSTANDARD2_0 + throw new PlatformNotSupportedException(); +#else +#error Unsupported configuration +#endif + public override string SkipReason => "Can not be run on Mono runtime"; + } } From 097a3549cbaeef6dd8ee13c590396896c90aab5e Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 20 Mar 2022 20:22:27 -0700 Subject: [PATCH 17/24] Restore run script in Mono O# packages --- build.cake | 4 ++++ mono-packaging/run | 26 ++++++++++++++++++++++++++ scripts/common.cake | 2 ++ 3 files changed, 32 insertions(+) create mode 100644 mono-packaging/run diff --git a/build.cake b/build.cake index 0e933ad656..ac83ed697a 100644 --- a/build.cake +++ b/build.cake @@ -464,6 +464,10 @@ string PublishMonoBuildForPlatform(string project, MonoRuntime monoRuntime, Buil DirectoryHelper.Copy(sourceFolder, omnisharpFolder, copySubDirectories: false); + var runScriptFile = CombinePaths(env.Folders.MonoPackaging, "run"); + FileHelper.Copy(runScriptFile, CombinePaths(outputFolder, "run"), overwrite: true); + Run("chmod", $"+x '{CombinePaths(outputFolder, "run")}'"); + CopyExtraDependencies(env, outputFolder); AddOmniSharpBindingRedirects(omnisharpFolder); diff --git a/mono-packaging/run b/mono-packaging/run new file mode 100644 index 0000000000..af4c1e3c80 --- /dev/null +++ b/mono-packaging/run @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +base_dir="$(cd "$(dirname "$0")" && pwd -P)" +bin_dir=${base_dir}/bin +etc_dir=${base_dir}/etc +omnisharp_dir=${base_dir}/omnisharp + +mono_cmd=mono +omnisharp_cmd=${omnisharp_dir}/OmniSharp.exe +config_file=${etc_dir}/config + +no_omnisharp=false + +if [ "$1" = "--no-omnisharp" ]; then + shift + no_omnisharp=true +fi + +export MONO_CFG_DIR=${etc_dir} +export MONO_ENV_OPTIONS="--assembly-loader=strict --config \"${config_file}\"" + +if [ "$no_omnisharp" = true ]; then + "${mono_cmd}" "$@" +else + "${mono_cmd}" "${omnisharp_cmd}" "$@" +fi diff --git a/scripts/common.cake b/scripts/common.cake index 2aaf04e6cc..f84d3990d0 100644 --- a/scripts/common.cake +++ b/scripts/common.cake @@ -146,6 +146,7 @@ public class Folders public string Source { get; } public string Tests { get; } public string TestAssets { get; } + public string MonoPackaging { get; } public string Artifacts { get; } public string ArtifactsPublish { get; } @@ -163,6 +164,7 @@ public class Folders this.Source = PathHelper.Combine(workingDirectory, "src"); this.Tests = PathHelper.Combine(workingDirectory, "tests"); this.TestAssets = PathHelper.Combine(workingDirectory, "test-assets"); + this.MonoPackaging = PathHelper.Combine(workingDirectory, "mono-packaging"); this.Artifacts = PathHelper.Combine(workingDirectory, "artifacts"); this.ArtifactsPublish = PathHelper.Combine(this.Artifacts, "publish"); From c24a1e0d38a7c4eddc5906878985ac6a3c14e9e8 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 23 Mar 2022 18:37:02 -0700 Subject: [PATCH 18/24] Add warning when using deprecated 'UseBundledOnly' option --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 742f23a78b..1974824ca5 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -34,6 +34,12 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { + var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); + if (useBundledOnly) + { + logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); + } + return new MSBuildLocator(loggerFactory, assemblyLoader, ImmutableArray.Create( new MicrosoftBuildLocatorInstanceProvider(loggerFactory), From f17682299f426ab43014241b8f403630999a1af7 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 23 Mar 2022 21:12:40 -0700 Subject: [PATCH 19/24] Create logger before using it. --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 1974824ca5..a533f9be7c 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -37,6 +37,7 @@ public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemb var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); if (useBundledOnly) { + var logger = loggerFactory.CreateLogger(); logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); } From c38a67f1fdbbc84c1724ab6360775fc6a8ad1c95 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 23 Mar 2022 21:32:33 -0700 Subject: [PATCH 20/24] Use nullable type for option value. --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index a533f9be7c..a3e338fa29 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -34,8 +34,8 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { - var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); - if (useBundledOnly) + var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); + if (useBundledOnly.HasValue) { var logger = loggerFactory.CreateLogger(); logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); From c662bba1fdc8d44af3a9803afdaaf8174b59ac90 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 23 Mar 2022 22:17:23 -0700 Subject: [PATCH 21/24] Parse option as a string --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index a3e338fa29..9c99d5326c 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -34,8 +34,8 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { - var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); - if (useBundledOnly.HasValue) + var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); + if (useBundledOnly is not null) { var logger = loggerFactory.CreateLogger(); logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); From 8201fef392635ed89ff2e868618d8ce2be8f09b6 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Wed, 23 Mar 2022 22:37:59 -0700 Subject: [PATCH 22/24] Pass default value when getting option --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 9c99d5326c..d1c2b89fac 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -34,8 +34,8 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { - var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly"); - if (useBundledOnly is not null) + var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly", false); + if (useBundledOnly) { var logger = loggerFactory.CreateLogger(); logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); From 18bc3bae83d3c30bd4f47a61ec3a976347fd89bb Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 24 Mar 2022 09:19:46 -0700 Subject: [PATCH 23/24] Handle null configuration --- src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index d1c2b89fac..619df22c3a 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -34,7 +34,7 @@ protected override void DisposeCore(bool disposing) public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) { - var useBundledOnly = msbuildConfiguration.GetValue("UseBundledOnly", false); + var useBundledOnly = msbuildConfiguration?.GetValue("UseBundledOnly") ?? false; if (useBundledOnly) { var logger = loggerFactory.CreateLogger(); From 24c0c0fc4c498ef4800d0f12bfa6f206e1cab365 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Thu, 24 Mar 2022 11:33:47 -0700 Subject: [PATCH 24/24] Update changelog --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d7d567312e..d0341ebb91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,10 @@ # Changelog All changes to the project will be documented in this file. -## [1.38.2] +## [1.38.3] +* Remove MSBuild and Mono from release packages ([#2339](https://github.com/OmniSharp/omnisharp-roslyn/issues/2339), PR: [#2360](https://github.com/OmniSharp/omnisharp-roslyn/pull/2360)) + +## [1.38.2] - 2202-03-22 * Add analyze open documents only (PR: [#2346](https://github.com/OmniSharp/omnisharp-roslyn/pull/2346)) * Create a new GoToTypeDefinition endpoint ([#2297](https://github.com/OmniSharp/omnisharp-roslyn/issues/2297), PR: [#2315](https://github.com/OmniSharp/omnisharp-roslyn/pull/2315)) * Eliminate more instances of IWorkspaceOptionsProvider (PR: [#2343](https://github.com/OmniSharp/omnisharp-roslyn/pull/2343))