Skip to content

Commit

Permalink
convert - try to read PackageReferences of new MsBuild - references #…
Browse files Browse the repository at this point in the history
  • Loading branch information
theimowski committed Nov 3, 2016
1 parent f698fe1 commit 17f6538
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 10 deletions.
41 changes: 32 additions & 9 deletions src/Paket.Core/NugetConvert.fs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ type NugetEnv =
{ RootDirectory : DirectoryInfo
NuGetConfig : NugetConfig
NuGetConfigFiles : list<FileInfo>
NuGetProjectFiles : list<ProjectFile * NugetPackagesConfig>
NuGetProjectFiles : list<ProjectFile * NugetPackagesConfig option>
NuGetTargets : option<FileInfo>
NuGetExe : option<FileInfo> }

Expand Down Expand Up @@ -179,14 +179,19 @@ module NugetEnv =
|> ok
with _ -> fail (NugetPackagesConfigParseError file)

let readPackages (projectFile : ProjectFile) : Result<ProjectFile * option<NugetPackagesConfig>, DomainMessage> =
let path = Path.Combine(Path.GetDirectoryName(projectFile.FileName), Constants.PackagesConfigFile)
if File.Exists path then
path |> FileInfo |> readSingle |> lift Some
else
Result.Succeed None
|> lift (fun configFile -> (projectFile,configFile))

let projectFiles = ProjectFile.FindAllProjects rootDirectory.FullName

projectFiles
|> Array.map (fun p -> p, Path.Combine(Path.GetDirectoryName(p.FileName), Constants.PackagesConfigFile))
|> Array.filter (fun (p,packages) -> File.Exists packages)
|> Array.map (fun (p,packages) -> readSingle(FileInfo(packages)) |> lift (fun packages -> (p,packages)))
|> Array.map readPackages
|> collect

let read (rootDirectory : DirectoryInfo) = trial {
let configs = FindAllFiles(rootDirectory.FullName, "nuget.config") |> Array.toList
let targets = FindAllFiles(rootDirectory.FullName, "nuget.targets") |> Array.tryHead
Expand Down Expand Up @@ -229,7 +234,13 @@ let createDependenciesFileR (rootDirectory : DirectoryInfo) nugetEnv mode =

let allVersionsGroupped =
nugetEnv.NuGetProjectFiles
|> List.collect (fun (_,c) -> c.Packages)
|> List.collect (fun (pf,c) ->
c
|> Option.map (fun x -> x.Packages)
|> Option.toList
|> List.concat
|> List.append (ProjectFile.dotNetCorePackages pf))
|> List.map (fun x -> tracefn "%A" x; x)
|> List.groupBy (fun p -> p.Id)

let findDistinctPackages selector =
Expand Down Expand Up @@ -321,13 +332,22 @@ let convertDependenciesConfigToReferencesFile projectFileName dependencies =

let convertProjects nugetEnv =
[for project,packagesConfig in nugetEnv.NuGetProjectFiles do
let packagesAndIds = packagesConfig.Packages |> List.map (fun p -> p.Id, p.Version)
let packagesAndIds =
packagesConfig
|> Option.map (fun x -> x.Packages)
|> Option.toList
|> List.concat
|> List.map (fun p -> p.Id, p.Version)
project.ReplaceNuGetPackagesFile()
project.RemoveNuGetTargetsEntries()
project.RemoveNugetAnalysers(packagesAndIds)
project.RemoveImportAndTargetEntries(packagesAndIds)
project.RemoveNuGetPackageImportStamp()
yield project, convertPackagesConfigToReferencesFile project.FileName packagesConfig]
match packagesConfig with
| Some packagesConfig ->
yield project, convertPackagesConfigToReferencesFile project.FileName packagesConfig
| None ->
()]

let createPaketEnv rootDirectory nugetEnv credsMirationMode = trial {
let! depFile = createDependenciesFileR rootDirectory nugetEnv credsMirationMode
Expand Down Expand Up @@ -373,7 +393,10 @@ let replaceNuGetWithPaket initAutoRestore installAfter fromBootstrapper result =
fi.Delete()

result.NuGetEnv.NuGetConfigFiles |> List.iter remove
result.NuGetEnv.NuGetProjectFiles |> List.map (fun (_,n) -> n.File) |> List.iter remove
result.NuGetEnv.NuGetProjectFiles
|> List.map (fun (_,n) -> n |> Option.map (fun x -> x.File))
|> List.choose id
|> List.iter remove
result.NuGetEnv.NuGetTargets |> Option.iter remove
result.NuGetEnv.NuGetExe
|> Option.iter
Expand Down
2 changes: 1 addition & 1 deletion src/Paket.Core/Paket.Core.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@
<Compile Include="DependenciesFileParser.fs" />
<Compile Include="LockFile.fs" />
<Compile Include="TemplateFile.fs" />
<Compile Include="PackagesConfigFile.fs" />
<Compile Include="ProjectFile.fs" />
<Compile Include="DependenciesFile.fs" />
<Compile Include="LocalFile.fs" />
Expand All @@ -126,7 +127,6 @@
<Compile Include="BindingRedirects.fs" />
<Compile Include="NupkgWriter.fs" />
<Compile Include="ProcessOptions.fs" />
<Compile Include="PackagesConfigFile.fs" />
<Compile Include="DependencyModel.fs" />
<Compile Include="InstallProcess.fs" />
<Compile Include="UpdateProcess.fs" />
Expand Down
8 changes: 8 additions & 0 deletions src/Paket.Core/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,14 @@ module ProjectFile =

tryNextPlat platforms []

let dotNetCorePackages (projectFile: ProjectFile) =
projectFile.ProjectNode
|> getDescendants "PackageReference"
|> List.map (fun node ->
{Paket.PackagesConfigFile.NugetPackage.Id = node |> getAttribute "Include" |> Option.get
Paket.PackagesConfigFile.Version = node |> getNode "Version" |> Option.get |> (fun n -> Paket.SemVer.Parse n.InnerText)
Paket.PackagesConfigFile.TargetFramework = None })

type ProjectFile with

member this.GetPropertyWithDefaults propertyName defaultProperties = ProjectFile.getPropertyWithDefaults propertyName defaultProperties this
Expand Down

0 comments on commit 17f6538

Please sign in to comment.