From 62dcb23f3981d5e0962c99c07580d291fcf4896a Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 3 Apr 2022 21:45:27 -0700 Subject: [PATCH 01/14] Add NET7 SDK and tests --- build.json | 3 ++- .../Net70Project/Net70Project.csproj | 8 ++++++++ test-assets/test-projects/Net70Project/Program.cs | 12 ++++++++++++ .../test-projects/Net70Project/global.json | 5 +++++ .../ProjectLoadListenerTests.cs | 12 ++++++++++++ .../WorkspaceInformationTests.cs | 15 ++++++++++++++- 6 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 test-assets/test-projects/Net70Project/Net70Project.csproj create mode 100644 test-assets/test-projects/Net70Project/Program.cs create mode 100644 test-assets/test-projects/Net70Project/global.json diff --git a/build.json b/build.json index a83db1d04b..f37318ac51 100644 --- a/build.json +++ b/build.json @@ -4,7 +4,8 @@ "DotNetVersions": [ "3.1.417", "5.0.406", - "6.0.201" + "6.0.201", + "7.0.100-preview.2.22153.17" ], "RequiredMonoVersion": "6.6.0", "DownloadURL": "https://roslynomnisharp.blob.core.windows.net/ext", diff --git a/test-assets/test-projects/Net70Project/Net70Project.csproj b/test-assets/test-projects/Net70Project/Net70Project.csproj new file mode 100644 index 0000000000..120e38c315 --- /dev/null +++ b/test-assets/test-projects/Net70Project/Net70Project.csproj @@ -0,0 +1,8 @@ + + + + Exe + net7.0 + + + diff --git a/test-assets/test-projects/Net70Project/Program.cs b/test-assets/test-projects/Net70Project/Program.cs new file mode 100644 index 0000000000..dbae8113d5 --- /dev/null +++ b/test-assets/test-projects/Net70Project/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace ProjectAndSolution +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/test-assets/test-projects/Net70Project/global.json b/test-assets/test-projects/Net70Project/global.json new file mode 100644 index 0000000000..a6c620aacf --- /dev/null +++ b/test-assets/test-projects/Net70Project/global.json @@ -0,0 +1,5 @@ +{ + "sdk": { + "version": "7.0.100-preview.2.22153.17" + } +} diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index ae1d627856..3682f954c9 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -245,6 +245,18 @@ public async Task The_correct_sdk_version_is_emitted_NET6() Assert.Equal(GetHashedFileExtension("6.0.201"), emitter.ReceivedMessages[0].SdkVersion); } + [ConditionalFact(typeof(NonMonoRuntimeOnly))] + public async Task The_correct_sdk_version_is_emitted_NET7() + { + // Arrange + var emitter = new ProjectLoadTestEventEmitter(); + + using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net70Project"); + using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); + Assert.Single(emitter.ReceivedMessages); + Assert.Equal(GetHashedFileExtension("7.0.100-preview.2.22153.17"), emitter.ReceivedMessages[0].SdkVersion); + } + private string GetHashedFileExtension(string fileExtension) { return _tfmAndFileHashingAlgorithm.HashInput(fileExtension).Value; diff --git a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs index d93eaedbd7..5dd5e70c08 100644 --- a/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/WorkspaceInformationTests.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Reflection; using System.Threading.Tasks; -using Microsoft.CodeAnalysis; using Microsoft.Extensions.Logging; using TestUtility; using Xunit; @@ -120,6 +119,20 @@ public async Task Net60Project() Assert.Contains(project.TargetFrameworks[0].ShortName, new[] { "net60", "net6.0" }); } + [ConditionalFact(typeof(NonMonoRuntimeOnly))] + public async Task Net70Project() + { + using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net70Project"); + using var host = CreateMSBuildTestHost(testProject.Directory); + var workspaceInfo = await host.RequestMSBuildWorkspaceInfoAsync(); + + Assert.NotNull(workspaceInfo.Projects); + var project = Assert.Single(workspaceInfo.Projects); + Assert.Equal("Net70Project", project.AssemblyName); + Assert.Equal(".NETCoreApp,Version=v7.0", project.TargetFramework); + Assert.Contains(project.TargetFrameworks[0].ShortName, new[] { "net70", "net7.0" }); + } + [Fact] public async Task TwoProjectsWithSolution() { From b7b0ced1e2a0c472929f8f590469310fdc1e4175 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 3 Apr 2022 21:46:28 -0700 Subject: [PATCH 02/14] Add SdkOptions and separate SDK locating --- src/OmniSharp.Host/CompositionHostBuilder.cs | 2 +- .../MSBuild/Discovery/MSBuildLocator.cs | 14 +- .../MicrosoftBuildLocatorInstanceProvider.cs | 40 ++---- .../Providers/SdkInstanceProvider.cs | 120 ++++++++++++++++++ .../MSBuild/Discovery/Providers/SdkOptions.cs | 15 +++ .../Providers/SdkOverrideInstanceProvider.cs | 52 ++++++++ .../Providers/UserOverrideInstanceProvider.cs | 7 +- .../AbstractMSBuildTestFixture.cs | 2 +- tests/TestUtility/TestHelpers.cs | 5 +- 9 files changed, 216 insertions(+), 41 deletions(-) create mode 100644 src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs create mode 100644 src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOptions.cs create mode 100644 src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs diff --git a/src/OmniSharp.Host/CompositionHostBuilder.cs b/src/OmniSharp.Host/CompositionHostBuilder.cs index ad9be7a5aa..d9698e10ef 100644 --- a/src/OmniSharp.Host/CompositionHostBuilder.cs +++ b/src/OmniSharp.Host/CompositionHostBuilder.cs @@ -153,7 +153,7 @@ public static IServiceProvider CreateDefaultServiceProvider( MSBuildLocator.CreateDefault( loggerFactory: sp.GetService(), assemblyLoader: sp.GetService(), - msbuildConfiguration: configuration.GetSection("msbuild"))); + configuration: configuration)); services.AddLogging(builder => { diff --git a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs index 619df22c3a..7769ec4d4a 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs @@ -32,8 +32,9 @@ protected override void DisposeCore(bool disposing) } } - public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration msbuildConfiguration) + public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemblyLoader assemblyLoader, IConfiguration configuration) { + var msbuildConfiguration = configuration?.GetSection("msbuild"); var useBundledOnly = msbuildConfiguration?.GetValue("UseBundledOnly") ?? false; if (useBundledOnly) { @@ -41,13 +42,20 @@ public static MSBuildLocator CreateDefault(ILoggerFactory loggerFactory, IAssemb logger.LogWarning("The MSBuild option 'UseBundledOnly' is no longer supported. Please update your OmniSharp configuration files."); } +#if NETCOREAPP + var sdkConfiguration = configuration?.GetSection("sdk"); + + return new MSBuildLocator(loggerFactory, assemblyLoader, + ImmutableArray.Create( + new SdkInstanceProvider(loggerFactory, sdkConfiguration), + new SdkOverrideInstanceProvider(loggerFactory, sdkConfiguration))); +#else return new MSBuildLocator(loggerFactory, assemblyLoader, ImmutableArray.Create( new MicrosoftBuildLocatorInstanceProvider(loggerFactory), -#if !NETCOREAPP new MonoInstanceProvider(loggerFactory), -#endif new UserOverrideInstanceProvider(loggerFactory, msbuildConfiguration))); +#endif } public void RegisterInstance(MSBuildInstance instance) diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MicrosoftBuildLocatorInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MicrosoftBuildLocatorInstanceProvider.cs index ed29222e0e..6e30a96325 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/MicrosoftBuildLocatorInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/MicrosoftBuildLocatorInstanceProvider.cs @@ -5,9 +5,7 @@ using Microsoft.Extensions.Logging; using MicrosoftBuildLocator = Microsoft.Build.Locator.MSBuildLocator; using MicrosoftDiscoveryType = Microsoft.Build.Locator.DiscoveryType; -#if !NETCOREAPP using OmniSharp.Utilities; -#endif namespace OmniSharp.MSBuild.Discovery.Providers { @@ -20,38 +18,23 @@ public MicrosoftBuildLocatorInstanceProvider(ILoggerFactory loggerFactory) public override ImmutableArray GetInstances() { - -#if NETCOREAPP - // Restrict instances to NET 6 SDK - var instances = MicrosoftBuildLocator.QueryVisualStudioInstances() - .Where(instance => instance.Version.Major == 6) - .OrderByDescending(instance => instance.Version) - .ToImmutableArray(); - - if (instances.Length == 0) - { - Logger.LogError($"OmniSharp requires the .NET 6 SDK be installed. Please visit https://dotnet.microsoft.com/download/dotnet/6.0 to download the .NET SDK."); - } -#else if (!PlatformHelper.IsWindows) { return NoInstances; } - var instances = MicrosoftBuildLocator.QueryVisualStudioInstances(); -#endif - - return instances.Select(instance => - { - var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll"); - var version = GetMSBuildVersion(microsoftBuildPath); + return MicrosoftBuildLocator.QueryVisualStudioInstances() + .Select(instance => + { + var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll"); + var version = GetMSBuildVersion(microsoftBuildPath); - return new MSBuildInstance( - $"{instance.Name} {instance.Version}", - instance.MSBuildPath, - version, - GetDiscoveryType(instance.DiscoveryType)); - }).ToImmutableArray(); + return new MSBuildInstance( + $"{instance.Name} {instance.Version}", + instance.MSBuildPath, + version, + GetDiscoveryType(instance.DiscoveryType)); + }).ToImmutableArray(); static DiscoveryType GetDiscoveryType(MicrosoftDiscoveryType discoveryType) { @@ -59,7 +42,6 @@ static DiscoveryType GetDiscoveryType(MicrosoftDiscoveryType discoveryType) { MicrosoftDiscoveryType.DeveloperConsole => DiscoveryType.DeveloperConsole, MicrosoftDiscoveryType.VisualStudioSetup => DiscoveryType.VisualStudioSetup, - MicrosoftDiscoveryType.DotNetSdk => DiscoveryType.DotNetSdk, _ => throw new ArgumentException() }; } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs new file mode 100644 index 0000000000..87d9492c76 --- /dev/null +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs @@ -0,0 +1,120 @@ +using System.Collections.Immutable; +using System.IO; +using System.Linq; +using Microsoft.Build.Locator; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; +using MicrosoftBuildLocator = Microsoft.Build.Locator.MSBuildLocator; + +namespace OmniSharp.MSBuild.Discovery.Providers +{ + internal class SdkInstanceProvider : MSBuildInstanceProvider + { + private readonly SdkOptions _options; + + public SdkInstanceProvider(ILoggerFactory loggerFactory, IConfiguration sdkConfiguration) + : base(loggerFactory) + { + _options = sdkConfiguration?.Get(); + } + + public override ImmutableArray GetInstances() + { + var includePrerelease = _options?.IncludePrereleases == true; + + SemanticVersion optionsVersion = null; + if (!string.IsNullOrEmpty(_options?.Version)) + { + if (!SemanticVersion.TryParse(_options.Version, out optionsVersion)) + { + Logger.LogError($"The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is '{optionsVersion}'. Please update your settings and restart OmniSharp."); + return NoInstances; + } + else if (optionsVersion.Major < 6) + { + Logger.LogError($"The Sdk version specified in the OmniSharp settings is not .NET 6 or higher. Configured version is '{optionsVersion}'. Please update your settings and restart OmniSharp."); + return NoInstances; + } + } + + var instances = MicrosoftBuildLocator.QueryVisualStudioInstances() + .Where(instance => IncludeSdkInstance(instance, optionsVersion, includePrerelease)) + .OrderByDescending(instance => instance.Version) + .ToImmutableArray(); + + if (instances.Length == 0) + { + if (optionsVersion is null) + { + Logger.LogError($"OmniSharp requires the .NET 6 SDK or higher be installed. Please visit https://dotnet.microsoft.com/download/dotnet/6.0 to download the .NET SDK."); + } + else + { + Logger.LogError($"The Sdk version specified in the OmniSharp settings could not be found. Configured version is '{optionsVersion}'. Please update your settings and restart OmniSharp."); + } + + return NoInstances; + } + + return instances.Select(instance => + { + var microsoftBuildPath = Path.Combine(instance.MSBuildPath, "Microsoft.Build.dll"); + var version = GetMSBuildVersion(microsoftBuildPath); + + return new MSBuildInstance( + $"{instance.Name} {instance.Version}", + instance.MSBuildPath, + version, + DiscoveryType.DotNetSdk, + _options?.PropertyOverrides?.ToImmutableDictionary()); + }).ToImmutableArray(); + } + + public static bool IncludeSdkInstance(VisualStudioInstance instance, SemanticVersion targetVersion, bool includePrerelease) + { + // If the path does not have a `.version` file, then do not consider it a valid option. + if (!TryGetSdkVersion(instance.VisualStudioRootPath, out var version)) + { + return false; + } + + // If the version is less than .NET 6, then do not consider it a valid option. + if (version.Major < 6) + { + return false; + } + + // If a target version was specified, then only a matching version is a valid option. + if (targetVersion is not null) + { + return version.Equals(targetVersion); + } + + // If we are including prereleases then everything else is valid, otherwise check that it is not a prerelease sdk. + return includePrerelease || + string.IsNullOrEmpty(version.PreReleaseLabel); + } + + public static bool TryGetSdkVersion(string sdkPath, out SemanticVersion version) + { + version = null; + + var versionPath = Path.Combine(sdkPath, ".version"); + if (!File.Exists(versionPath)) + { + return false; + } + + var lines = File.ReadAllLines(versionPath); + foreach (var line in lines) + { + if (SemanticVersion.TryParse(line, out version)) + { + return true; + } + } + + return false; + } + } +} diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOptions.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOptions.cs new file mode 100644 index 0000000000..fcac04c809 --- /dev/null +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOptions.cs @@ -0,0 +1,15 @@ +using System.Collections.Generic; + +namespace OmniSharp.MSBuild.Discovery.Providers +{ + internal class SdkOptions + { + public Dictionary PropertyOverrides { get; set; } + + public string Path { get; set; } + + public string Version { get; set; } + + public bool IncludePrereleases { get; set; } + } +} diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs new file mode 100644 index 0000000000..025b87a903 --- /dev/null +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Immutable; +using System.IO; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Logging; + +namespace OmniSharp.MSBuild.Discovery.Providers +{ + internal class SdkOverrideInstanceProvider : MSBuildInstanceProvider + { + private readonly SdkOptions _options; + + public SdkOverrideInstanceProvider(ILoggerFactory loggerFactory, IConfiguration sdkConfiguration) + : base(loggerFactory) + { + _options = sdkConfiguration?.Get(); + } + + public override ImmutableArray GetInstances() + { + if (string.IsNullOrEmpty(_options?.Path)) + { + return NoInstances; + } + + if (!File.Exists(_options.Path)) + { + Logger.LogError($"The Sdk path specified in the OmniSharp settings does not exist. Configured path is '{_options.Path}'. Please update your settings and restart OmniSharp."); + return NoInstances; + } + + if (!SdkInstanceProvider.TryGetSdkVersion(_options.Path, out var pathVersion)) + { + Logger.LogError($"The Sdk path specified in the OmniSharp settings does not appear to be a valid SDK. Configured path is '{_options.Path}'. Please update your settings and restart OmniSharp."); + return NoInstances; + } + + if (pathVersion.Major < 6) + { + Logger.LogError($"The Sdk path specified in the OmniSharp settings is not .NET 6 or higher. Reported version is '{pathVersion}'. Please update your settings and restart OmniSharp."); + return NoInstances; + } + + return ImmutableArray.Create(new MSBuildInstance( + $".NET SDK {pathVersion} from {_options.Path}", + _options.Path, + new Version(pathVersion.Major, pathVersion.Minor, pathVersion.Patch), + DiscoveryType.UserOverride, + _options?.PropertyOverrides?.ToImmutableDictionary())); + } + } +} diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs index c7b3deedcf..a55d965c86 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/UserOverrideInstanceProvider.cs @@ -1,8 +1,6 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; -using System; using System.Collections.Immutable; -using System.Diagnostics; using System.IO; namespace OmniSharp.MSBuild.Discovery.Providers @@ -11,10 +9,10 @@ internal class UserOverrideInstanceProvider : MSBuildInstanceProvider { private readonly MSBuildOverrideOptions _options; - public UserOverrideInstanceProvider(ILoggerFactory loggerFactory, IConfiguration configuration) + public UserOverrideInstanceProvider(ILoggerFactory loggerFactory, IConfiguration msbuildConfiguration) : base(loggerFactory) { - _options = configuration?.GetSection("msbuildoverride").Get(); + _options = msbuildConfiguration?.GetSection("msbuildoverride").Get(); } public override ImmutableArray GetInstances() @@ -35,7 +33,6 @@ public override ImmutableArray GetInstances() DiscoveryType.UserOverride, _options.PropertyOverrides?.ToImmutableDictionary())); return builder.ToImmutable(); - } } } diff --git a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs index ff90378ec8..25cf3744d6 100644 --- a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs +++ b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs @@ -24,7 +24,7 @@ public AbstractMSBuildTestFixture(ITestOutputHelper output) { _assemblyLoader = new AssemblyLoader(this.LoggerFactory); _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; - _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, msbuildConfiguration: null); + _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configuration: null); // Some tests require MSBuild to be discovered early // to ensure that the Microsoft.Build.* assemblies can be located diff --git a/tests/TestUtility/TestHelpers.cs b/tests/TestUtility/TestHelpers.cs index 173f628890..de7f6624b5 100644 --- a/tests/TestUtility/TestHelpers.cs +++ b/tests/TestUtility/TestHelpers.cs @@ -142,9 +142,9 @@ public static MSBuildInstance AddDotNetCoreToFakeInstance(this MSBuildInstance i public static IConfiguration GetConfigurationDataWithAnalyzerConfig( bool roslynAnalyzersEnabled = false, + bool analyzeOpenDocumentsOnly = false, bool editorConfigEnabled = false, - Dictionary existingConfiguration = null, - bool analyzeOpenDocumentsOnly = false) + Dictionary existingConfiguration = null) { if (existingConfiguration == null) { @@ -158,6 +158,7 @@ public static IConfiguration GetConfigurationDataWithAnalyzerConfig( var copyOfExistingConfigs = existingConfiguration.ToDictionary(x => x.Key, x => x.Value); copyOfExistingConfigs.Add("RoslynExtensionsOptions:EnableAnalyzersSupport", roslynAnalyzersEnabled.ToString()); + copyOfExistingConfigs.Add("RoslynExtensionsOptions:AnalyzeOpenDocumentsOnly", analyzeOpenDocumentsOnly.ToString()); copyOfExistingConfigs.Add("FormattingOptions:EnableEditorConfigSupport", editorConfigEnabled.ToString()); return copyOfExistingConfigs.ToConfiguration(); From 10947a752b68bf3e3b32e3e5ea978b8c4e2e1ef1 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 14:05:43 -0700 Subject: [PATCH 03/14] Build on .NET 7 SDK. --- build/Packages.props | 2 +- global.json | 2 +- .../AbstractMSBuildTestFixture.cs | 24 ++++++------------- .../ProjectLoadListenerTests.cs | 7 +++++- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/build/Packages.props b/build/Packages.props index 1b95c441b7..3aeac83990 100644 --- a/build/Packages.props +++ b/build/Packages.props @@ -6,7 +6,7 @@ 6.0.0 17.0.0 17.0.0 - 6.1.0 + 6.2.0-preview.2.80 4.2.0-3.22169.1 2.4.1 diff --git a/global.json b/global.json index 5d6044cf02..a6c620aacf 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "6.0.201" + "version": "7.0.100-preview.2.22153.17" } } diff --git a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs index 25cf3744d6..944daf3338 100644 --- a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs +++ b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs @@ -1,9 +1,7 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; 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; @@ -13,10 +11,9 @@ namespace OmniSharp.MSBuild.Tests { - public abstract class AbstractMSBuildTestFixture : AbstractTestFixture, IDisposable + public abstract class AbstractMSBuildTestFixture : AbstractTestFixture { private readonly IAssemblyLoader _assemblyLoader; - private readonly IMSBuildLocator _msbuildLocator; private readonly IAnalyzerAssemblyLoader _analyzerAssemblyLoader; public AbstractMSBuildTestFixture(ITestOutputHelper output) @@ -24,23 +21,16 @@ public AbstractMSBuildTestFixture(ITestOutputHelper output) { _assemblyLoader = new AssemblyLoader(this.LoggerFactory); _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; - _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configuration: 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); - } - - public void Dispose() - { - (_msbuildLocator as IDisposable)?.Dispose(); } - protected OmniSharpTestHost CreateMSBuildTestHost(string path, IEnumerable additionalExports = null, + protected OmniSharpTestHost CreateMSBuildTestHost( + string path, + IEnumerable additionalExports = null, IConfiguration configurationData = null) { var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); - var serviceProvider = TestServiceProvider.Create(this.TestOutput, environment, this.LoggerFactory, _assemblyLoader, _analyzerAssemblyLoader, _msbuildLocator, + using var msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configurationData); + var serviceProvider = TestServiceProvider.Create(this.TestOutput, environment, this.LoggerFactory, _assemblyLoader, _analyzerAssemblyLoader, msbuildLocator, configurationData); return OmniSharpTestHost.Create(serviceProvider, additionalExports); diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 3682f954c9..5736d6921d 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -248,11 +248,16 @@ public async Task The_correct_sdk_version_is_emitted_NET6() [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task The_correct_sdk_version_is_emitted_NET7() { + var configuration = new Dictionary + { + ["sdk:IncludePrereleases"] = bool.TrueString + }.ToConfiguration(); + // Arrange var emitter = new ProjectLoadTestEventEmitter(); using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net70Project"); - using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); + using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory), configuration); Assert.Single(emitter.ReceivedMessages); Assert.Equal(GetHashedFileExtension("7.0.100-preview.2.22153.17"), emitter.ReceivedMessages[0].SdkVersion); } From e9d6683c04183b946414d40ca33cf352b7f4d912 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 14:13:03 -0700 Subject: [PATCH 04/14] Install .NET 7 in CI --- .github/workflows/build.yml | 2 +- .github/workflows/tests-net6.yml | 2 +- .github/workflows/tests.yml | 2 +- .pipelines/init.yml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5a99f6c9f4..a2b9c182af 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,7 +1,7 @@ name: 'Build' env: - DotNetVersion: "6.0.201" + DotNetVersion: "7.0.100-preview.2.22153.17" DotNetVersion2: "3.1.417" NuGetVersion: "5.7.0" MonoVersion: "6.12.0" diff --git a/.github/workflows/tests-net6.yml b/.github/workflows/tests-net6.yml index b70afedece..6c449547f4 100644 --- a/.github/workflows/tests-net6.yml +++ b/.github/workflows/tests-net6.yml @@ -1,7 +1,7 @@ name: 'Tests net6.0' env: - DotNetVersion: "6.0.201" + DotNetVersion: "7.0.100-preview.2.22153.17" DotNetVersion2: "3.1.417" NuGetVersion: "5.7.0" MonoVersion: "6.12.0" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8b927ecf1f..3ca4bb4202 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,7 @@ name: 'Tests' env: - DotNetVersion: "6.0.201" + DotNetVersion: "7.0.100-preview.2.22153.17" DotNetVersion2: "3.1.417" NuGetVersion: "5.7.0" MonoVersion: "6.12.0" diff --git a/.pipelines/init.yml b/.pipelines/init.yml index ff042f98a2..6d25b732d0 100644 --- a/.pipelines/init.yml +++ b/.pipelines/init.yml @@ -1,7 +1,7 @@ parameters: # Configuration: Release Verbosity: Normal - DotNetVersion: "6.0.201" + DotNetVersion: "7.0.100-preview.2.22153.17" DotNetVersion2: "3.1.417" CakeVersion: "1.1.0" NuGetVersion: "5.7.0" From 7b62a5d961a9ba6f0fcd73825c483b373ec7b294 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 14:38:52 -0700 Subject: [PATCH 05/14] Ensure we load the preview SDK during testing. --- .../AbstractMSBuildTestFixture.cs | 31 ++++++++++++++----- .../ProjectLoadListenerTests.cs | 7 +---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs index 944daf3338..37c1cdc6d2 100644 --- a/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs +++ b/tests/OmniSharp.MSBuild.Tests/AbstractMSBuildTestFixture.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Composition.Hosting.Core; using Microsoft.CodeAnalysis; using Microsoft.Extensions.Configuration; @@ -11,9 +12,10 @@ namespace OmniSharp.MSBuild.Tests { - public abstract class AbstractMSBuildTestFixture : AbstractTestFixture + public abstract class AbstractMSBuildTestFixture : AbstractTestFixture, IDisposable { private readonly IAssemblyLoader _assemblyLoader; + private readonly IMSBuildLocator _msbuildLocator; private readonly IAnalyzerAssemblyLoader _analyzerAssemblyLoader; public AbstractMSBuildTestFixture(ITestOutputHelper output) @@ -21,16 +23,31 @@ public AbstractMSBuildTestFixture(ITestOutputHelper output) { _assemblyLoader = new AssemblyLoader(this.LoggerFactory); _analyzerAssemblyLoader = ShadowCopyAnalyzerAssemblyLoader.Instance; + + // Since we can only load MSBuild once into our process we need to include + // prerelease version so that our .NET 7 tests will pass. + var configuration = new Dictionary + { + ["sdk:IncludePrereleases"] = bool.TrueString + }.ToConfiguration(); + + _msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configuration); + + // 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); + } + + public void Dispose() + { + (_msbuildLocator as IDisposable)?.Dispose(); } - protected OmniSharpTestHost CreateMSBuildTestHost( - string path, - IEnumerable additionalExports = null, + protected OmniSharpTestHost CreateMSBuildTestHost(string path, IEnumerable additionalExports = null, IConfiguration configurationData = null) { var environment = new OmniSharpEnvironment(path, logLevel: LogLevel.Trace); - using var msbuildLocator = MSBuildLocator.CreateDefault(this.LoggerFactory, _assemblyLoader, configurationData); - var serviceProvider = TestServiceProvider.Create(this.TestOutput, environment, this.LoggerFactory, _assemblyLoader, _analyzerAssemblyLoader, msbuildLocator, + var serviceProvider = TestServiceProvider.Create(this.TestOutput, environment, this.LoggerFactory, _assemblyLoader, _analyzerAssemblyLoader, _msbuildLocator, configurationData); return OmniSharpTestHost.Create(serviceProvider, additionalExports); diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs index 5736d6921d..3682f954c9 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectLoadListenerTests.cs @@ -248,16 +248,11 @@ public async Task The_correct_sdk_version_is_emitted_NET6() [ConditionalFact(typeof(NonMonoRuntimeOnly))] public async Task The_correct_sdk_version_is_emitted_NET7() { - var configuration = new Dictionary - { - ["sdk:IncludePrereleases"] = bool.TrueString - }.ToConfiguration(); - // Arrange var emitter = new ProjectLoadTestEventEmitter(); using var testProject = await TestAssets.Instance.GetTestProjectAsync("Net70Project"); - using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory), configuration); + using var host = CreateMSBuildTestHost(testProject.Directory, emitter.AsExportDescriptionProvider(LoggerFactory)); Assert.Single(emitter.ReceivedMessages); Assert.Equal(GetHashedFileExtension("7.0.100-preview.2.22153.17"), emitter.ReceivedMessages[0].SdkVersion); } From 26d648fe71d5fed20f676cfaeaadd38edc83c632 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 15:10:58 -0700 Subject: [PATCH 06/14] Allow hosts to run on latest installed runtime. --- src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj | 4 ++++ .../OmniSharp.LanguageServerProtocol.csproj | 4 ++++ src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj b/src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj index 60650470cf..e83ebad30c 100644 --- a/src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj +++ b/src/OmniSharp.Http.Driver/OmniSharp.Http.Driver.csproj @@ -7,6 +7,10 @@ Exe true win7-x64;win7-x86;win10-arm64 + + + 6.0.0-preview.7.21317.1 + LatestMajor diff --git a/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj b/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj index 0021cb9793..643b870a6a 100644 --- a/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj +++ b/src/OmniSharp.LanguageServerProtocol/OmniSharp.LanguageServerProtocol.csproj @@ -6,6 +6,10 @@ OmniSharp.LanguageServerProtocol true win7-x64;win7-x86;win10-arm64 + + + 6.0.0-preview.7.21317.1 + LatestMajor diff --git a/src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj b/src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj index 610f2929cb..58cbd97492 100644 --- a/src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj +++ b/src/OmniSharp.Stdio.Driver/OmniSharp.Stdio.Driver.csproj @@ -7,6 +7,10 @@ Exe true win7-x64;win7-x86;win10-arm64 + + + 6.0.0-preview.7.21317.1 + LatestMajor From 9ad7f5d18fd153bcd83b7687865893c6cc528aee Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 15:24:04 -0700 Subject: [PATCH 07/14] Target test projects to .NET 7.0 so that the test runner will run on correct runtime --- tests/OmniSharp.Cake.Tests/OmniSharp.Cake.Tests.csproj | 2 +- .../OmniSharp.DotNetTest.Tests.csproj | 2 +- tests/OmniSharp.Http.Tests/OmniSharp.Http.Tests.csproj | 2 +- tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj | 2 +- tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj | 2 +- .../OmniSharp.Roslyn.CSharp.Tests.csproj | 2 +- tests/OmniSharp.Script.Tests/OmniSharp.Script.Tests.csproj | 2 +- tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj | 2 +- tests/OmniSharp.Tests/OmniSharp.Tests.csproj | 2 +- tests/TestUtility/TestUtility.csproj | 2 +- 10 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/OmniSharp.Cake.Tests/OmniSharp.Cake.Tests.csproj b/tests/OmniSharp.Cake.Tests/OmniSharp.Cake.Tests.csproj index 189e9dd947..0801957f2d 100644 --- a/tests/OmniSharp.Cake.Tests/OmniSharp.Cake.Tests.csproj +++ b/tests/OmniSharp.Cake.Tests/OmniSharp.Cake.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj index c4f0377231..7e8a7995f9 100644 --- a/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj +++ b/tests/OmniSharp.DotNetTest.Tests/OmniSharp.DotNetTest.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.Http.Tests/OmniSharp.Http.Tests.csproj b/tests/OmniSharp.Http.Tests/OmniSharp.Http.Tests.csproj index c735523e68..9fa69e08b7 100644 --- a/tests/OmniSharp.Http.Tests/OmniSharp.Http.Tests.csproj +++ b/tests/OmniSharp.Http.Tests/OmniSharp.Http.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj index 705ec5db8b..c9684d7c61 100644 --- a/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj +++ b/tests/OmniSharp.Lsp.Tests/OmniSharp.Lsp.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj index 37a3d4d3bd..8d59239a44 100644 --- a/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj +++ b/tests/OmniSharp.MSBuild.Tests/OmniSharp.MSBuild.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true 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 70f171f7d5..248e3855f3 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/OmniSharp.Roslyn.CSharp.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true CS0618 diff --git a/tests/OmniSharp.Script.Tests/OmniSharp.Script.Tests.csproj b/tests/OmniSharp.Script.Tests/OmniSharp.Script.Tests.csproj index e3b2a0740f..b4ae9dee16 100644 --- a/tests/OmniSharp.Script.Tests/OmniSharp.Script.Tests.csproj +++ b/tests/OmniSharp.Script.Tests/OmniSharp.Script.Tests.csproj @@ -1,7 +1,7 @@ - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj index 865ba7a150..016d0f815f 100644 --- a/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj +++ b/tests/OmniSharp.Stdio.Tests/OmniSharp.Stdio.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/OmniSharp.Tests/OmniSharp.Tests.csproj b/tests/OmniSharp.Tests/OmniSharp.Tests.csproj index d30a32ff30..081168a223 100644 --- a/tests/OmniSharp.Tests/OmniSharp.Tests.csproj +++ b/tests/OmniSharp.Tests/OmniSharp.Tests.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU true diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index 7f2fa06c18..306d2ec6f2 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -1,7 +1,7 @@  - net6.0;net472 + net7.0;net472 AnyCPU From f5aec88f2e504461bad4e7b4232712099807ee51 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 15:35:49 -0700 Subject: [PATCH 08/14] Fix test framework version --- build.cake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.cake b/build.cake index ac83ed697a..459b354100 100644 --- a/build.cake +++ b/build.cake @@ -293,7 +293,7 @@ Task("Test") .IsDependentOn("PrepareTestAssets") .Does(() => { - var testTargetFramework = useDotNetTest ? "net6.0" : "net472"; + var testTargetFramework = useDotNetTest ? "net7.0" : "net472"; var testProjects = string.IsNullOrEmpty(testProjectArgument) ? buildPlan.TestProjects : testProjectArgument.Split(','); foreach (var testProject in testProjects) { From 23e9fa139358a6c3a223ee9eca2e6e1def1e88e0 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 16:31:38 -0700 Subject: [PATCH 09/14] Fix Returns_struct_kind test to accept 'Struct' or 'Structure' --- tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs index df1bef0d8e..43a3484cba 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/FindSymbolsFacts.cs @@ -161,7 +161,7 @@ public async Task Returns_struct_kind(string filename) var usages = await FindSymbolsAsync(code, filename); var symbols = usages.QuickFixes.Cast().Select(q => q.Kind); - Assert.Equal("Structure", symbols.First()); + Assert.Contains(symbols.First(), new[] { "Struct", "Structure" }); } [Theory] From 7e67969903e7b9492b9dab5d4ecbf4e5eba5cc76 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 16:33:44 -0700 Subject: [PATCH 10/14] Fix DotNetCliServiceFacts tests --- tests/OmniSharp.Tests/DotNetCliServiceFacts.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs index ea7f86ac3b..b6d1dabe50 100644 --- a/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs +++ b/tests/OmniSharp.Tests/DotNetCliServiceFacts.cs @@ -7,7 +7,7 @@ namespace OmniSharp.Tests { public class DotNetCliServiceFacts : AbstractTestFixture { - private const string DotNetVersion = "6.0.201"; + private const string DotNetVersion = "7.0.100-preview.2.22153.17"; private int Major { get; } private int Minor { get; } private int Patch { get; } From db612fe697bccd53f300552d9fde232b67974db7 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 21:54:56 -0700 Subject: [PATCH 11/14] Update packages and ensure we rollForward to prereleases --- build.cake | 6 ++++-- build/Packages.props | 8 ++++---- omnisharp.json | 3 +++ src/OmniSharp.Http.Driver/app.config | 6 +++--- src/OmniSharp.LanguageServerProtocol/app.config | 6 +++--- src/OmniSharp.Stdio.Driver/app.config | 6 +++--- tests/app.config | 6 +++--- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/build.cake b/build.cake index 459b354100..f8fbc92012 100644 --- a/build.cake +++ b/build.cake @@ -264,7 +264,8 @@ void BuildWithDotNetCli(BuildEnvironment env, string configuration) .WithProperty("PackageVersion", env.VersionInfo.NuGetVersion) .WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer) .WithProperty("FileVersion", env.VersionInfo.AssemblySemVer) - .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion); + .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion) + .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1"); // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. DotNetCoreMSBuild("OmniSharp.sln", settings); } @@ -573,7 +574,8 @@ string PublishBuild(string project, BuildEnvironment env, BuildPlan plan, string .WithProperty("PackageVersion", env.VersionInfo.NuGetVersion) .WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer) .WithProperty("FileVersion", env.VersionInfo.AssemblySemVer) - .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion), + .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion) + .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1"), // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. ToolPath = env.DotNetCommand, WorkingDirectory = env.WorkingDirectory, Verbosity = DotNetCoreVerbosity.Minimal, diff --git a/build/Packages.props b/build/Packages.props index 3aeac83990..6c6a92a618 100644 --- a/build/Packages.props +++ b/build/Packages.props @@ -76,11 +76,11 @@ - + - - - + + + diff --git a/omnisharp.json b/omnisharp.json index cc1b6bd556..adc812a53f 100644 --- a/omnisharp.json +++ b/omnisharp.json @@ -9,5 +9,8 @@ "RoslynExtensionsOptions": { "enableAnalyzersSupport": true, "enableDecompilationSupport": true + }, + "SDK": { + "includePrereleases": true } } diff --git a/src/OmniSharp.Http.Driver/app.config b/src/OmniSharp.Http.Driver/app.config index ea5e74fe57..99a09a4154 100644 --- a/src/OmniSharp.Http.Driver/app.config +++ b/src/OmniSharp.Http.Driver/app.config @@ -52,15 +52,15 @@ - + - + - + diff --git a/src/OmniSharp.LanguageServerProtocol/app.config b/src/OmniSharp.LanguageServerProtocol/app.config index 5642f27c35..b9b8896fa9 100644 --- a/src/OmniSharp.LanguageServerProtocol/app.config +++ b/src/OmniSharp.LanguageServerProtocol/app.config @@ -52,15 +52,15 @@ - + - + - + diff --git a/src/OmniSharp.Stdio.Driver/app.config b/src/OmniSharp.Stdio.Driver/app.config index ea5e74fe57..99a09a4154 100644 --- a/src/OmniSharp.Stdio.Driver/app.config +++ b/src/OmniSharp.Stdio.Driver/app.config @@ -52,15 +52,15 @@ - + - + - + diff --git a/tests/app.config b/tests/app.config index bdbc18b221..7ae31dc872 100644 --- a/tests/app.config +++ b/tests/app.config @@ -36,15 +36,15 @@ - + - + - + From 87729fcd254ffff50cc5f2023afb42e92ae61363 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 22:48:24 -0700 Subject: [PATCH 12/14] Fix app.configs --- src/OmniSharp.Http.Driver/app.config | 2 +- src/OmniSharp.LanguageServerProtocol/app.config | 2 +- src/OmniSharp.Stdio.Driver/app.config | 2 +- tests/app.config | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OmniSharp.Http.Driver/app.config b/src/OmniSharp.Http.Driver/app.config index 99a09a4154..c69ce59989 100644 --- a/src/OmniSharp.Http.Driver/app.config +++ b/src/OmniSharp.Http.Driver/app.config @@ -27,7 +27,7 @@ - + diff --git a/src/OmniSharp.LanguageServerProtocol/app.config b/src/OmniSharp.LanguageServerProtocol/app.config index b9b8896fa9..0f2ad45129 100644 --- a/src/OmniSharp.LanguageServerProtocol/app.config +++ b/src/OmniSharp.LanguageServerProtocol/app.config @@ -27,7 +27,7 @@ - + diff --git a/src/OmniSharp.Stdio.Driver/app.config b/src/OmniSharp.Stdio.Driver/app.config index 99a09a4154..c69ce59989 100644 --- a/src/OmniSharp.Stdio.Driver/app.config +++ b/src/OmniSharp.Stdio.Driver/app.config @@ -27,7 +27,7 @@ - + diff --git a/tests/app.config b/tests/app.config index 7ae31dc872..4927f89978 100644 --- a/tests/app.config +++ b/tests/app.config @@ -27,7 +27,7 @@ - + From 8b324952d610485f4ff098993fef17101f42193e Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Sun, 10 Apr 2022 22:48:52 -0700 Subject: [PATCH 13/14] Add SdkInstanceProvider tests --- .../Providers/SdkInstanceProvider.cs | 38 ++- .../Providers/SdkOverrideInstanceProvider.cs | 42 ++- .../SdkInstanceProviderTests.cs | 255 ++++++++++++++++++ 3 files changed, 307 insertions(+), 28 deletions(-) create mode 100644 tests/OmniSharp.MSBuild.Tests/SdkInstanceProviderTests.cs diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs index 87d9492c76..d55ac47dc6 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs @@ -23,22 +23,15 @@ public override ImmutableArray GetInstances() var includePrerelease = _options?.IncludePrereleases == true; SemanticVersion optionsVersion = null; - if (!string.IsNullOrEmpty(_options?.Version)) + if (!string.IsNullOrEmpty(_options?.Version) && + !TryParseVersion(_options.Version, out optionsVersion, out var errorMessage)) { - if (!SemanticVersion.TryParse(_options.Version, out optionsVersion)) - { - Logger.LogError($"The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is '{optionsVersion}'. Please update your settings and restart OmniSharp."); - return NoInstances; - } - else if (optionsVersion.Major < 6) - { - Logger.LogError($"The Sdk version specified in the OmniSharp settings is not .NET 6 or higher. Configured version is '{optionsVersion}'. Please update your settings and restart OmniSharp."); - return NoInstances; - } + Logger.LogError(errorMessage); + return NoInstances; } var instances = MicrosoftBuildLocator.QueryVisualStudioInstances() - .Where(instance => IncludeSdkInstance(instance, optionsVersion, includePrerelease)) + .Where(instance => IncludeSdkInstance(instance.VisualStudioRootPath, optionsVersion, includePrerelease)) .OrderByDescending(instance => instance.Version) .ToImmutableArray(); @@ -70,10 +63,27 @@ public override ImmutableArray GetInstances() }).ToImmutableArray(); } - public static bool IncludeSdkInstance(VisualStudioInstance instance, SemanticVersion targetVersion, bool includePrerelease) + public static bool TryParseVersion(string versionString, out SemanticVersion version, out string errorMessage) + { + if (!SemanticVersion.TryParse(versionString, out version)) + { + errorMessage = $"The Sdk version specified in the OmniSharp settings was not a valid semantic version. Configured version is '{versionString}'. Please update your settings and restart OmniSharp."; + return false; + } + else if (version.Major < 6) + { + errorMessage = $"The Sdk version specified in the OmniSharp settings is not .NET 6 or higher. Configured version is '{versionString}'. Please update your settings and restart OmniSharp."; + return false; + } + + errorMessage = null; + return true; + } + + public static bool IncludeSdkInstance(string sdkPath, SemanticVersion targetVersion, bool includePrerelease) { // If the path does not have a `.version` file, then do not consider it a valid option. - if (!TryGetSdkVersion(instance.VisualStudioRootPath, out var version)) + if (!TryGetSdkVersion(sdkPath, out var version)) { return false; } diff --git a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs index 025b87a903..a1affb76a6 100644 --- a/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs +++ b/src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOverrideInstanceProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Immutable; using System.IO; +using System.Runtime.InteropServices; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; @@ -23,21 +24,9 @@ public override ImmutableArray GetInstances() return NoInstances; } - if (!File.Exists(_options.Path)) + if (!TryGetVersion(_options.Path, out var pathVersion, out var errorMessage)) { - Logger.LogError($"The Sdk path specified in the OmniSharp settings does not exist. Configured path is '{_options.Path}'. Please update your settings and restart OmniSharp."); - return NoInstances; - } - - if (!SdkInstanceProvider.TryGetSdkVersion(_options.Path, out var pathVersion)) - { - Logger.LogError($"The Sdk path specified in the OmniSharp settings does not appear to be a valid SDK. Configured path is '{_options.Path}'. Please update your settings and restart OmniSharp."); - return NoInstances; - } - - if (pathVersion.Major < 6) - { - Logger.LogError($"The Sdk path specified in the OmniSharp settings is not .NET 6 or higher. Reported version is '{pathVersion}'. Please update your settings and restart OmniSharp."); + Logger.LogError(errorMessage); return NoInstances; } @@ -48,5 +37,30 @@ public override ImmutableArray GetInstances() DiscoveryType.UserOverride, _options?.PropertyOverrides?.ToImmutableDictionary())); } + + public static bool TryGetVersion(string path, out SemanticVersion version, out string errorMessage) + { + if (!Directory.Exists(path)) + { + version = null; + errorMessage = $"The Sdk path specified in the OmniSharp settings does not exist. Configured path is '{path}'. Please update your settings and restart OmniSharp."; + return false; + } + + if (!SdkInstanceProvider.TryGetSdkVersion(path, out version)) + { + errorMessage = $"The Sdk path specified in the OmniSharp settings does not appear to be a valid SDK. Configured path is '{path}'. Please update your settings and restart OmniSharp."; + return false; + } + + if (version.Major < 6) + { + errorMessage = $"The Sdk path specified in the OmniSharp settings is not .NET 6 or higher. Reported version is '{version}'. Please update your settings and restart OmniSharp."; + return false; + } + + errorMessage = null; + return true; + } } } diff --git a/tests/OmniSharp.MSBuild.Tests/SdkInstanceProviderTests.cs b/tests/OmniSharp.MSBuild.Tests/SdkInstanceProviderTests.cs new file mode 100644 index 0000000000..75ff65ca37 --- /dev/null +++ b/tests/OmniSharp.MSBuild.Tests/SdkInstanceProviderTests.cs @@ -0,0 +1,255 @@ +using System.IO; +using OmniSharp.MSBuild.Discovery.Providers; +using TestUtility; +using Xunit; +using Xunit.Abstractions; + +namespace OmniSharp.MSBuild.Tests +{ + public class SdkInstanceProviderTests : AbstractTestFixture + { + public SdkInstanceProviderTests(ITestOutputHelper output) + : base(output) + { + } + + [Fact] + public void VersionString_Malformed_DoesNotParse() + { + var versionString = "This.Is.Not.Valid"; + + var parsed = SdkInstanceProvider.TryParseVersion( + versionString, + out var version, + out var errorMessage); + + Assert.False(parsed); + Assert.NotNull(errorMessage); + } + + [Fact] + public void VersionString_LessThanMinimumVersion_DoesNotParse() + { + var versionString = "5.0.100"; + + var parsed = SdkInstanceProvider.TryParseVersion( + versionString, + out var version, + out var errorMessage); + + Assert.False(parsed); + Assert.NotNull(errorMessage); + } + + [Fact] + public void VersionString_ReleaseVersion_DoesParse() + { + var versionString = "6.0.100"; + + var parsed = SdkInstanceProvider.TryParseVersion( + versionString, + out var version, + out var errorMessage); + + Assert.True(parsed); + Assert.Equal(versionString, version.ToString()); + Assert.Null(errorMessage); + } + + [Fact] + public void VersionString_PreReleaseVersion_DoesParse() + { + var versionString = "7.0.100-preview.2"; + + var parsed = SdkInstanceProvider.TryParseVersion( + versionString, + out var version, + out var errorMessage); + + Assert.True(parsed); + Assert.Equal(versionString, version.ToString()); + Assert.Null(errorMessage); + } + + [Fact] + public void MissingVersionFile_DoNotInclude() + { + var sdkPath = CreateFakeSdkFolder(version: null); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: null, + includePrerelease: false); + + Assert.False(include); + } + + [Fact] + public void ReleaseVersion_Include() + { + var sdkPath = CreateFakeSdkFolder(version: new("6.0.100")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: null, + includePrerelease: false); + + Assert.True(include); + } + + [Fact] + public void ReleaseVersion_DoesNotMatchTargetVersion_DoNotInclude() + { + var sdkPath = CreateFakeSdkFolder(version: new("6.0.100")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: new("6.0.101"), + includePrerelease: false); + + Assert.False(include); + } + + [Fact] + public void ReleaseVersion_MatchesTargetVersion_Include() + { + var sdkPath = CreateFakeSdkFolder(version: new("6.0.101")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: new("6.0.101"), + includePrerelease: false); + + Assert.True(include); + } + + [Fact] + public void PreReleaseVersion_NotIncludesPrereleases_DoNotInclude() + { + var sdkPath = CreateFakeSdkFolder(version: new("7.0.100-preview.2")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: null, + includePrerelease: false); + + Assert.False(include); + } + + [Fact] + public void PreReleaseVersion_IncludesPrereleases_Include() + { + var sdkPath = CreateFakeSdkFolder(version: new("7.0.100-preview.2")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: null, + includePrerelease: true); + + Assert.True(include); + } + + [Fact] + public void PreReleaseVersion_TargetVersionTrumpsIncludePrereleases_Include() + { + var sdkPath = CreateFakeSdkFolder(version: new("7.0.100-preview.2")); + + var include = SdkInstanceProvider.IncludeSdkInstance( + sdkPath, + targetVersion: new("7.0.100-preview.2"), + includePrerelease: false); + + Assert.True(include); + } + + [Fact] + public void SdkPath_PathDoesNotExist_DoesNotGetVersion() + { + var sdkPath = "ThisPathDoesNotExist"; + + var got = SdkOverrideInstanceProvider.TryGetVersion( + sdkPath, + out var version, + out var errorString); + + Assert.False(got); + Assert.NotNull(errorString); + } + + [Fact] + public void SdkPath_VersionFileDoesNotExist_DoesNotGetVersion() + { + var sdkPath = CreateFakeSdkFolder(version: null); + + var got = SdkOverrideInstanceProvider.TryGetVersion( + sdkPath, + out var version, + out var errorString); + + Assert.False(got); + Assert.NotNull(errorString); + } + + [Fact] + public void SdkPath_LessThanMinimumVersion_DoesNotGetVersion() + { + var versionString = "5.0.100"; + var sdkPath = CreateFakeSdkFolder(version: new(versionString)); + + var got = SdkOverrideInstanceProvider.TryGetVersion( + sdkPath, + out var version, + out var errorString); + + Assert.False(got); + Assert.NotNull(errorString); + } + + [Fact] + public void SdkPath_ReleaseVersion_DoesGetVersion() + { + var versionString = "6.0.100"; + var sdkPath = CreateFakeSdkFolder(version: new(versionString)); + + var got = SdkOverrideInstanceProvider.TryGetVersion( + sdkPath, + out var version, + out var errorString); + + Assert.Null(errorString); + Assert.True(got); + Assert.Equal(versionString, version.ToString()); + } + + [Fact] + public void SdkPath_PreReleaseVersion_DoesGetVersion() + { + var versionString = "7.0.100-preview.2"; + var sdkPath = CreateFakeSdkFolder(version: new(versionString)); + + var got = SdkOverrideInstanceProvider.TryGetVersion( + sdkPath, + out var version, + out var errorString); + + Assert.Null(errorString); + Assert.True(got); + Assert.Equal(versionString, version.ToString()); + } + + internal string CreateFakeSdkFolder(SemanticVersion version) + { + var tempFolderPath = TestIO.GetRandomTempFolderPath(); + + if (version is null) + { + return tempFolderPath; + } + + var versionFilePath = Path.Combine(tempFolderPath, ".version"); + File.WriteAllText(versionFilePath, version.ToString()); + + return tempFolderPath; + } + } +} From bdc14cac9562aa2fb7a3f6d4b437eb99ae1eb5b8 Mon Sep 17 00:00:00 2001 From: Joey Robichaud Date: Mon, 11 Apr 2022 11:04:26 -0700 Subject: [PATCH 14/14] Specify RollForward during build and publish. --- build.cake | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.cake b/build.cake index f8fbc92012..110155272e 100644 --- a/build.cake +++ b/build.cake @@ -265,7 +265,8 @@ void BuildWithDotNetCli(BuildEnvironment env, string configuration) .WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer) .WithProperty("FileVersion", env.VersionInfo.AssemblySemVer) .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion) - .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1"); // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. + .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1") // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. + .WithProperty("RollForward", "LatestMajor"); DotNetCoreMSBuild("OmniSharp.sln", settings); } @@ -575,7 +576,8 @@ string PublishBuild(string project, BuildEnvironment env, BuildPlan plan, string .WithProperty("AssemblyVersion", env.VersionInfo.AssemblySemVer) .WithProperty("FileVersion", env.VersionInfo.AssemblySemVer) .WithProperty("InformationalVersion", env.VersionInfo.InformationalVersion) - .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1"), // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. + .WithProperty("RuntimeFrameworkVersion", "6.0.0-preview.7.21317.1") // Set the minimum runtime to a .NET 6 prerelease so that prerelease SDKs will be considered during rollForward. + .WithProperty("RollForward", "LatestMajor"), ToolPath = env.DotNetCommand, WorkingDirectory = env.WorkingDirectory, Verbosity = DotNetCoreVerbosity.Minimal,