Merge pull request #7077 from livarcocc/min_sdk_resolver
Adding a Minimum VS Defined SDK version to the resolver.
This commit is contained in:
commit
7c9307dcbe
4 changed files with 107 additions and 8 deletions
|
@ -2,10 +2,10 @@
|
||||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
// NOTE: Currently, only the NET46 build ships (with Visual Studio/desktop msbuild),
|
// NOTE: Currently, only the NET46 build ships (with Visual Studio/desktop msbuild),
|
||||||
// but the netstandard1.3 adaptation here acts a proof-of-concept for cross-platform
|
// but the netstandard1.5 adaptation here acts a proof-of-concept for cross-platform
|
||||||
// portability of the underlying hostfxr API and gives us build and test coverage
|
// portability of the underlying hostfxr API and gives us build and test coverage
|
||||||
// on non-Windows machines.
|
// on non-Windows machines.
|
||||||
#if NETSTANDARD1_3
|
#if NETSTANDARD1_5
|
||||||
|
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
@ -34,4 +34,4 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NETSTANDARD1_3
|
#endif // NETSTANDARD1_5
|
|
@ -6,6 +6,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.MSBuildSdkResolver
|
namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
{
|
{
|
||||||
|
@ -64,6 +65,7 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
+ " the version specified in global.json."
|
+ " the version specified in global.json."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
string minimumMSBuildVersionString = GetMinimumMSBuildVersion(netcoreSdkDir);
|
string minimumMSBuildVersionString = GetMinimumMSBuildVersion(netcoreSdkDir);
|
||||||
var minimumMSBuildVersion = Version.Parse(minimumMSBuildVersionString);
|
var minimumMSBuildVersion = Version.Parse(minimumMSBuildVersionString);
|
||||||
if (context.MSBuildVersion < minimumMSBuildVersion)
|
if (context.MSBuildVersion < minimumMSBuildVersion)
|
||||||
|
@ -77,6 +79,18 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
+ " version currently available."
|
+ " version currently available."
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string minimumVSDefinedSDKVersion = GetMinimumVSDefinedSDKVersion();
|
||||||
|
if (IsNetCoreSDKSmallerThanTheMinimumVersion(netcoreSdkVersion, minimumVSDefinedSDKVersion))
|
||||||
|
{
|
||||||
|
return factory.IndicateFailure(
|
||||||
|
new[]
|
||||||
|
{
|
||||||
|
$"Version {netcoreSdkVersion} of the .NET Core SDK is smaller than the minimum version"
|
||||||
|
+ $" {minimumVSDefinedSDKVersion} required by Visual Studio. Check that a recent enough"
|
||||||
|
+ " .NET Core SDK is installed or increase the version specified in global.json."
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
string msbuildSdkDir = Path.Combine(msbuildSdksDir, sdkReference.Name, "Sdk");
|
string msbuildSdkDir = Path.Combine(msbuildSdksDir, sdkReference.Name, "Sdk");
|
||||||
|
@ -107,6 +121,22 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
||||||
return File.ReadLines(minimumVersionFilePath).First().Trim();
|
return File.ReadLines(minimumVersionFilePath).First().Trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string GetMinimumVSDefinedSDKVersion()
|
||||||
|
{
|
||||||
|
string dotnetMSBuildSdkResolverDirectory =
|
||||||
|
Path.GetDirectoryName(typeof(DotNetMSBuildSdkResolver).GetTypeInfo().Assembly.Location);
|
||||||
|
string minimumVSDefinedSdkVersionFilePath =
|
||||||
|
Path.Combine(dotnetMSBuildSdkResolverDirectory, "minimumVSDefinedSDKVersion");
|
||||||
|
|
||||||
|
if (!File.Exists(minimumVSDefinedSdkVersionFilePath))
|
||||||
|
{
|
||||||
|
// smallest version that is required by VS 15.3.
|
||||||
|
return "1.0.4";
|
||||||
|
}
|
||||||
|
|
||||||
|
return File.ReadLines(minimumVSDefinedSdkVersionFilePath).First().Trim();
|
||||||
|
}
|
||||||
|
|
||||||
private bool IsNetCoreSDKSmallerThanTheMinimumVersion(string netcoreSdkVersion, string minimumVersion)
|
private bool IsNetCoreSDKSmallerThanTheMinimumVersion(string netcoreSdkVersion, string minimumVersion)
|
||||||
{
|
{
|
||||||
FXVersion netCoreSdkFXVersion;
|
FXVersion netCoreSdkFXVersion;
|
||||||
|
|
|
@ -3,8 +3,8 @@
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Version>$(SdkVersion)</Version>
|
<Version>$(SdkVersion)</Version>
|
||||||
<TargetFrameworks>netstandard1.3;net46</TargetFrameworks>
|
<TargetFrameworks>netstandard1.5;net46</TargetFrameworks>
|
||||||
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.3</TargetFrameworks>
|
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">netstandard1.5</TargetFrameworks>
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
|
<RuntimeIdentifiers>win-x86;win-x64</RuntimeIdentifiers>
|
||||||
<WarningsAsErrors>true</WarningsAsErrors>
|
<WarningsAsErrors>true</WarningsAsErrors>
|
||||||
|
@ -20,7 +20,7 @@
|
||||||
<PackageReference Include="Microsoft.NETCore.DotNetHostResolver" Version="$(CLI_SharedFrameworkVersion)" PrivateAssets="All" />
|
<PackageReference Include="Microsoft.NETCore.DotNetHostResolver" Version="$(CLI_SharedFrameworkVersion)" PrivateAssets="All" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.3'">
|
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard1.5'">
|
||||||
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
<PackageReference Include="NETStandard.Library" Version="1.6.0" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,8 @@ using Xunit;
|
||||||
using Xunit.Abstractions;
|
using Xunit.Abstractions;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
|
[assembly: CollectionBehavior(DisableTestParallelization = true)]
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli.Utils.Tests
|
namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
{
|
{
|
||||||
public class GivenAnMSBuildSdkResolver : TestBase
|
public class GivenAnMSBuildSdkResolver : TestBase
|
||||||
|
@ -106,11 +108,59 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItReturnsTheVersionIfItIsEqualToTheMinVersion()
|
public void ItReturnsNullWhenTheDefaultVSRequiredSDKVersionIsHigherThanTheSDKVersionAvailable()
|
||||||
|
{
|
||||||
|
var environment = new TestEnvironment();
|
||||||
|
var expected =
|
||||||
|
environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "1.0.1");
|
||||||
|
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
||||||
|
|
||||||
|
var resolver = environment.CreateResolver();
|
||||||
|
var result = (MockResult)resolver.Resolve(
|
||||||
|
new SdkReference("Some.Test.Sdk", null, "1.0.0"),
|
||||||
|
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
|
||||||
|
new MockFactory());
|
||||||
|
|
||||||
|
result.Success.Should().BeFalse();
|
||||||
|
result.Path.Should().BeNull();
|
||||||
|
result.Version.Should().BeNull();
|
||||||
|
result.Warnings.Should().BeNullOrEmpty();
|
||||||
|
result.Errors.Should().Contain($"Version 1.0.1 of the .NET Core SDK is smaller than the minimum version"
|
||||||
|
+ " 1.0.4 required by Visual Studio. Check that a recent enough"
|
||||||
|
+ " .NET Core SDK is installed or increase the version specified in global.json.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItReturnsNullWhenTheTheVSRequiredSDKVersionIsHigherThanTheSDKVersionAvailable()
|
||||||
|
{
|
||||||
|
var environment = new TestEnvironment();
|
||||||
|
var expected =
|
||||||
|
environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "1.0.1");
|
||||||
|
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
||||||
|
environment.CreateMinimumVSDefinedSDKVersionFile("2.0.0");
|
||||||
|
|
||||||
|
var resolver = environment.CreateResolver();
|
||||||
|
var result = (MockResult)resolver.Resolve(
|
||||||
|
new SdkReference("Some.Test.Sdk", null, "1.0.0"),
|
||||||
|
new MockContext { ProjectFilePath = environment.TestDirectory.FullName },
|
||||||
|
new MockFactory());
|
||||||
|
|
||||||
|
result.Success.Should().BeFalse();
|
||||||
|
result.Path.Should().BeNull();
|
||||||
|
result.Version.Should().BeNull();
|
||||||
|
result.Warnings.Should().BeNullOrEmpty();
|
||||||
|
result.Errors.Should().Contain($"Version 1.0.1 of the .NET Core SDK is smaller than the minimum version"
|
||||||
|
+ " 2.0.0 required by Visual Studio. Check that a recent enough"
|
||||||
|
+ " .NET Core SDK is installed or increase the version specified in global.json.");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItReturnsTheVersionIfItIsEqualToTheMinVersionAndTheVSDefinedMinVersion()
|
||||||
{
|
{
|
||||||
var environment = new TestEnvironment();
|
var environment = new TestEnvironment();
|
||||||
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99");
|
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99");
|
||||||
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
||||||
|
environment.CreateMinimumVSDefinedSDKVersionFile("99.99.99");
|
||||||
|
|
||||||
var resolver = environment.CreateResolver();
|
var resolver = environment.CreateResolver();
|
||||||
var result = (MockResult)resolver.Resolve(
|
var result = (MockResult)resolver.Resolve(
|
||||||
|
@ -126,11 +176,12 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void ItReturnsTheVersionIfItIsHigherThanTheMinVersion()
|
public void ItReturnsTheVersionIfItIsHigherThanTheMinVersionAndTheVSDefinedMinVersion()
|
||||||
{
|
{
|
||||||
var environment = new TestEnvironment();
|
var environment = new TestEnvironment();
|
||||||
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "999.99.99");
|
var expected = environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "999.99.99");
|
||||||
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
||||||
|
environment.CreateMinimumVSDefinedSDKVersionFile("999.99.98");
|
||||||
|
|
||||||
var resolver = environment.CreateResolver();
|
var resolver = environment.CreateResolver();
|
||||||
var result = (MockResult)resolver.Resolve(
|
var result = (MockResult)resolver.Resolve(
|
||||||
|
@ -167,6 +218,8 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
identifier: identifier,
|
identifier: identifier,
|
||||||
callingMethod: callingMethod);
|
callingMethod: callingMethod);
|
||||||
|
|
||||||
|
DeleteMinimumVSDefinedSDKVersionFile();
|
||||||
|
|
||||||
PathEnvironmentVariable = string.Empty;
|
PathEnvironmentVariable = string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -248,6 +301,22 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void CreateMinimumVSDefinedSDKVersionFile(string version)
|
||||||
|
{
|
||||||
|
File.WriteAllText(GetMinimumVSDefinedSDKVersionFilePath(), version);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DeleteMinimumVSDefinedSDKVersionFile()
|
||||||
|
{
|
||||||
|
File.Delete(GetMinimumVSDefinedSDKVersionFilePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private string GetMinimumVSDefinedSDKVersionFilePath()
|
||||||
|
{
|
||||||
|
string baseDirectory = AppContext.BaseDirectory;
|
||||||
|
return Path.Combine(baseDirectory, "minimumVSDefinedSDKVersion");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class MockContext : SdkResolverContext
|
private sealed class MockContext : SdkResolverContext
|
||||||
|
|
Loading…
Add table
Reference in a new issue