From d20e0d74f283cd9e467b5514e70bebc6f6a36228 Mon Sep 17 00:00:00 2001 From: Mihai Codoban Date: Wed, 30 Mar 2016 10:58:30 -0700 Subject: [PATCH] LockFilePatcher should only patch when lock file has holes in it If not, the export file is stale --- .../project.fragment.lock.json | 35 +++++++++++++++++++ .../valid_staleFragment/project.json | 10 ++++++ .../valid_staleFragment/project.lock.json | 13 +++++++ .../Graph/LockFilePatcher.cs | 2 +- .../LockFilePatchingTests.cs | 15 ++++++++ 5 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.fragment.lock.json create mode 100644 TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.json create mode 100644 TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.lock.json diff --git a/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.fragment.lock.json b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.fragment.lock.json new file mode 100644 index 000000000..415fc75d8 --- /dev/null +++ b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.fragment.lock.json @@ -0,0 +1,35 @@ +{ + "version": 2, + "exports": { + "ClassLibrary1/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.5.2", + "compile": { + "bin/Debug/ClassLibrary1.dll": {} + }, + "runtime": { + "bin/Debug/ClassLibrary1.dll": {} + } + }, + "ClassLibrary2/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.6", + "compile": { + "bin/Debug/ClassLibrary2.dll": {} + }, + "runtime": { + "bin/Debug/ClassLibrary2.dll": {} + } + }, + "ClassLibrary3/1.0.0": { + "type": "project", + "framework": ".NETFramework,Version=v4.6", + "compile": { + "bin/Debug/ClassLibrary3.dll": {} + }, + "runtime": { + "bin/Debug/ClassLibrary3.dll": {} + } + } + } +} \ No newline at end of file diff --git a/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.json b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.json new file mode 100644 index 000000000..2959f5fbc --- /dev/null +++ b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.json @@ -0,0 +1,10 @@ +{ + "version": "1.0.0-*", + "compilationOptions": { + "emitEntryPoint": true + }, + + "frameworks": { + "net46": { } + } +} diff --git a/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.lock.json b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.lock.json new file mode 100644 index 000000000..e7b45e57d --- /dev/null +++ b/TestAssets/LockFileSamples/ExportFileSamples/valid_staleFragment/project.lock.json @@ -0,0 +1,13 @@ +{ + "locked": false, + "version": 2, + "targets": { + ".NETFramework,Version=v4.6": { } + }, + "libraries": { + }, + "projectFileDependencyGroups": { + "": [], + ".NETFramework,Version=v4.6": [] + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs index 1754890ea..a0f7c0c0e 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs @@ -26,7 +26,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph { var exportFilePath = GetExportFilePath(_lockFile.LockFilePath); - if (File.Exists(exportFilePath)) + if (File.Exists(exportFilePath) && _msbuildTargetLibraries.Any()) { var exportFile = LockFileReader.ReadExportFile(exportFilePath); PatchLockWithExport(exportFile); diff --git a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs index 35eea7c4d..6e3b69295 100644 --- a/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs +++ b/test/Microsoft.DotNet.ProjectModel.Tests/LockFilePatchingTests.cs @@ -52,6 +52,21 @@ namespace Microsoft.DotNet.ProjectModel.Tests } } + [Fact] + public void TestFragmentExistsButNoHolesInLockFile() + { + var lockFilePath = GetLockFilePath("valid_staleFragment"); + var lockFile = LockFileReader.Read(lockFilePath); + + var exportFile = lockFile.ExportFile; + + exportFile.Should().BeNull(); + + lockFile.Targets.Count.Should().Be(1); + + lockFile.Targets[0].Libraries.Count.Should().Be(0); + } + [Fact] public void TestMissingExportFileThrows() {