Skip to content

Commit

Permalink
Whenever a references targets file changed we save the ProjectFile
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 10, 2014
1 parent a122a25 commit a18667e
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/Paket.Core/Constants.fs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let ReferencesFile = "paket.references"
let PaketFilesFolderName = "paket-files"

[<Literal>]
let PackageTargetsFileName = "paket.targets"
let PackageTargetsFileName = "generated.paket.targets"

[<Literal>]
let SolutionFolderProjectGuid = "2150E333-8FDC-42A3-9474-1A3956D46DE8"
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/InstallProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ let Install(sources,force, hard, withBindingRedirects, lockFile:LockFile) =

project.UpdateFileItems(gitRemoteItems @ nuGetFileItems, hard)

project.Save()
project.SaveIfChanged()

if withBindingRedirects || lockFile.Options.Redirects then
applyBindingRedirects root extractedPackages
2 changes: 1 addition & 1 deletion src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ let ConvertFromNuget(dependenciesFileName, force, installAfter, initAutoRestore,
for project in ProjectFile.FindAllProjects root do
project.ReplaceNuGetPackagesFile()
project.RemoveNuGetTargetsEntries()
project.Save()
project.SaveIfChanged()

for packagesConfigFile in nugetPackagesConfigs |> Seq.map (fun f -> f.File) do
removeFile packagesConfigFile.FullName
Expand Down
39 changes: 34 additions & 5 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,18 @@ type ProjectFile =
for node in nodesToDelete do
node.ParentNode.RemoveChild(node) |> ignore

member this.DeletePaketImportNodes() =
let nodesToDelete =
[for node in this.Document |> getDescendants "Import" do
let attr = node.Attributes.["Project"]
if attr <> null then
if attr.InnerText.EndsWith("\\" + Constants.PackageTargetsFileName) then
yield node]

for node in nodesToDelete do
node.ParentNode.RemoveChild(node) |> ignore


member this.GenerateTargetImport(filename:string) =
let relativePath = createRelativePath this.FileName filename

Expand Down Expand Up @@ -241,7 +253,8 @@ type ProjectFile =
member this.GenerateReferences(rootPath:string,completeModel: Map<NormalizedPackageName,InstallModel>, usedPackages : Set<NormalizedPackageName>, hard) =
let generateTargetsFiles = true // TODO: Make parameter

this.DeletePaketNodes("Reference")
this.DeletePaketNodes("Reference")
this.DeletePaketImportNodes()

["ItemGroup";"When";"Otherwise";"Choose";"When";"Choose"]
|> List.iter this.DeleteIfEmpty
Expand Down Expand Up @@ -276,12 +289,28 @@ type ProjectFile =

member this.UpdateReferences(rootPath:string,completeModel: Map<NormalizedPackageName,InstallModel>, usedPackages : Set<NormalizedPackageName>, hard) =
for targetFileName,doc in this.GenerateReferences(rootPath,completeModel, usedPackages, hard) do
doc.Save(targetFileName)
let fi = FileInfo(targetFileName)
let originalText =
if fi.Exists then
let originalDoc = new XmlDocument()
originalDoc.Load fi.FullName
Utils.normalizeXml originalDoc
else
""

let newText = Utils.normalizeXml doc

if newText <> originalText then
doc.Save(targetFileName)
this.Save() // Save in order to make Visual Studio reload the project

member this.Save() =
if Utils.normalizeXml this.Document <> this.OriginalText then
member this.Save() = this.Document.Save(this.FileName)

member this.SaveIfChanged() =
let currentText = Utils.normalizeXml this.Document
if currentText <> this.OriginalText then
verbosefn "Project %s changed" this.FileName
this.Document.Save(this.FileName)
this.Save()

member this.GetPaketFileItems() =
this.FindPaketNodes("Content")
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/VSIntegration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ let InitAutoRestore(dependenciesFileName) =
let relativePath =
createRelativePath project.FileName (Path.Combine(root, ".paket", "paket.targets"))
project.AddImportForPaketTargets(relativePath)
project.Save()
project.SaveIfChanged()
2 changes: 1 addition & 1 deletion src/Paket/Paket.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<StartProgram>paket.exe</StartProgram>
<StartWorkingDirectory>
</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\PaketTest3</StartWorkingDirectory>
<StartWorkingDirectory>d:\code\Paketkopie</StartWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down

0 comments on commit a18667e

Please sign in to comment.