From c6bfd752ddac8531782f2557fbeb69101c63fc90 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Mon, 15 Feb 2016 10:57:03 +0100 Subject: [PATCH] Touch project files when paket.lock changed in order to support incremental builds with MsBuild - closes #1471 --- RELEASE_NOTES.md | 3 +++ .../Paket.IntegrationTests/PaketCoreSpecs.fs | 4 ++-- src/Paket.Core/AddProcess.fs | 4 ++-- src/Paket.Core/BindingRedirects.fs | 2 +- src/Paket.Core/InstallProcess.fs | 8 ++++---- src/Paket.Core/LockFile.fs | 1 + src/Paket.Core/NugetConvert.fs | 2 +- src/Paket.Core/ProjectFile.fs | 8 +++++--- src/Paket.Core/RemoveProcess.fs | 12 ++++++------ src/Paket.Core/UpdateProcess.fs | 8 ++++---- src/Paket.Core/VSIntegration.fs | 6 +++--- 11 files changed, 32 insertions(+), 26 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 345b1beef7..6e4b343eba 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,3 +1,6 @@ +#### 2.50.10 - 15.02.2016 +* USABILITY: Touch project files when paket.lock changed in order to support incremental builds with MsBuild - https://github.com/fsprojects/Paket/issues/1471 + #### 2.50.9 - 14.02.2016 * BUGFIX: Do not try to pack output folder - https://github.com/fsprojects/Paket/issues/1473 diff --git a/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs b/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs index 5ff0f332c1..699d7f33f1 100644 --- a/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs +++ b/integrationtests/Paket.IntegrationTests/PaketCoreSpecs.fs @@ -25,7 +25,7 @@ let ``#1251 full installer demo``() = [GroupName "Main",PackageName "FAKE" GroupName "Main",PackageName "FSharp.Formatting"] - let lockFile = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, SemVerUpdateMode.NoRestriction, force) + let lockFile,_ = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, SemVerUpdateMode.NoRestriction, force) let model = Paket.InstallProcess.CreateModel(Path.GetDirectoryName dependenciesFile.FileName, force, dependenciesFile, lockFile, Set.ofSeq packagesToInstall) |> Map.ofArray lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "FAKE"].Version @@ -43,7 +43,7 @@ let ``#1251 install FSharp.Collections.ParallelSeq``() = // get from references file [GroupName "Main",PackageName "FSharp.Collections.ParallelSeq"] - let lockFile = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, SemVerUpdateMode.NoRestriction, force) + let lockFile,_ = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, SemVerUpdateMode.NoRestriction, force) lockFile.Groups.[Constants.MainDependencyGroup].Resolution.[PackageName "FSharp.Collections.ParallelSeq"].Version |> shouldBeGreaterThan (SemVer.Parse "1.0.1") diff --git a/src/Paket.Core/AddProcess.fs b/src/Paket.Core/AddProcess.fs index a5dec7f26b..5425b4f9f9 100644 --- a/src/Paket.Core/AddProcess.fs +++ b/src/Paket.Core/AddProcess.fs @@ -23,7 +23,7 @@ let private add installToProjects addToProjectsF dependenciesFileName groupName existingDependenciesFile .Add(groupName,package,version) - let lockFile = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, options.SemVerUpdateMode, options.Force) + let lockFile,hasChanged = UpdateProcess.SelectiveUpdate(dependenciesFile, PackageResolver.UpdateMode.Install, options.SemVerUpdateMode, options.Force) let projects = seq { for p in ProjectFile.FindAllProjects(Path.GetDirectoryName lockFile.FileName) -> p } // lazy sequence in case no project install required dependenciesFile.Save() @@ -31,7 +31,7 @@ let private add installToProjects addToProjectsF dependenciesFileName groupName addToProjectsF projects groupName package if installAfter then - InstallProcess.Install(options, dependenciesFile, lockFile) + InstallProcess.Install(options, hasChanged, dependenciesFile, lockFile) // Add a package with the option to add it to a specified project. let AddToProject(dependenciesFileName, groupName, package, version, options : InstallerOptions, projectName, installAfter) = diff --git a/src/Paket.Core/BindingRedirects.fs b/src/Paket.Core/BindingRedirects.fs index 47257679e7..99a99069e7 100644 --- a/src/Paket.Core/BindingRedirects.fs +++ b/src/Paket.Core/BindingRedirects.fs @@ -119,7 +119,7 @@ let private addConfigFileToProject project = |> Xml.addAttribute "Include" "app.config" |> itemGroup.AppendChild |> ignore - project.Save()) + project.Save(false)) /// Applies a set of binding redirects to a single configuration file. let private applyBindingRedirects isFirstGroup cleanBindingRedirects bindingRedirects (configFilePath:string) = diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index 48e5c4bdae..baf0b21b0a 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -263,7 +263,7 @@ let findAllReferencesFiles root = |> collect /// Installs all packages from the lock file. -let InstallIntoProjects(options : InstallerOptions, dependenciesFile, lockFile : LockFile, projectsAndReferences : (ProjectFile * ReferencesFile) list) = +let InstallIntoProjects(options : InstallerOptions, forceTouch, dependenciesFile, lockFile : LockFile, projectsAndReferences : (ProjectFile * ReferencesFile) list) = let packagesToInstall = if options.OnlyReferenced then projectsAndReferences @@ -382,7 +382,7 @@ let InstallIntoProjects(options : InstallerOptions, dependenciesFile, lockFile : |> List.concat processContentFiles root project usedPackages gitRemoteItems options - project.Save() + project.Save forceTouch let loadedLibs = new Dictionary<_,_>() let first = ref true @@ -407,7 +407,7 @@ let InstallIntoProjects(options : InstallerOptions, dependenciesFile, lockFile : first := false /// Installs all packages from the lock file. -let Install(options : InstallerOptions, dependenciesFile, lockFile : LockFile) = +let Install(options : InstallerOptions, forceTouch, dependenciesFile, lockFile : LockFile) = let root = FileInfo(lockFile.FileName).Directory.FullName let projects = findAllReferencesFiles root |> returnOrFail - InstallIntoProjects(options, dependenciesFile, lockFile, projects) + InstallIntoProjects(options, forceTouch, dependenciesFile, lockFile, projects) diff --git a/src/Paket.Core/LockFile.fs b/src/Paket.Core/LockFile.fs index e7326708cb..c4ad9a27be 100644 --- a/src/Paket.Core/LockFile.fs +++ b/src/Paket.Core/LockFile.fs @@ -499,6 +499,7 @@ type LockFile(fileName:string,groups: Map) = tracefn "Locked version resolution written to %s" fileName else tracefn "%s is already up-to-date" fileName + hasChanged /// Parses a paket.lock file from file static member LoadFrom(lockFileName) : LockFile = diff --git a/src/Paket.Core/NugetConvert.fs b/src/Paket.Core/NugetConvert.fs index 0ea4b7d8c5..bebd5ab047 100644 --- a/src/Paket.Core/NugetConvert.fs +++ b/src/Paket.Core/NugetConvert.fs @@ -374,7 +374,7 @@ let replaceNuGetWithPaket initAutoRestore installAfter result = result.PaketEnv.DependenciesFile.Save() result.PaketEnv.Projects |> List.iter (fun (project, referencesFile) -> - project.Save() + project.Save(true) referencesFile.Save()) result.SolutionFiles |> Array.iter (fun s -> s.Save()) diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index a19a010d64..0aec801695 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -942,8 +942,10 @@ module ProjectFile = ) - let save project = - if Utils.normalizeXml project.Document <> project.OriginalText then + let save forceTouch project = + if forceTouch then + project.Document.Save(project.FileName) + elif Utils.normalizeXml project.Document <> project.OriginalText then verbosefn "Project %s changed" project.FileName project.Document.Save(project.FileName) @@ -1304,7 +1306,7 @@ type ProjectFile with member this.UpdateReferences (completeModel, usedPackages, hard) = ProjectFile.updateReferences completeModel usedPackages hard this - member this.Save () = ProjectFile.save this + member this.Save(forceTouch) = ProjectFile.save forceTouch this member this.GetPaketFileItems () = ProjectFile.getPaketFileItems this diff --git a/src/Paket.Core/RemoveProcess.fs b/src/Paket.Core/RemoveProcess.fs index 4c453c15af..cb8d4fc2ed 100644 --- a/src/Paket.Core/RemoveProcess.fs +++ b/src/Paket.Core/RemoveProcess.fs @@ -34,25 +34,25 @@ let private remove removeFromProjects dependenciesFileName groupName (package: P let lockFileName = DependenciesFile.FindLockfile dependenciesFileName LockFile.LoadFrom(lockFileName.FullName) - let dependenciesFile,lockFile = + let dependenciesFile,(lockFile,hasChanged) = let exisitingDependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName - if stillInstalled then exisitingDependenciesFile,oldLockFile else + if stillInstalled then exisitingDependenciesFile,(oldLockFile,false) else let dependenciesFile = exisitingDependenciesFile.Remove(groupName,package) dependenciesFile.Save() dependenciesFile,UpdateProcess.SelectiveUpdate(dependenciesFile,PackageResolver.UpdateMode.Install,SemVerUpdateMode.NoRestriction,force) if installAfter then - InstallProcess.Install(InstallerOptions.CreateLegacyOptions(force, hard, false, false, SemVerUpdateMode.NoRestriction), dependenciesFile, lockFile) + InstallProcess.Install(InstallerOptions.CreateLegacyOptions(force, hard, false, false, SemVerUpdateMode.NoRestriction), hasChanged, dependenciesFile, lockFile) /// Removes a package with the option to remove it from a specified project. -let RemoveFromProject(dependenciesFileName, groupName, packageName:PackageName, force, hard, projectName, installAfter) = +let RemoveFromProject(dependenciesFileName, groupName, packageName:PackageName, force, hard, projectName, installAfter) = let groupName = match groupName with | None -> Constants.MainDependencyGroup | Some name -> GroupName name - let removeFromSpecifiedProject (projects : ProjectFile seq) = + let removeFromSpecifiedProject (projects : ProjectFile seq) = match ProjectFile.TryFindProject(projects,projectName) with | Some p -> if p.HasPackageInstalled(groupName,packageName) then @@ -71,7 +71,7 @@ let Remove(dependenciesFileName, groupName, packageName:PackageName, force, hard | Some name -> GroupName name let removeFromProjects (projects: ProjectFile seq) = - for project in projects do + for project in projects do if project.HasPackageInstalled(groupName,packageName) then if (not interactive) || Utils.askYesNo(sprintf " Remove from %s (group %O)?" project.Name groupName) then removePackageFromProject project groupName packageName diff --git a/src/Paket.Core/UpdateProcess.fs b/src/Paket.Core/UpdateProcess.fs index 2ad58f23c6..97a56ab9a5 100644 --- a/src/Paket.Core/UpdateProcess.fs +++ b/src/Paket.Core/UpdateProcess.fs @@ -209,18 +209,18 @@ let SelectiveUpdate(dependenciesFile : DependenciesFile, updateMode, semVerUpdat dependenciesFile updateMode semVerUpdateMode - lockFile.Save() - lockFile + let hasChanged = lockFile.Save() + lockFile,hasChanged /// Smart install command let SmartInstall(dependenciesFile, updateMode, options : UpdaterOptions) = - let lockFile = SelectiveUpdate(dependenciesFile, updateMode, options.Common.SemVerUpdateMode, options.Common.Force) + let lockFile,hasChanged = SelectiveUpdate(dependenciesFile, updateMode, options.Common.SemVerUpdateMode, options.Common.Force) let root = Path.GetDirectoryName dependenciesFile.FileName let projectsAndReferences = InstallProcess.findAllReferencesFiles root |> returnOrFail if not options.NoInstall then - InstallProcess.InstallIntoProjects(options.Common, dependenciesFile, lockFile, projectsAndReferences) + InstallProcess.InstallIntoProjects(options.Common, hasChanged, dependenciesFile, lockFile, projectsAndReferences) /// Update a single package command let UpdatePackage(dependenciesFileName, groupName, packageName : PackageName, newVersion, options : UpdaterOptions) = diff --git a/src/Paket.Core/VSIntegration.fs b/src/Paket.Core/VSIntegration.fs index 11a88c6a49..d34785f090 100644 --- a/src/Paket.Core/VSIntegration.fs +++ b/src/Paket.Core/VSIntegration.fs @@ -11,7 +11,7 @@ open Releases let TurnOnAutoRestore environment = let exeDir = Path.Combine(environment.RootDirectory.FullName, ".paket") - trial { + trial { do! downloadLatestBootstrapperAndTargets environment let paketTargetsPath = Path.Combine(exeDir, "paket.targets") @@ -20,7 +20,7 @@ let TurnOnAutoRestore environment = |> List.iter (fun project -> let relativePath = createRelativePath project.FileName paketTargetsPath project.AddImportForPaketTargets(relativePath) - project.Save() + project.Save(true) ) } @@ -37,6 +37,6 @@ let TurnOffAutoRestore environment = |> List.iter (fun project -> let relativePath = createRelativePath project.FileName paketTargetsPath project.RemoveImportForPaketTargets(relativePath) - project.Save() + project.Save(true) ) } \ No newline at end of file