Moving version validation to only when a SDK is not overriden. Also adding a validation for the minimum MSBuild version.
This commit is contained in:
parent
808faf154f
commit
75eac0c92b
4 changed files with 106 additions and 22 deletions
|
@ -50,20 +50,34 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
}
|
||||
|
||||
msbuildSdksDir = Path.Combine(netcoreSdkDir, "Sdks");
|
||||
netcoreSdkVersion = new DirectoryInfo(netcoreSdkDir).Name;;
|
||||
}
|
||||
netcoreSdkVersion = new DirectoryInfo(netcoreSdkDir).Name;
|
||||
|
||||
if (!IsNetCoreSDKOveridden(netcoreSdkVersion) &&
|
||||
IsNetCoreSDKSmallerThanTheMinimumVersion(netcoreSdkVersion, sdkReference.MinimumVersion))
|
||||
{
|
||||
return factory.IndicateFailure(
|
||||
new[]
|
||||
{
|
||||
$"Version {netcoreSdkVersion} of the SDK is smaller than the minimum version"
|
||||
+ $" {sdkReference.MinimumVersion} requested. Check that a recent enough .NET Core SDK is"
|
||||
+ " installed, increase the minimum version specified in the project, or increase"
|
||||
+ " the version specified in global.json."
|
||||
});
|
||||
if (IsNetCoreSDKSmallerThanTheMinimumVersion(netcoreSdkVersion, sdkReference.MinimumVersion))
|
||||
{
|
||||
return factory.IndicateFailure(
|
||||
new[]
|
||||
{
|
||||
$"Version {netcoreSdkVersion} of the SDK is smaller than the minimum version"
|
||||
+ $" {sdkReference.MinimumVersion} requested. Check that a recent enough .NET Core SDK is"
|
||||
+ " installed, increase the minimum version specified in the project, or increase"
|
||||
+ " the version specified in global.json."
|
||||
});
|
||||
}
|
||||
|
||||
var minimumMSBuildVersionString =
|
||||
File.ReadAllLines(Path.Combine(netcoreSdkDir, "minimumMSBuildVersion"))[0];
|
||||
var minimumMSBuildVersion = Version.Parse(minimumMSBuildVersionString);
|
||||
if (context.MSBuildVersion.CompareTo(minimumMSBuildVersion) == -1)
|
||||
{
|
||||
return factory.IndicateFailure(
|
||||
new[]
|
||||
{
|
||||
$"Version {netcoreSdkVersion} of the SDK requires at least version {minimumMSBuildVersionString}"
|
||||
+ $" of msbuild. The current available version of msbuild is {context.MSBuildVersion.ToString()}."
|
||||
+ " Change the SDK specified in global.json to an older version that requires the msbuild"
|
||||
+ " version currently available."
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
string msbuildSdkDir = Path.Combine(msbuildSdksDir, sdkReference.Name, "Sdk");
|
||||
|
@ -80,11 +94,6 @@ namespace Microsoft.DotNet.MSBuildSdkResolver
|
|||
return factory.IndicateSuccess(msbuildSdkDir, netcoreSdkVersion);
|
||||
}
|
||||
|
||||
private bool IsNetCoreSDKOveridden(string netcoreSdkVersion)
|
||||
{
|
||||
return netcoreSdkVersion == null;
|
||||
}
|
||||
|
||||
private bool IsNetCoreSDKSmallerThanTheMinimumVersion(string netcoreSdkVersion, string minimumVersion)
|
||||
{
|
||||
FXVersion netCoreSdkFXVersion;
|
||||
|
|
1
src/redist/minimumMSBuildVersion
Normal file
1
src/redist/minimumMSBuildVersion
Normal file
|
@ -0,0 +1 @@
|
|||
15.3.246
|
|
@ -36,6 +36,12 @@
|
|||
<ProjectReference Include="..\tool_nuget\tool_nuget.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="minimumMSBuildVersion">
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PublishAspNetRuntimePackageStore"
|
||||
AfterTargets="CrossgenPublishDir">
|
||||
<ItemGroup>
|
||||
|
|
|
@ -78,6 +78,32 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
|||
+ " specified in the project, or increase the version specified in global.json.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItReturnsNullWhenTheSDKRequiresAHigherVersionOfMSBuildThanTheOneAvailable()
|
||||
{
|
||||
var environment = new TestEnvironment();
|
||||
var expected =
|
||||
environment.CreateSdkDirectory(ProgramFiles.X64, "Some.Test.Sdk", "99.99.99", new Version(2, 0));
|
||||
environment.CreateMuxerAndAddToPath(ProgramFiles.X64);
|
||||
|
||||
var resolver = environment.CreateResolver();
|
||||
var result = (MockResult)resolver.Resolve(
|
||||
new SdkReference("Some.Test.Sdk", null, "99.99.99"),
|
||||
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 99.99.99 of the SDK requires at least version 2.0 of msbuild."
|
||||
+ " The current available version of msbuild is 1.0. Change the SDK specified in global.json to an older"
|
||||
+ " version that requires the msbuild version currently available.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ItReturnsTheVersionIfItIsEqualToTheMinVersion()
|
||||
{
|
||||
|
@ -147,27 +173,63 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
|||
=> new DotNetMSBuildSdkResolver(GetEnvironmentVariable);
|
||||
|
||||
public DirectoryInfo GetSdkDirectory(ProgramFiles programFiles, string sdkName, string sdkVersion)
|
||||
=> TestDirectory.GetDirectory(GetProgramFilesDirectory(programFiles).FullName, "dotnet", "sdk", sdkVersion, "Sdks", sdkName, "Sdk");
|
||||
=> TestDirectory.GetDirectory(
|
||||
GetProgramFilesDirectory(programFiles).FullName,
|
||||
"dotnet",
|
||||
"sdk",
|
||||
sdkVersion,
|
||||
"Sdks",
|
||||
sdkName,
|
||||
"Sdk");
|
||||
|
||||
public DirectoryInfo GetProgramFilesDirectory(ProgramFiles programFiles)
|
||||
=> TestDirectory.GetDirectory($"ProgramFiles{programFiles}");
|
||||
|
||||
public DirectoryInfo CreateSdkDirectory(ProgramFiles programFiles, string sdkVersion, string sdkName)
|
||||
public DirectoryInfo CreateSdkDirectory(
|
||||
ProgramFiles programFiles,
|
||||
string sdkName,
|
||||
string sdkVersion,
|
||||
Version minimumMSBuildVersion = null)
|
||||
{
|
||||
var dir = GetSdkDirectory(programFiles, sdkVersion, sdkName);
|
||||
var dir = GetSdkDirectory(programFiles, sdkName, sdkVersion);
|
||||
dir.Create();
|
||||
|
||||
CreateMSBuildRequiredVersionFile(programFiles, sdkVersion, minimumMSBuildVersion);
|
||||
|
||||
return dir;
|
||||
}
|
||||
|
||||
public void CreateMuxerAndAddToPath(ProgramFiles programFiles)
|
||||
{
|
||||
var muxerDirectory = TestDirectory.GetDirectory(GetProgramFilesDirectory(programFiles).FullName, "dotnet");
|
||||
var muxerDirectory =
|
||||
TestDirectory.GetDirectory(GetProgramFilesDirectory(programFiles).FullName, "dotnet");
|
||||
|
||||
new FileInfo(Path.Combine(muxerDirectory.FullName, Muxer)).Create();
|
||||
|
||||
PathEnvironmentVariable = $"{muxerDirectory}{Path.PathSeparator}{PathEnvironmentVariable}";
|
||||
}
|
||||
|
||||
private void CreateMSBuildRequiredVersionFile(
|
||||
ProgramFiles programFiles,
|
||||
string sdkVersion,
|
||||
Version minimumMSBuildVersion)
|
||||
{
|
||||
if (minimumMSBuildVersion == null)
|
||||
{
|
||||
minimumMSBuildVersion = new Version(1, 0);
|
||||
}
|
||||
|
||||
var cliDirectory = TestDirectory.GetDirectory(
|
||||
GetProgramFilesDirectory(programFiles).FullName,
|
||||
"dotnet",
|
||||
"sdk",
|
||||
sdkVersion);
|
||||
|
||||
File.WriteAllText(
|
||||
Path.Combine(cliDirectory.FullName, "minimumMSBuildVersion"),
|
||||
minimumMSBuildVersion.ToString());
|
||||
}
|
||||
|
||||
public void CreateGlobalJson(DirectoryInfo directory, string version)
|
||||
=> File.WriteAllText(directory.GetFile("global.json").FullName,
|
||||
$@"{{ ""sdk"": {{ ""version"": ""{version}"" }} }}");
|
||||
|
@ -188,6 +250,12 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
|
|||
{
|
||||
public new string ProjectFilePath { get => base.ProjectFilePath; set => base.ProjectFilePath = value; }
|
||||
public new string SolutionFilePath { get => base.SolutionFilePath; set => base.SolutionFilePath = value; }
|
||||
public new Version MSBuildVersion { get => base.MSBuildVersion; set => base.MSBuildVersion = value; }
|
||||
|
||||
public MockContext()
|
||||
{
|
||||
MSBuildVersion = new Version(1, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class MockFactory : SdkResultFactory
|
||||
|
|
Loading…
Reference in a new issue