From 386d3e325fa2b51b19313d3143af6c25dc1af975 Mon Sep 17 00:00:00 2001 From: Dustin Campbell Date: Tue, 13 Dec 2016 16:39:18 -0800 Subject: [PATCH] Skip unit test --- src/OmniSharp.MSBuild/MSBuildProjectSystem.cs | 51 +++++++++++++++++-- .../ProjectFileInfoTests.cs | 22 +++----- tests/OmniSharp.MSBuild.Tests/project.json | 5 +- 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/OmniSharp.MSBuild/MSBuildProjectSystem.cs b/src/OmniSharp.MSBuild/MSBuildProjectSystem.cs index e8275f78e4..5fdc10a57a 100644 --- a/src/OmniSharp.MSBuild/MSBuildProjectSystem.cs +++ b/src/OmniSharp.MSBuild/MSBuildProjectSystem.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Collections.Immutable; using System.Composition; +using System.Diagnostics; using System.IO; using System.Linq; using System.Text; @@ -67,8 +68,49 @@ public MSBuildProjectSystem( _logger = loggerFactory.CreateLogger("OmniSharp#MSBuild"); } - public static void SetUpMSBuildEnvironment(string msbuildFolder, ILogger logger) + private static string FindMSBuildFolder() { + // Try to locate the appropriate build-time msbuild folder by searching for + // the OmniSharp solution relative to the current folder. + + var current = Directory.GetCurrentDirectory(); + while (!File.Exists(Path.Combine(current, "OmniSharp.sln"))) + { + current = Path.GetDirectoryName(current); + if (Path.GetPathRoot(current) == current) + { + break; + } + } + +#if NET46 + var folderName = ".msbuild-net46"; +#else + var folderName = ".msbuild-netcoreapp1.0"; +#endif + + var result = Path.Combine(current, folderName); + + return Directory.Exists(result) + ? result + : null; + } + + public static void SetUpMSBuildEnvironment(ILogger logger) + { + var msbuildFolder = Path.Combine(AppContext.BaseDirectory, "msbuild"); + + if (!Directory.Exists(msbuildFolder)) + { + msbuildFolder = FindMSBuildFolder(); + } + + if (msbuildFolder == null || !Directory.Exists(msbuildFolder)) + { + logger.LogError("Could not locate MSBuild path. MSBuildProjectSystem will not function properly."); + return; + } + // Set the MSBuildExtensionsPath environment variable to the msbuild folder. Environment.SetEnvironmentVariable("MSBuildExtensionsPath", msbuildFolder); logger.LogInformation($"MSBuildExtensionsPath environment variable set to {msbuildFolder}"); @@ -114,13 +156,12 @@ public void Initalize(IConfiguration configuration) _options = new MSBuildOptions(); ConfigurationBinder.Bind(configuration, _options); - var msbuildFolder = Path.Combine(AppContext.BaseDirectory, "msbuild"); - SetUpMSBuildEnvironment(msbuildFolder, _logger); + SetUpMSBuildEnvironment(_logger); if (_options.WaitForDebugger) { - Console.WriteLine($"Attach to process {System.Diagnostics.Process.GetCurrentProcess().Id}"); - while (!System.Diagnostics.Debugger.IsAttached) + Console.WriteLine($"Attach to process {Process.GetCurrentProcess().Id}"); + while (!Debugger.IsAttached) { System.Threading.Thread.Sleep(100); } diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs index 9260adb0b0..f9231896e3 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs @@ -1,9 +1,11 @@ -using System.IO; +using System; +using System.IO; using Microsoft.Extensions.Logging; using OmniSharp.MSBuild.ProjectFile; using TestUtility; using TestUtility.Fake; using Xunit; +using Xunit.Abstractions; namespace OmniSharp.MSBuild.Tests { @@ -12,24 +14,15 @@ public class ProjectFileInfoTests private readonly TestAssets _testAssets; private readonly ILogger _logger; - public ProjectFileInfoTests() + public ProjectFileInfoTests(ITestOutputHelper output) { this._testAssets = TestAssets.Instance; + this._logger = new TestLogger(output); - var loggerFactory = new FakeLoggerFactory(); - this._logger = loggerFactory.CreateLogger("test"); - -#if NET46 - var folderName = ".msbuild-net46"; -#else - var folderName = ".msbuild-netcoreapp1.0"; -#endif - - var msbuildFolder = Path.Combine(this._testAssets.SolutionFolder, folderName); - MSBuildProjectSystem.SetUpMSBuildEnvironment(msbuildFolder, this._logger); + MSBuildProjectSystem.SetUpMSBuildEnvironment(this._logger); } - [Fact] + [Fact(Skip = "Won't work until we restore .NET Core .csproj projects")] public void Hello_world_has_correct_property_values() { var projectFolder = _testAssets.GetTestProjectFolder("HelloWorld"); @@ -37,6 +30,7 @@ public void Hello_world_has_correct_property_values() var projectFileInfo = ProjectFileInfo.Create(projectFilePath, projectFolder, this._logger); + Assert.NotNull(projectFileInfo); Assert.Equal(projectFilePath, projectFileInfo.ProjectFilePath); Assert.Equal(1, projectFileInfo.TargetFrameworks.Count); Assert.Equal(".NETCoreApp,Version=v1.0", projectFileInfo.TargetFrameworks[0].DotNetFrameworkName); diff --git a/tests/OmniSharp.MSBuild.Tests/project.json b/tests/OmniSharp.MSBuild.Tests/project.json index c8ddadf1fd..e05b197eca 100644 --- a/tests/OmniSharp.MSBuild.Tests/project.json +++ b/tests/OmniSharp.MSBuild.Tests/project.json @@ -1,10 +1,7 @@ { "version": "1.0.0-*", "buildOptions": { - "warningsAsErrors": true, - "copyToOutput": [ - "../../Microsoft.CSharp.Core.targets" - ] + "warningsAsErrors": true }, "dependencies": { "OmniSharp.MSBuild": "1.0.0",