Merge pull request #6701 from nguerrera/resolver-fix

Allow resolution of SDKs without minimum msbuild version file
This commit is contained in:
Livar 2017-05-27 10:02:56 -07:00 committed by GitHub
commit 5a47e7db07
2 changed files with 22 additions and 5 deletions

View file

@ -5,6 +5,7 @@ using Microsoft.Build.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Microsoft.DotNet.MSBuildSdkResolver
{
@ -63,9 +64,7 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
+ " the version specified in global.json."
});
}
var minimumMSBuildVersionString =
File.ReadAllLines(Path.Combine(netcoreSdkDir, "minimumMSBuildVersion"))[0];
string minimumMSBuildVersionString = GetMinimumMSBuildVersion(netcoreSdkDir);
var minimumMSBuildVersion = Version.Parse(minimumMSBuildVersionString);
if (context.MSBuildVersion < minimumMSBuildVersion)
{
@ -94,6 +93,20 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
return factory.IndicateSuccess(msbuildSdkDir, netcoreSdkVersion);
}
private static string GetMinimumMSBuildVersion(string netcoreSdkDir)
{
string minimumVersionFilePath = Path.Combine(netcoreSdkDir, "minimumMSBuildVersion");
if (!File.Exists(minimumVersionFilePath))
{
// smallest version that had resolver support and also
// greater than or equal to the version required by any
// .NET Core SDK that did not have this file.
return "15.3.0";
}
return File.ReadLines(minimumVersionFilePath).First().Trim();
}
private bool IsNetCoreSDKSmallerThanTheMinimumVersion(string netcoreSdkVersion, string minimumVersion)
{
FXVersion netCoreSdkFXVersion;

View file

@ -91,6 +91,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
new SdkReference("Some.Test.Sdk", null, "99.99.99"),
new MockContext
{
MSBuildVersion = new Version(1, 0),
ProjectFilePath = environment.TestDirectory.FullName
},
new MockFactory());
@ -194,7 +195,10 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
var dir = GetSdkDirectory(programFiles, sdkName, sdkVersion);
dir.Create();
CreateMSBuildRequiredVersionFile(programFiles, sdkVersion, minimumMSBuildVersion);
if (minimumMSBuildVersion != null)
{
CreateMSBuildRequiredVersionFile(programFiles, sdkVersion, minimumMSBuildVersion);
}
return dir;
}
@ -254,7 +258,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
public MockContext()
{
MSBuildVersion = new Version(1, 0);
MSBuildVersion = new Version(15, 3, 0);
}
}