Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .NET 7 SDKs #2377

Merged
merged 14 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests-net6.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 1 addition & 1 deletion .pipelines/init.yml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
8 changes: 5 additions & 3 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -293,7 +294,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)
{
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion build.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions build/Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<MicrosoftExtensionPackageVersion>6.0.0</MicrosoftExtensionPackageVersion>
<MicrosoftTestPackageVersion>17.0.0</MicrosoftTestPackageVersion>
<MSBuildPackageVersion>17.0.0</MSBuildPackageVersion>
<NuGetPackageVersion>6.1.0</NuGetPackageVersion>
<NuGetPackageVersion>6.2.0-preview.2.80</NuGetPackageVersion>
<RoslynPackageVersion>4.2.0-3.22169.1</RoslynPackageVersion>
<XunitPackageVersion>2.4.1</XunitPackageVersion>
</PropertyGroup>
Expand Down Expand Up @@ -76,11 +76,11 @@
<PackageReference Update="OmniSharp.Extensions.LanguageProtocol.Testing" Version="0.19.0" />

<PackageReference Update="SQLitePCLRaw.bundle_green" Version="2.0.7" />
<PackageReference Update="System.Collections.Immutable" Version="5.0.0" />
<PackageReference Update="System.Collections.Immutable" Version="6.0.0" />
<PackageReference Update="System.ComponentModel.Composition" Version="4.5.0" />
<PackageReference Update="System.Composition" Version="1.0.31" />
<PackageReference Update="System.Reflection.Metadata" Version="5.0.0" />
<PackageReference Update="System.Threading.Tasks.Dataflow" Version="5.0.0" />
<PackageReference Update="System.Composition" Version="6.0.0" />
<PackageReference Update="System.Reflection.Metadata" Version="6.0.0" />
<PackageReference Update="System.Threading.Tasks.Dataflow" Version="6.0.0" />
<PackageReference Update="System.ValueTuple" Version="4.5.0" />

<PackageReference Update="System.Reactive" Version="4.4.1" />
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "6.0.201"
"version": "7.0.100-preview.2.22153.17"
}
}
3 changes: 3 additions & 0 deletions omnisharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@
"RoslynExtensionsOptions": {
"enableAnalyzersSupport": true,
"enableDecompilationSupport": true
},
"SDK": {
"includePrereleases": true
}
}
2 changes: 1 addition & 1 deletion src/OmniSharp.Host/CompositionHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static IServiceProvider CreateDefaultServiceProvider(
MSBuildLocator.CreateDefault(
loggerFactory: sp.GetService<ILoggerFactory>(),
assemblyLoader: sp.GetService<IAssemblyLoader>(),
msbuildConfiguration: configuration.GetSection("msbuild")));
configuration: configuration));

services.AddLogging(builder =>
{
Expand Down
14 changes: 11 additions & 3 deletions src/OmniSharp.Host/MSBuild/Discovery/MSBuildLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,30 @@ 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<bool>("UseBundledOnly") ?? false;
if (useBundledOnly)
{
var logger = loggerFactory.CreateLogger<MSBuildLocator>();
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<MSBuildInstanceProvider>(
new SdkInstanceProvider(loggerFactory, sdkConfiguration),
new SdkOverrideInstanceProvider(loggerFactory, sdkConfiguration)));
#else
return new MSBuildLocator(loggerFactory, assemblyLoader,
ImmutableArray.Create<MSBuildInstanceProvider>(
new MicrosoftBuildLocatorInstanceProvider(loggerFactory),
#if !NETCOREAPP
new MonoInstanceProvider(loggerFactory),
#endif
new UserOverrideInstanceProvider(loggerFactory, msbuildConfiguration)));
#endif
}

public void RegisterInstance(MSBuildInstance instance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -20,46 +18,30 @@ public MicrosoftBuildLocatorInstanceProvider(ILoggerFactory loggerFactory)

public override ImmutableArray<MSBuildInstance> 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)
{
return discoveryType switch
{
MicrosoftDiscoveryType.DeveloperConsole => DiscoveryType.DeveloperConsole,
MicrosoftDiscoveryType.VisualStudioSetup => DiscoveryType.VisualStudioSetup,
MicrosoftDiscoveryType.DotNetSdk => DiscoveryType.DotNetSdk,
_ => throw new ArgumentException()
};
}
Expand Down
130 changes: 130 additions & 0 deletions src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkInstanceProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
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<SdkOptions>();
}

public override ImmutableArray<MSBuildInstance> GetInstances()
{
var includePrerelease = _options?.IncludePrereleases == true;

SemanticVersion optionsVersion = null;
if (!string.IsNullOrEmpty(_options?.Version) &&
!TryParseVersion(_options.Version, out optionsVersion, out var errorMessage))
{
Logger.LogError(errorMessage);
return NoInstances;
}

var instances = MicrosoftBuildLocator.QueryVisualStudioInstances()
.Where(instance => IncludeSdkInstance(instance.VisualStudioRootPath, 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 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(sdkPath, 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;
}
}
}
15 changes: 15 additions & 0 deletions src/OmniSharp.Host/MSBuild/Discovery/Providers/SdkOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.Collections.Generic;

namespace OmniSharp.MSBuild.Discovery.Providers
{
internal class SdkOptions
{
public Dictionary<string, string> PropertyOverrides { get; set; }

public string Path { get; set; }

public string Version { get; set; }

public bool IncludePrereleases { get; set; }
}
}
Loading