2020-05-06 14:59:23 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2018-06-21 17:40:44 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using NuGet.ProjectModel;
|
|
|
|
|
using NuGet.Versioning;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace EndToEnd
|
|
|
|
|
{
|
|
|
|
|
public class GivenFrameworkDependentApps : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
|
|
|
|
[ClassData(typeof(SupportedNetCoreAppVersions))]
|
2018-09-27 01:54:17 +00:00
|
|
|
|
public void ItDoesNotRollForwardToTheLatestVersionOfNetCore(string minorVersion)
|
|
|
|
|
{
|
2022-01-13 20:36:52 +00:00
|
|
|
|
if (minorVersion == "3.0" || minorVersion == "3.1" || minorVersion == "5.0" || minorVersion == "6.0" || minorVersion == "7.0")
|
2019-02-21 00:29:03 +00:00
|
|
|
|
{
|
|
|
|
|
// https://github.com/dotnet/core-sdk/issues/621
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-08 20:11:30 +00:00
|
|
|
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.NETCorePackageName, minorVersion);
|
2018-09-27 01:54:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 20:11:30 +00:00
|
|
|
|
[Theory]
|
2018-09-27 01:54:17 +00:00
|
|
|
|
[ClassData(typeof(SupportedAspNetCoreVersions))]
|
|
|
|
|
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVersion)
|
|
|
|
|
{
|
2022-01-13 20:36:52 +00:00
|
|
|
|
if (minorVersion == "3.0" || minorVersion == "3.1" || minorVersion == "5.0" || minorVersion == "6.0" || minorVersion == "7.0")
|
2019-02-21 00:29:03 +00:00
|
|
|
|
{
|
|
|
|
|
// https://github.com/dotnet/core-sdk/issues/621
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-11-08 20:11:30 +00:00
|
|
|
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
|
2018-09-27 01:54:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-11-08 20:11:30 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[ClassData(typeof(SupportedAspNetCoreAllVersions))]
|
2018-09-27 01:54:17 +00:00
|
|
|
|
public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll(string minorVersion)
|
|
|
|
|
{
|
2018-11-08 20:11:30 +00:00
|
|
|
|
ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
|
2018-09-27 01:54:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-23 02:59:58 +00:00
|
|
|
|
internal void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
|
2018-06-21 17:40:44 +00:00
|
|
|
|
{
|
2022-10-18 16:50:01 +00:00
|
|
|
|
// https://github.com/NuGet/Home/issues/8571
|
|
|
|
|
#if LINUX_PORTABLE
|
|
|
|
|
return;
|
2022-10-19 18:02:33 +00:00
|
|
|
|
#else
|
|
|
|
|
var testProjectCreator = new TestProjectCreator()
|
|
|
|
|
{
|
|
|
|
|
PackageName = packageName,
|
|
|
|
|
MinorVersion = minorVersion,
|
|
|
|
|
};
|
2018-11-08 20:11:30 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
var _testInstance = testProjectCreator.Create();
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
string projectDirectory = _testInstance.Root.FullName;
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
// Get the resolved version of .NET Core
|
|
|
|
|
new RestoreCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should().Pass();
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
|
|
|
|
|
var assetsFile = new LockFileFormat().Read(assetsFilePath);
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
var versionInAssertsJson = GetPackageVersion(assetsFile, packageName);
|
|
|
|
|
versionInAssertsJson.Should().NotBeNull();
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
if (versionInAssertsJson.IsPrerelease && versionInAssertsJson.Patch == 0)
|
|
|
|
|
{
|
|
|
|
|
// if the bundled version is, for example, a prerelease of
|
|
|
|
|
// .NET Core 2.1.1, that we don't roll forward to that prerelease
|
|
|
|
|
// version for framework-dependent deployments.
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-21 17:40:44 +00:00
|
|
|
|
|
2022-10-19 18:02:33 +00:00
|
|
|
|
versionInAssertsJson.ToNormalizedString().Should().BeEquivalentTo(GetExpectedVersion(packageName, minorVersion));
|
|
|
|
|
#endif
|
2018-06-21 17:40:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 01:54:17 +00:00
|
|
|
|
private static NuGetVersion GetPackageVersion(LockFile lockFile, string packageName)
|
2018-06-21 17:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
return lockFile?.Targets?.SingleOrDefault(t => t.RuntimeIdentifier == null)
|
|
|
|
|
?.Libraries?.SingleOrDefault(l =>
|
2018-09-27 01:54:17 +00:00
|
|
|
|
string.Compare(l.Name, packageName, StringComparison.CurrentCultureIgnoreCase) == 0)
|
2018-06-21 17:40:44 +00:00
|
|
|
|
?.Version;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-27 01:54:17 +00:00
|
|
|
|
public string GetExpectedVersion(string packageName, string minorVersion)
|
2018-06-21 17:40:44 +00:00
|
|
|
|
{
|
|
|
|
|
if (minorVersion.StartsWith("1.0"))
|
|
|
|
|
{
|
|
|
|
|
return "1.0.5"; // special case for 1.0
|
|
|
|
|
}
|
|
|
|
|
else if (minorVersion.StartsWith("1.1"))
|
|
|
|
|
{
|
|
|
|
|
return "1.1.2"; // special case for 1.1
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2018-09-27 01:54:17 +00:00
|
|
|
|
// ASP.NET 2.1.0 packages had exact version dependencies, which was problematic,
|
|
|
|
|
// so the default version for 2.1 apps is 2.1.1.
|
2018-11-08 20:11:30 +00:00
|
|
|
|
if (packageName == TestProjectCreator.AspNetCoreAppPackageName ||
|
|
|
|
|
packageName == TestProjectCreator.AspNetCoreAllPackageName)
|
2018-09-27 01:54:17 +00:00
|
|
|
|
{
|
|
|
|
|
if (minorVersion == "2.1")
|
|
|
|
|
{
|
|
|
|
|
return "2.1.1";
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-21 17:40:44 +00:00
|
|
|
|
var parsed = NuGetVersion.Parse(minorVersion);
|
|
|
|
|
return new NuGetVersion(parsed.Major, parsed.Minor, 0).ToNormalizedString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|