-
Notifications
You must be signed in to change notification settings - Fork 525
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add paket folder to sln with dep and lock file
- Loading branch information
1 parent
0e0bd0c
commit 818f791
Showing
2 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
namespace Paket | ||
|
||
open System.IO | ||
open Logging | ||
open System | ||
|
||
/// Contains methods to read and manipulate solution files. | ||
module SolutionFile = | ||
let private removeNugetSlnFolderIfEmpty(slnContent: ResizeArray<string>) = | ||
match slnContent |> Seq.tryFindIndex (fun line -> | ||
line.StartsWith("""Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}")""") && line.Contains(".nuget")) with | ||
type SolutionFile(fileName: string) = | ||
[<Literal>] | ||
let slnFolderProjectGuid = "2150E333-8FDC-42A3-9474-1A3956D46DE8" | ||
let originalContent = File.ReadAllLines fileName |> Array.toList | ||
let content = ResizeArray( originalContent ) | ||
|
||
let removeNugetSlnFolderIfEmpty() = | ||
match content |> Seq.tryFindIndex (fun line -> | ||
line.StartsWith(sprintf """Project({%s})""" slnFolderProjectGuid) && line.Contains(".nuget")) with | ||
| Some(index) -> | ||
if slnContent.[index+1].Contains("ProjectSection(SolutionItems)") && | ||
slnContent.[index+2].Contains("EndProjectSection") && | ||
slnContent.[index+3].Contains("EndProject") | ||
if content.[index+1].Contains("ProjectSection(SolutionItems)") && | ||
content.[index+2].Contains("EndProjectSection") && | ||
content.[index+3].Contains("EndProject") | ||
then | ||
slnContent.RemoveRange(index, 4) | ||
content.RemoveRange(index, 4) | ||
| None -> () | ||
|
||
let RemoveNugetEntries(solutionName: string) = | ||
let slnContent = ResizeArray( File.ReadAllLines solutionName ) | ||
let mutable modified = false | ||
|
||
member __.RemoveNugetEntries() = | ||
for file in ["nuget.targets";"packages.config";"nuget.exe"] do | ||
match slnContent |> Seq.tryFindIndex (fun line -> line.ToLower().Contains(sprintf ".nuget\\%s" file)) with | ||
| Some(index) -> slnContent.RemoveAt(index); modified <- true | ||
match content |> Seq.tryFindIndex (fun line -> line.ToLower().Contains(sprintf ".nuget\\%s" file)) with | ||
| Some(index) -> content.RemoveAt(index) | ||
| None -> () | ||
|
||
removeNugetSlnFolderIfEmpty(slnContent) | ||
if modified then File.WriteAllLines(solutionName, slnContent) | ||
removeNugetSlnFolderIfEmpty() | ||
|
||
member __.AddPaketFolder(dependenciesFile, lockFile) = | ||
match content |> Seq.tryFindIndex (fun line -> line.StartsWith("MinimumVisualStudioVersion")) with | ||
| Some index -> | ||
let depFile = createRelativePath dependenciesFile fileName | ||
let lockFile = lockFile |> Option.map (fun l -> createRelativePath l fileName) | ||
let lines = ResizeArray<_>() | ||
|
||
lines.Add(sprintf "Project(\"{%s}\") = \".paket\", \".paket\", \"{%s}\"" slnFolderProjectGuid <| Guid.NewGuid().ToString("D")) | ||
lines.Add " ProjectSection(SolutionItems) = preProject" | ||
lines.Add(sprintf " %s = %s" depFile depFile) | ||
if lockFile |> Option.isSome then | ||
lines.Add(sprintf" %s = %s" lockFile.Value lockFile.Value) | ||
lines.Add " EndProjectSection" | ||
lines.Add "EndProject" | ||
content.InsertRange(index + 1, lines) | ||
| None -> failwithf "Unable to add paket folder to solution %s" fileName | ||
|
||
member __.Save() = | ||
if content |> Seq.toList <> originalContent | ||
then | ||
File.WriteAllLines(fileName, content) | ||
tracefn "Solution %s changed" fileName |