diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 72ec7a8c56..ba946eda21 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -3,6 +3,7 @@ * Fix build exe path which includes whitespace - https://github.com/fsprojects/ProjectScaffold/pull/185 * Preserve encoding upon saving solution - https://github.com/fsprojects/Paket/pull/940 * BUGFIX: If we specify a templatefile in paket pack it still packs all templates - https://github.com/fsprojects/Paket/pull/944 +* BUGFIX: If we specify a type project templatefile in paket pack it should find the project - https://github.com/fsprojects/Paket/issues/945 #### 1.21.0 - 23.07.2015 * Allow nuget packages to put version in the path - https://github.com/fsprojects/Paket/pull/928 diff --git a/src/Paket.Core/PackageProcess.fs b/src/Paket.Core/PackageProcess.fs index 6bd69b79c6..fe6437cd52 100644 --- a/src/Paket.Core/PackageProcess.fs +++ b/src/Paket.Core/PackageProcess.fs @@ -10,6 +10,49 @@ open System.Collections.Generic open Paket.PackageMetaData open Chessie.ErrorHandling +let private merge buildConfig version projectFile templateFile = + let withVersion = + match version with + | None -> templateFile + | Some v -> templateFile |> TemplateFile.setVersion v + + match withVersion with + | { Contents = ProjectInfo(md, opt) } -> + match md with + | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } + | _ -> + let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile + let md = { md with Id = md.Id ++ Some id } + + match md with + | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } + | _ -> + let attribs = loadAssemblyAttributes assemblyFileName assembly + + let merged = + { Id = md.Id + Version = md.Version ++ getVersion assembly attribs + Authors = md.Authors ++ getAuthors attribs + Description = md.Description ++ getDescription attribs } + + match merged with + | Invalid -> + let missing = + [ if merged.Id = None then yield "Id" + if merged.Version = None then yield "Version" + if merged.Authors = None || merged.Authors = Some [] then yield "Authors" + if merged.Description = None then yield "Description" ] + |> fun xs -> String.Join(", ",xs) + + failwithf + "Incomplete mandatory metadata in template file %s (even including assembly attributes)%sTemplate: %A%sMissing: %s" + templateFile.FileName + Environment.NewLine md + Environment.NewLine missing + + | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } + | _ -> templateFile + let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, version, releaseNotes, templateFile, lockDependencies) = let buildConfig = defaultArg buildConfig "Release" let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath) @@ -46,48 +89,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon |> Array.map (fun (projectFile,templateFile) -> allTemplateFiles.Remove(templateFile.FileName) |> ignore - let merged = - let withVersion = - match version with - | None -> templateFile - | Some v -> templateFile |> TemplateFile.setVersion v - - match withVersion with - | { Contents = ProjectInfo(md, opt) } -> - match md with - | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } - | _ -> - let assembly,id,assemblyFileName = loadAssemblyId buildConfig projectFile - let md = { md with Id = md.Id ++ Some id } - - match md with - | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } - | _ -> - let attribs = loadAssemblyAttributes assemblyFileName assembly - - let merged = - { Id = md.Id - Version = md.Version ++ getVersion assembly attribs - Authors = md.Authors ++ getAuthors attribs - Description = md.Description ++ getDescription attribs } - - match merged with - | Invalid -> - let missing = - [ if merged.Id = None then yield "Id" - if merged.Version = None then yield "Version" - if merged.Authors = None || merged.Authors = Some [] then yield "Authors" - if merged.Description = None then yield "Description" ] - |> fun xs -> String.Join(", ",xs) - - failwithf - "Incomplete mandatory metadata in template file %s (even including assembly attributes)%sTemplate: %A%sMissing: %s" - templateFile.FileName - Environment.NewLine md - Environment.NewLine missing - - | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, opt) } - | _ -> templateFile + let merged = merge buildConfig version projectFile templateFile let id = match merged.Contents with @@ -103,7 +105,18 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon |> Map.map (fun _ (t, p) -> p,findDependencies dependencies buildConfig t p lockDependencies projectTemplates) |> Map.toList |> List.map (fun (_,(_,x)) -> x) - |> List.append [for fileName in allTemplateFiles -> TemplateFile.Load(fileName,version)] + |> List.append [for fileName in allTemplateFiles -> + let templateFile = TemplateFile.Load(fileName,version) + match templateFile with + | { Contents = ProjectInfo(_) } -> + let fi = FileInfo(fileName) + let allProjectFiles = ProjectFile.FindAllProjects(fi.Directory.FullName) |> Array.toList + + match allProjectFiles with + | [ projectFile ] -> merge buildConfig version projectFile templateFile + | [] -> failwithf "There was no project file found for template file %s" fileName + | _ -> failwithf "There was more than one project file found for template file %s" fileName + | _ -> templateFile ] // set version let templatesWithVersion =