From 895878234d2c42d044a7ef52ff8207519e8e34f0 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Wed, 10 Apr 2019 15:30:22 -0700 Subject: [PATCH 1/6] fix Restore does not generate lock file on NoOp --- .../RestoreCommand/RestoreCommand.cs | 2 +- .../Utility/NoOpRestoreUtilities.cs | 8 ++- .../NuGet.Commands/Strings.Designer.cs | 9 +++ src/NuGet.Core/NuGet.Commands/Strings.resx | 3 + .../RestoreNETCoreTest.cs | 63 +++++++++++++++++++ 5 files changed, 83 insertions(+), 2 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs index 428f70efeab..9fbe596eed3 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs @@ -130,7 +130,7 @@ public async Task ExecuteAsync(CancellationToken token) { noOpTelemetry.StartIntervalMeasure(); - var noOpSuccess = NoOpRestoreUtilities.VerifyAssetsAndMSBuildFilesAndPackagesArePresent(_request); + var noOpSuccess = NoOpRestoreUtilities.VerifyAssetsAndMSBuildFilesAndLockFilesAndPackagesArePresent(_request); noOpTelemetry.EndIntervalMeasure(MsbuildAssetsVerificationDuration); noOpTelemetry.TelemetryEvent[MsbuildAssetsVerificationResult] = noOpSuccess; diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs index 767739d8435..215c5201a10 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs @@ -111,7 +111,7 @@ internal static string GetCacheFilePath(RestoreRequest request, LockFile lockFil /// This method verifies that the props/targets files and all the packages written out in the lock file are present on disk /// This does not account if the files were manually modified since the last restore /// - internal static bool VerifyAssetsAndMSBuildFilesAndPackagesArePresent(RestoreRequest request) + internal static bool VerifyAssetsAndMSBuildFilesAndLockFilesAndPackagesArePresent(RestoreRequest request) { if (!File.Exists(request.ExistingLockFile?.Path)) @@ -134,6 +134,12 @@ internal static bool VerifyAssetsAndMSBuildFilesAndPackagesArePresent(RestoreReq request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_PropsFileNotOnDisk, request.Project.Name, propsFilePath)); return false; } + var packageLockFilePath = PackagesLockFileUtilities.GetNuGetLockFilePath(request.Project); + if (!File.Exists(packageLockFilePath)) + { + request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_LockFileNotOnDisk, request.Project.Name, packageLockFilePath)); + return false; + } } if (!VerifyPackagesOnDisk(request)) diff --git a/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs b/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs index cdaaa2419b9..2cbd11e3ccf 100644 --- a/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs +++ b/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs @@ -997,6 +997,15 @@ internal static string Log_LockFileMissingLibraryForTargetLibrary { } } + /// + /// Looks up a localized string similar to The Lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore.. + /// + internal static string Log_LockFileNotOnDisk { + get { + return ResourceManager.GetString("Log_LockFileNotOnDisk", resourceCulture); + } + } + /// /// Looks up a localized string similar to The lock file is out-of-date relative to the project file. Regenerating the lock file and re-locking.. /// diff --git a/src/NuGet.Core/NuGet.Commands/Strings.resx b/src/NuGet.Core/NuGet.Commands/Strings.resx index 6ea515c3b42..5457610190a 100644 --- a/src/NuGet.Core/NuGet.Commands/Strings.resx +++ b/src/NuGet.Core/NuGet.Commands/Strings.resx @@ -539,6 +539,9 @@ For more information, visit http://docs.nuget.org/docs/reference/command-line-re The targets file for {0} at location {1} does not exist, no-op is not possible. Continuing restore. + + The Lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore. + {0} depends on {1} but {2} was not found. An approximate best match of {3} was resolved. diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs index 4744a43255c..0d18ac3cb4c 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs @@ -6429,6 +6429,69 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( } } + [Fact] + public async Task RestoreNetCore_NoOp_PackageLockFileMissingWillFailNoOpAndGenerateNewLockFile() + { + // Related issue: https://github.com/NuGet/Home/issues/7807 + // First restore should generate the package lock file. After deleting the package lock file, run the second restore. + // The second restore should fail the No-op, and generate the package lock file. + + // Arrange + using (var pathContext = new SimpleTestPathContext()) + { + // Set up solution, project, and packages + var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); + + var packageX = new SimpleTestPackageContext() + { + Id = "x", + Version = "1.0.0" + }; + + var projects = new List(); + + var project = SimpleTestProjectContext.CreateNETCore( + $"proj", + pathContext.SolutionRoot, + NuGetFramework.Parse("net45")); + + project.Properties.Add("RestorePackagesWithLockFile", "true"); + + project.AddPackageToAllFrameworks(packageX); + solution.Projects.Add(project); + solution.Create(pathContext.SolutionRoot); + + + await SimpleTestPackageUtility.CreateFolderFeedV3Async( + pathContext.PackageSource, + PackageSaveMode.Defaultv3, + packageX); + + + // Prerequisites + var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + Assert.Equal(0, result1.Item1); + Assert.Contains("Writing packages lock file at disk.", result1.Item2); + + var packageLockFileName = Path.Combine(Path.GetDirectoryName(project.ProjectPath), "packages.lock.json"); + Assert.True(File.Exists(packageLockFileName)); + + File.Delete(packageLockFileName); + Assert.False(File.Exists(packageLockFileName)); + + // Act + var result2 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + //Assert + Assert.Equal(0, result2.Item1); + var noopFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + Assert.Contains(noopFailedMsg, result2.Item2); + Assert.Contains("Writing packages lock file at disk.", result2.Item2); + Assert.True(File.Exists(packageLockFileName)); + } + } + [Fact] public async Task RestoreNetCore_SingleTFM_SimplePackageDownload() { From 9b9fbaa5d68d5f9fdf4caa8215f2ef631ccfbc4b Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Fri, 12 Apr 2019 16:01:13 -0700 Subject: [PATCH 2/6] check if lockfile is supported & add tests --- .../Utility/NoOpRestoreUtilities.cs | 12 +- .../RestoreNETCoreTest.cs | 215 +++++++++++++++++- 2 files changed, 214 insertions(+), 13 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs index 215c5201a10..160ee1ec41d 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs @@ -134,12 +134,16 @@ internal static bool VerifyAssetsAndMSBuildFilesAndLockFilesAndPackagesArePresen request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_PropsFileNotOnDisk, request.Project.Name, propsFilePath)); return false; } - var packageLockFilePath = PackagesLockFileUtilities.GetNuGetLockFilePath(request.Project); - if (!File.Exists(packageLockFilePath)) + if (PackagesLockFileUtilities.IsNuGetLockFileSupported(request.Project)) { - request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_LockFileNotOnDisk, request.Project.Name, packageLockFilePath)); - return false; + var packageLockFilePath = PackagesLockFileUtilities.GetNuGetLockFilePath(request.Project); + if (!File.Exists(packageLockFilePath)) + { + request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_LockFileNotOnDisk, request.Project.Name, packageLockFilePath)); + return false; + } } + } if (!VerifyPackagesOnDisk(request)) diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs index 0d18ac3cb4c..9e1e00b7e56 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs @@ -6430,11 +6430,12 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( } [Fact] - public async Task RestoreNetCore_NoOp_PackageLockFileMissingWillFailNoOpAndGenerateNewLockFile() + public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_BySetProperty_ThenDeletePackageLockFile() { // Related issue: https://github.com/NuGet/Home/issues/7807 - // First restore should generate the package lock file. After deleting the package lock file, run the second restore. - // The second restore should fail the No-op, and generate the package lock file. + // First senario : Enable RestorePackagesWithLockFile by only setting property. + // First restore should fail the No-op, generate the package lock file. After deleting the package lock file, run the second restore. + // The second restore should fail the No-op, and generate the package lock file. // Arrange using (var pathContext = new SimpleTestPathContext()) @@ -6468,30 +6469,226 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( packageX); - // Prerequisites + var packageLockFileName = project.NuGetLockFileOutputPath; + var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + + // Act var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + // Assert Assert.Equal(0, result1.Item1); Assert.Contains("Writing packages lock file at disk.", result1.Item2); - - var packageLockFileName = Path.Combine(Path.GetDirectoryName(project.ProjectPath), "packages.lock.json"); Assert.True(File.Exists(packageLockFileName)); + // Act File.Delete(packageLockFileName); Assert.False(File.Exists(packageLockFileName)); - // Act var result2 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); //Assert Assert.Equal(0, result2.Item1); - var noopFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; - Assert.Contains(noopFailedMsg, result2.Item2); + Assert.Contains(noOpFailedMsg, result2.Item2); Assert.Contains("Writing packages lock file at disk.", result2.Item2); Assert.True(File.Exists(packageLockFileName)); } } + + [Fact] + public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_BySetProperty_ThenNotDeletePackageLockFile() + { + // Related issue: https://github.com/NuGet/Home/issues/7807 + // Contrast test to the first senario : do not delete package lock file at the end of the first restore. + // First restore should fail the No-op, generate the package lock file. DO NOT delete the package lock file, run the second restore. + // The second restore should No-op, and won't generate the package lock file. + + // Arrange + using (var pathContext = new SimpleTestPathContext()) + { + // Set up solution, project, and packages + var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); + + var packageX = new SimpleTestPackageContext() + { + Id = "x", + Version = "1.0.0" + }; + + var projects = new List(); + + var project = SimpleTestProjectContext.CreateNETCore( + $"proj", + pathContext.SolutionRoot, + NuGetFramework.Parse("net45")); + + project.Properties.Add("RestorePackagesWithLockFile", "true"); + + project.AddPackageToAllFrameworks(packageX); + solution.Projects.Add(project); + solution.Create(pathContext.SolutionRoot); + + + await SimpleTestPackageUtility.CreateFolderFeedV3Async( + pathContext.PackageSource, + PackageSaveMode.Defaultv3, + packageX); + + + var packageLockFileName = project.NuGetLockFileOutputPath; + var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; + + // Act + var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + // Assert + Assert.Equal(0, result1.Item1); + Assert.Contains("Writing packages lock file at disk.", result1.Item2); + Assert.True(File.Exists(packageLockFileName)); + + // Act + var result2 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + //Assert + Assert.Equal(0, result2.Item1); + Assert.Contains(noOpSucceedMsg, result2.Item2); + Assert.DoesNotContain("Writing packages lock file at disk.", result2.Item2); + Assert.True(File.Exists(packageLockFileName)); + } + } + + [Fact] + public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_ByAddLockFile_ThenDeletePackageLockFile() + { + // Related issue: https://github.com/NuGet/Home/issues/7807 + // Second senario : Enable RestorePackagesWithLockFile by only adding a lock file. + // First restore should fail the No-op, regenerate the package lock file. After deleting the package lock file, run the second restore. + // The second restore: since there is no property set and no lock file exists, no lockfile will be generated. And no-op succeed. + + // Arrange + using (var pathContext = new SimpleTestPathContext()) + { + // Set up solution, project, and packages + var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); + + var packageX = new SimpleTestPackageContext() + { + Id = "x", + Version = "1.0.0" + }; + + var projects = new List(); + + var project = SimpleTestProjectContext.CreateNETCore( + $"proj", + pathContext.SolutionRoot, + NuGetFramework.Parse("net45")); + + project.AddPackageToAllFrameworks(packageX); + solution.Projects.Add(project); + solution.Create(pathContext.SolutionRoot); + + await SimpleTestPackageUtility.CreateFolderFeedV3Async( + pathContext.PackageSource, + PackageSaveMode.Defaultv3, + packageX); + + var packageLockFileName = project.NuGetLockFileOutputPath; + Assert.False(File.Exists(packageLockFileName)); + File.Create(packageLockFileName).Close(); + Assert.True(File.Exists(packageLockFileName)); + + + var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; + + // Act + var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + // Assert + Assert.Equal(0, result1.Item1); + Assert.Contains("Writing packages lock file at disk.", result1.Item2); + Assert.True(File.Exists(packageLockFileName)); + + // Act + File.Delete(packageLockFileName); + Assert.False(File.Exists(packageLockFileName)); + + var result2 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + //Assert + Assert.Equal(0, result2.Item1); + Assert.Contains(noOpSucceedMsg, result2.Item2); + Assert.DoesNotContain("Writing packages lock file at disk.", result2.Item2); + Assert.False(File.Exists(packageLockFileName)); + } + } + + [Fact] + public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_ByAddLockFile_ThenNotDeletePackageLockFile() + { + // Related issue: https://github.com/NuGet/Home/issues/7807 + // Contrast test to the second senario : do not delete package lock file at the end of the first restore. + // First restore should fail the No-op, regenerate the package lock file. DO NOT delete the package lock file, run the second restore. + // The second restore: No lockfile will be generated. And no-op succeed. + + // Arrange + using (var pathContext = new SimpleTestPathContext()) + { + // Set up solution, project, and packages + var solution = new SimpleTestSolutionContext(pathContext.SolutionRoot); + + var packageX = new SimpleTestPackageContext() + { + Id = "x", + Version = "1.0.0" + }; + + var projects = new List(); + + var project = SimpleTestProjectContext.CreateNETCore( + $"proj", + pathContext.SolutionRoot, + NuGetFramework.Parse("net45")); + + project.AddPackageToAllFrameworks(packageX); + solution.Projects.Add(project); + solution.Create(pathContext.SolutionRoot); + + await SimpleTestPackageUtility.CreateFolderFeedV3Async( + pathContext.PackageSource, + PackageSaveMode.Defaultv3, + packageX); + + var packageLockFileName = project.NuGetLockFileOutputPath; + Assert.False(File.Exists(packageLockFileName)); + File.Create(packageLockFileName).Close(); + Assert.True(File.Exists(packageLockFileName)); + + + var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; + + // Act + var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + // Assert + Assert.Equal(0, result1.Item1); + Assert.Contains("Writing packages lock file at disk.", result1.Item2); + Assert.True(File.Exists(packageLockFileName)); + + // Act + var result2 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); + + //Assert + Assert.Equal(0, result2.Item1); + Assert.Contains(noOpSucceedMsg, result2.Item2); + Assert.DoesNotContain("Writing packages lock file at disk.", result2.Item2); + Assert.False(File.Exists(packageLockFileName)); + } + } + [Fact] public async Task RestoreNetCore_SingleTFM_SimplePackageDownload() { From 2a7b9eb121a0effdb4f18bac21cbb9b7294a195e Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Fri, 12 Apr 2019 20:22:35 -0700 Subject: [PATCH 3/6] fix a test --- .../NuGet.CommandLine.Test/RestoreNETCoreTest.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs index 9e1e00b7e56..f249b336614 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs @@ -6631,7 +6631,7 @@ public async Task RestoreNetCore_NoOp_EnableRestorePackagesWithLockFile_ByAddLoc // Related issue: https://github.com/NuGet/Home/issues/7807 // Contrast test to the second senario : do not delete package lock file at the end of the first restore. // First restore should fail the No-op, regenerate the package lock file. DO NOT delete the package lock file, run the second restore. - // The second restore: No lockfile will be generated. And no-op succeed. + // The second restore: No-op should succeed, lock file will not be regenerated. // Arrange using (var pathContext = new SimpleTestPathContext()) @@ -6685,7 +6685,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( Assert.Equal(0, result2.Item1); Assert.Contains(noOpSucceedMsg, result2.Item2); Assert.DoesNotContain("Writing packages lock file at disk.", result2.Item2); - Assert.False(File.Exists(packageLockFileName)); + Assert.True(File.Exists(packageLockFileName)); } } From 92142fa8ff5f7dfa84f614985a95401769297790 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Mon, 15 Apr 2019 09:24:16 -0700 Subject: [PATCH 4/6] change the long method name to a short one & add comment --- .../NuGet.Commands/RestoreCommand/RestoreCommand.cs | 2 +- .../RestoreCommand/Utility/NoOpRestoreUtilities.cs | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs index 9fbe596eed3..7e5c47b31e0 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs @@ -130,7 +130,7 @@ public async Task ExecuteAsync(CancellationToken token) { noOpTelemetry.StartIntervalMeasure(); - var noOpSuccess = NoOpRestoreUtilities.VerifyAssetsAndMSBuildFilesAndLockFilesAndPackagesArePresent(_request); + var noOpSuccess = NoOpRestoreUtilities.VerifyRestoreOutput(_request); noOpTelemetry.EndIntervalMeasure(MsbuildAssetsVerificationDuration); noOpTelemetry.TelemetryEvent[MsbuildAssetsVerificationResult] = noOpSuccess; diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs index 160ee1ec41d..5495f5ffad2 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs @@ -108,10 +108,11 @@ internal static string GetCacheFilePath(RestoreRequest request, LockFile lockFil } /// - /// This method verifies that the props/targets files and all the packages written out in the lock file are present on disk + /// This method verifies that the assets files, props/targets files and all the packages written out in the lock file are present on disk + /// When package lock file is supported, this method also verifies if the package lock file is present on disk /// This does not account if the files were manually modified since the last restore /// - internal static bool VerifyAssetsAndMSBuildFilesAndLockFilesAndPackagesArePresent(RestoreRequest request) + internal static bool VerifyRestoreOutput(RestoreRequest request) { if (!File.Exists(request.ExistingLockFile?.Path)) From 11867cc967ddb47edfb960a0dccd3be86a3f4909 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Tue, 16 Apr 2019 13:28:00 -0700 Subject: [PATCH 5/6] change method name and remarks to make it more precisely --- .../Diagnostics/UnexpectedDependencyMessages.cs | 2 +- .../NuGet.Commands/RestoreCommand/RestoreCommand.cs | 4 ++-- .../RestoreCommand/Utility/NoOpRestoreUtilities.cs | 6 +++--- src/NuGet.Core/NuGet.Commands/Strings.Designer.cs | 2 +- src/NuGet.Core/NuGet.Commands/Strings.resx | 2 +- .../NuGet.PackageManagement/NuGetPackageManager.cs | 2 +- .../ProjectLockFile/PackagesLockFileUtilities.cs | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Diagnostics/UnexpectedDependencyMessages.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Diagnostics/UnexpectedDependencyMessages.cs index 7bcaad86474..732bccd1d47 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Diagnostics/UnexpectedDependencyMessages.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Diagnostics/UnexpectedDependencyMessages.cs @@ -39,7 +39,7 @@ public static async Task LogAsync(IEnumerable graphs, Packa // Ignore generating NU1603/NU1602 across entire graph if lock file is enabled. Because // lock file enforce a fixed resolved version for all the different requests for the same package ID. - if (!PackagesLockFileUtilities.IsNuGetLockFileSupported(project)) + if (!PackagesLockFileUtilities.IsNuGetLockFileEnabled(project)) { // 2. Detect dependency and source issues across the entire graph // where the minimum version was not matched exactly. diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs index 7e5c47b31e0..cb4c02de310 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs @@ -167,7 +167,7 @@ public async Task ExecuteAsync(CancellationToken token) using (var lockFileTelemetry = TelemetryActivity.CreateTelemetryActivityWithNewOperationIdAndEvent(parentId: _operationId, eventName: RestoreLockFileInformation)) { - lockFileTelemetry.TelemetryEvent[IsLockFileEnabled] = PackagesLockFileUtilities.IsNuGetLockFileSupported(_request.Project); + lockFileTelemetry.TelemetryEvent[IsLockFileEnabled] = PackagesLockFileUtilities.IsNuGetLockFileEnabled(_request.Project); var packagesLockFileResult = await EvaluatePackagesLockFileAsync(packagesLockFilePath, contextForProject, lockFileTelemetry); @@ -309,7 +309,7 @@ public async Task ExecuteAsync(CancellationToken token) // clear out the existing lock file so that we don't over-write the same file packagesLockFile = null; } - else if (PackagesLockFileUtilities.IsNuGetLockFileSupported(_request.Project)) + else if (PackagesLockFileUtilities.IsNuGetLockFileEnabled(_request.Project)) { // generate packages.lock.json file if enabled packagesLockFile = new PackagesLockFileBuilder() diff --git a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs index 5495f5ffad2..ae1381535bc 100644 --- a/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs +++ b/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/NoOpRestoreUtilities.cs @@ -108,8 +108,8 @@ internal static string GetCacheFilePath(RestoreRequest request, LockFile lockFil } /// - /// This method verifies that the assets files, props/targets files and all the packages written out in the lock file are present on disk - /// When package lock file is supported, this method also verifies if the package lock file is present on disk + /// This method verifies that the assets files, props/targets files and all the packages written out in the assets file are present on disk + /// When the project has opted into packages lock file, it also verified that the lock file is present on disk. /// This does not account if the files were manually modified since the last restore /// internal static bool VerifyRestoreOutput(RestoreRequest request) @@ -135,7 +135,7 @@ internal static bool VerifyRestoreOutput(RestoreRequest request) request.Log.LogVerbose(string.Format(CultureInfo.CurrentCulture, Strings.Log_PropsFileNotOnDisk, request.Project.Name, propsFilePath)); return false; } - if (PackagesLockFileUtilities.IsNuGetLockFileSupported(request.Project)) + if (PackagesLockFileUtilities.IsNuGetLockFileEnabled(request.Project)) { var packageLockFilePath = PackagesLockFileUtilities.GetNuGetLockFilePath(request.Project); if (!File.Exists(packageLockFilePath)) diff --git a/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs b/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs index 2cbd11e3ccf..8be9d1a555c 100644 --- a/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs +++ b/src/NuGet.Core/NuGet.Commands/Strings.Designer.cs @@ -998,7 +998,7 @@ internal static string Log_LockFileMissingLibraryForTargetLibrary { } /// - /// Looks up a localized string similar to The Lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore.. + /// Looks up a localized string similar to The lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore.. /// internal static string Log_LockFileNotOnDisk { get { diff --git a/src/NuGet.Core/NuGet.Commands/Strings.resx b/src/NuGet.Core/NuGet.Commands/Strings.resx index 5457610190a..7193f6970e2 100644 --- a/src/NuGet.Core/NuGet.Commands/Strings.resx +++ b/src/NuGet.Core/NuGet.Commands/Strings.resx @@ -540,7 +540,7 @@ For more information, visit http://docs.nuget.org/docs/reference/command-line-re The targets file for {0} at location {1} does not exist, no-op is not possible. Continuing restore. - The Lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore. + The lock file for {0} at location {1} does not exist, no-op is not possible. Continuing restore. {0} depends on {1} but {2} was not found. An approximate best match of {3} was resolved. diff --git a/src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs b/src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs index 6c9fc4bc5f8..5d03be0e0b0 100644 --- a/src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs +++ b/src/NuGet.Core/NuGet.PackageManagement/NuGetPackageManager.cs @@ -2829,7 +2829,7 @@ await DependencyGraphRestoreUtility.RestoreProjectAsync( } // add packages lock file into project - if (PackagesLockFileUtilities.IsNuGetLockFileSupported(projectAction.RestoreResult.LockFile.PackageSpec)) + if (PackagesLockFileUtilities.IsNuGetLockFileEnabled(projectAction.RestoreResult.LockFile.PackageSpec)) { var lockFilePath = PackagesLockFileUtilities.GetNuGetLockFilePath(projectAction.RestoreResult.LockFile.PackageSpec); diff --git a/src/NuGet.Core/NuGet.ProjectModel/ProjectLockFile/PackagesLockFileUtilities.cs b/src/NuGet.Core/NuGet.ProjectModel/ProjectLockFile/PackagesLockFileUtilities.cs index 9b6ccf99e23..d19c7f2a666 100644 --- a/src/NuGet.Core/NuGet.ProjectModel/ProjectLockFile/PackagesLockFileUtilities.cs +++ b/src/NuGet.Core/NuGet.ProjectModel/ProjectLockFile/PackagesLockFileUtilities.cs @@ -14,7 +14,7 @@ namespace NuGet.ProjectModel { public static class PackagesLockFileUtilities { - public static bool IsNuGetLockFileSupported(PackageSpec project) + public static bool IsNuGetLockFileEnabled(PackageSpec project) { var restorePackagesWithLockFile = project.RestoreMetadata?.RestoreLockProperties.RestorePackagesWithLockFile; return MSBuildStringUtility.IsTrue(restorePackagesWithLockFile) || File.Exists(GetNuGetLockFilePath(project)); From 3d0a7ed947cf5bf2ea62471bff9ddd5dbbabac74 Mon Sep 17 00:00:00 2001 From: Heng Liu Date: Tue, 16 Apr 2019 15:07:22 -0700 Subject: [PATCH 6/6] change Lock into lock in msg --- .../NuGet.CommandLine.Test/RestoreNETCoreTest.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs index f249b336614..d20988d3027 100644 --- a/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs +++ b/test/NuGet.Clients.Tests/NuGet.CommandLine.Test/RestoreNETCoreTest.cs @@ -6470,7 +6470,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( var packageLockFileName = project.NuGetLockFileOutputPath; - var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; // Act var result1 = Util.Restore(pathContext, project.ProjectPath, additionalArgs: "-verbosity Detailed"); @@ -6536,7 +6536,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( var packageLockFileName = project.NuGetLockFileOutputPath; - var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; // Act @@ -6600,7 +6600,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( Assert.True(File.Exists(packageLockFileName)); - var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; // Act @@ -6667,7 +6667,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( Assert.True(File.Exists(packageLockFileName)); - var noOpFailedMsg = "The Lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; + var noOpFailedMsg = "The lock file for " + project.ProjectName + " at location " + packageLockFileName + " does not exist, no-op is not possible. Continuing restore."; var noOpSucceedMsg = "No-Op restore. The cache will not be updated."; // Act