GivenFrameworkDependentApps.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // Copyright (c) .NET Foundation and contributors. All rights reserved.
  2. // Licensed under the MIT license. See LICENSE file in the project root for full license information.
  3. using NuGet.ProjectModel;
  4. using NuGet.Versioning;
  5. using RestoreCommand = Microsoft.DotNet.Tools.Test.Utilities.RestoreCommand;
  6. using TestBase = Microsoft.DotNet.Tools.Test.Utilities.TestBase;
  7. using static Microsoft.DotNet.Tools.Test.Utilities.TestCommandExtensions;
  8. namespace EndToEnd
  9. {
  10. public class GivenFrameworkDependentApps : TestBase
  11. {
  12. [Theory]
  13. [ClassData(typeof(SupportedNetCoreAppVersions))]
  14. public void ItDoesNotRollForwardToTheLatestVersionOfNetCore(string minorVersion)
  15. {
  16. if (minorVersion == "3.0" || minorVersion == "3.1" || minorVersion == "5.0" || minorVersion == "6.0" || minorVersion == "7.0" || minorVersion == "8.0" || minorVersion == "9.0")
  17. {
  18. // https://github.com/dotnet/core-sdk/issues/621
  19. return;
  20. }
  21. ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.NETCorePackageName, minorVersion);
  22. }
  23. [Theory]
  24. [ClassData(typeof(SupportedAspNetCoreVersions))]
  25. public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreApp(string minorVersion)
  26. {
  27. if (minorVersion == "3.0" || minorVersion == "3.1" || minorVersion == "5.0" || minorVersion == "6.0" || minorVersion == "7.0" || minorVersion == "8.0" || minorVersion == "9.0")
  28. {
  29. // https://github.com/dotnet/core-sdk/issues/621
  30. return;
  31. }
  32. ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAppPackageName, minorVersion);
  33. }
  34. [Theory]
  35. [ClassData(typeof(SupportedAspNetCoreAllVersions))]
  36. public void ItDoesNotRollForwardToTheLatestVersionOfAspNetCoreAll(string minorVersion) => ItDoesNotRollForwardToTheLatestVersion(TestProjectCreator.AspNetCoreAllPackageName, minorVersion);
  37. internal void ItDoesNotRollForwardToTheLatestVersion(string packageName, string minorVersion)
  38. {
  39. // https://github.com/NuGet/Home/issues/8571
  40. #if LINUX_PORTABLE
  41. return;
  42. #else
  43. var testProjectCreator = new TestProjectCreator()
  44. {
  45. PackageName = packageName,
  46. MinorVersion = minorVersion,
  47. };
  48. var _testInstance = testProjectCreator.Create();
  49. string projectDirectory = _testInstance.Root.FullName;
  50. string projectPath = Path.Combine(projectDirectory, "TestAppSimple.csproj");
  51. // Get the resolved version of .NET Core
  52. new RestoreCommand()
  53. .WithWorkingDirectory(projectDirectory)
  54. .Execute().Should().Pass();
  55. string assetsFilePath = Path.Combine(projectDirectory, "obj", "project.assets.json");
  56. var assetsFile = new LockFileFormat().Read(assetsFilePath);
  57. var versionInAssertsJson = GetPackageVersion(assetsFile, packageName);
  58. versionInAssertsJson.Should().NotBeNull();
  59. if (versionInAssertsJson.IsPrerelease && versionInAssertsJson.Patch == 0)
  60. {
  61. // if the bundled version is, for example, a prerelease of
  62. // .NET Core 2.1.1, that we don't roll forward to that prerelease
  63. // version for framework-dependent deployments.
  64. return;
  65. }
  66. versionInAssertsJson.ToNormalizedString().Should().BeEquivalentTo(GetExpectedVersion(packageName, minorVersion));
  67. #endif
  68. }
  69. private static NuGetVersion GetPackageVersion(LockFile lockFile, string packageName) => lockFile?.Targets?.SingleOrDefault(t => t.RuntimeIdentifier == null)
  70. ?.Libraries?.SingleOrDefault(l =>
  71. string.Compare(l.Name, packageName, StringComparison.CurrentCultureIgnoreCase) == 0)
  72. ?.Version;
  73. public string GetExpectedVersion(string packageName, string minorVersion)
  74. {
  75. if (minorVersion.StartsWith("1.0"))
  76. {
  77. return "1.0.5"; // special case for 1.0
  78. }
  79. else if (minorVersion.StartsWith("1.1"))
  80. {
  81. return "1.1.2"; // special case for 1.1
  82. }
  83. else
  84. {
  85. // ASP.NET 2.1.0 packages had exact version dependencies, which was problematic,
  86. // so the default version for 2.1 apps is 2.1.1.
  87. if (packageName == TestProjectCreator.AspNetCoreAppPackageName ||
  88. packageName == TestProjectCreator.AspNetCoreAllPackageName)
  89. {
  90. if (minorVersion == "2.1")
  91. {
  92. return "2.1.1";
  93. }
  94. }
  95. var parsed = NuGetVersion.Parse(minorVersion);
  96. return new NuGetVersion(parsed.Major, parsed.Minor, 0).ToNormalizedString();
  97. }
  98. }
  99. }
  100. }