diff --git a/src/Paket.Core/PackageMetaData.fs b/src/Paket.Core/PackageMetaData.fs index 46a795848d..75812d5252 100644 --- a/src/Paket.Core/PackageMetaData.fs +++ b/src/Paket.Core/PackageMetaData.fs @@ -157,19 +157,25 @@ let findDependencies (dependencies : DependenciesFile) config platform (template // Add the assembly + pdb + dll from this project let templateWithOutput = - let assemblyFileName = toFile config platform project - let fi = FileInfo(assemblyFileName) - let name = Path.GetFileNameWithoutExtension fi.Name + let additionalFiles = + let referencedProjects = seq{yield project; yield! project.GetInterProjectDependencies() |> Seq.map(fun proj -> ProjectFile.TryLoad(proj.Path).Value)} + let assemblyNames = referencedProjects + |> Seq.map (fun proj -> proj.GetAssemblyName()) + assemblyNames + |> Seq.collect (fun assemblyFileName -> + let fi = FileInfo(assemblyFileName) + let name = Path.GetFileNameWithoutExtension fi.Name - let additionalFiles = - fi.Directory.GetFiles(name + ".*") - |> Array.filter (fun f -> - let isSameFileName = Path.GetFileNameWithoutExtension f.Name = name - let isValidExtension = - [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"] - |> List.exists ((=) (f.Extension.ToLower())) + fi.Directory.GetFiles(Path.Combine(project.GetOutputDirectory config platform, name + ".*")) + |> Array.filter (fun f -> + let isSameFileName = (Path.GetFileNameWithoutExtension f.Name) = name + let isValidExtension = + [".xml"; ".dll"; ".exe"; ".pdb"; ".mdb"] + |> List.exists ((=) (f.Extension.ToLower())) - isSameFileName && isValidExtension) + isSameFileName && isValidExtension) + ) + |> Seq.toArray additionalFiles |> Array.fold (fun template file -> addFile file.FullName targetDir template) template diff --git a/src/Paket.Core/PackageProcess.fs b/src/Paket.Core/PackageProcess.fs index fd9147dd50..b1efafbbf1 100644 --- a/src/Paket.Core/PackageProcess.fs +++ b/src/Paket.Core/PackageProcess.fs @@ -64,7 +64,7 @@ let private merge buildConfig buildPlatform versionFromAssembly specificVersions | Valid completeCore -> { templateFile with Contents = CompleteInfo(completeCore, mergedOpt) } | _ -> templateFile -let private convertToSymbols (projectFile : ProjectFile) templateFile = +let private convertToSymbols (projectFile : ProjectFile) (includeReferencedProjects : bool) templateFile = let sourceFiles = let getTarget compileItem = match compileItem.Link with @@ -73,7 +73,7 @@ let private convertToSymbols (projectFile : ProjectFile) templateFile = |> Path.GetDirectoryName |> (fun d -> Path.Combine("src", d)) - projectFile.GetCompileItems() + projectFile.GetCompileItems(includeReferencedProjects) |> Seq.map (fun c -> c.Include, getTarget c) |> Seq.toList @@ -85,7 +85,7 @@ let private convertToSymbols (projectFile : ProjectFile) templateFile = let augmentedFiles = optional.Files |> List.append sourceFiles { templateFile with Contents = ProjectInfo({ core with Symbols = true }, { optional with Files = augmentedFiles }) } -let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols) = +let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols, includeReferencedProjects) = let buildConfig = defaultArg buildConfig "Release" let buildPlatform = defaultArg buildPlatform "" let packageOutputPath = if Path.IsPathRooted(packageOutputPath) then packageOutputPath else Path.Combine(workingDir,packageOutputPath) @@ -134,7 +134,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon // add dependencies let allTemplates = let optWithSymbols projectFile templateFile = - seq { yield templateFile; if symbols then yield templateFile |> convertToSymbols projectFile } + seq { yield templateFile; if symbols then yield templateFile |> convertToSymbols projectFile includeReferencedProjects } let convertRemainingTemplate fileName = let templateFile = TemplateFile.Load(fileName,lockFile,version,specificVersions) @@ -180,7 +180,7 @@ let Pack(workingDir,dependencies : DependenciesFile, packageOutputPath, buildCon async { match templateFile with | CompleteTemplate(core, optional) -> - NupkgWriter.Write core optional (Path.GetDirectoryName templateFile.FileName) packageOutputPath + NupkgWriter.Write core optional (Path.GetDirectoryName (Path.GetDirectoryName templateFile.FileName)) packageOutputPath |> NuGetV2.fixDatesInArchive tracefn "Packed: %s" templateFile.FileName | IncompleteTemplate -> diff --git a/src/Paket.Core/ProjectFile.fs b/src/Paket.Core/ProjectFile.fs index 062ec91e76..3df70e97b8 100644 --- a/src/Paket.Core/ProjectFile.fs +++ b/src/Paket.Core/ProjectFile.fs @@ -1078,18 +1078,27 @@ type ProjectFile = sprintf "%s.%s" assemblyName (this.OutputType |> function ProjectOutputType.Library -> "dll" | ProjectOutputType.Exe -> "exe") - member this.GetCompileItems () = - let getCompileItem (compileNode : XmlNode) = + member this.GetCompileItems (includeReferencedProjects:bool) = + let getCompileItem (projfile: ProjectFile, compileNode: XmlNode) = let includePath = compileNode |> getAttribute "Include" |> fun a -> a.Value + let includePath = Path.Combine(Path.GetFileName(Path.GetDirectoryName(projfile.FileName)), includePath) compileNode |> getDescendants "Link" |> function | [] -> { Include = includePath; Link = None } | [link] | link::_ -> { Include = includePath; Link = Some link.InnerText } - this.Document - |> getDescendants "Compile" - |> Seq.map getCompileItem + + let referencedProjects = if includeReferencedProjects then + let getProjects = this.GetInterProjectDependencies() |> Seq.map (fun proj -> ProjectFile.TryLoad(proj.Path).Value) + seq{yield this; yield! getProjects} + else seq {yield this} + + referencedProjects |> Seq.collect(fun proj -> + proj.Document + |> getDescendants "Compile" + |> Seq.map (fun i -> getCompileItem(proj, i)) + ) static member LoadFromStream(fullName:string, stream:Stream) = let doc = new XmlDocument() diff --git a/src/Paket.Core/PublicAPI.fs b/src/Paket.Core/PublicAPI.fs index 032fd35856..671b4c663e 100644 --- a/src/Paket.Core/PublicAPI.fs +++ b/src/Paket.Core/PublicAPI.fs @@ -465,13 +465,14 @@ type Dependencies(dependenciesFileName: string) = FindReferences.FindReferencesForPackage (GroupName group) (PackageName package) |> this.Process // Packs all paket.template files. - member this.Pack(outputPath, ?buildConfig, ?buildPlatform, ?version, ?specificVersions, ?releaseNotes, ?templateFile, ?workingDir, ?excludedTemplates, ?lockDependencies, ?symbols) = + member this.Pack(outputPath, ?buildConfig, ?buildPlatform, ?version, ?specificVersions, ?releaseNotes, ?templateFile, ?workingDir, ?excludedTemplates, ?lockDependencies, ?symbols, ?includeReferencedProjects) = let dependenciesFile = DependenciesFile.ReadFromFile dependenciesFileName let specificVersions = defaultArg specificVersions Seq.empty let workingDir = defaultArg workingDir (dependenciesFile.FileName |> Path.GetDirectoryName) let lockDependencies = defaultArg lockDependencies false let symbols = defaultArg symbols false - PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols) + let includeReferencedProjects = defaultArg includeReferencedProjects false + PackageProcess.Pack(workingDir, dependenciesFile, outputPath, buildConfig, buildPlatform, version, specificVersions, releaseNotes, templateFile, excludedTemplates, lockDependencies, symbols, includeReferencedProjects) /// Pushes a nupkg file. static member Push(packageFileName, ?url, ?apiKey, (?endPoint: string), ?maxTrials) = diff --git a/src/Paket/Commands.fs b/src/Paket/Commands.fs index 5bf8d7dce5..3cd6006aa9 100644 --- a/src/Paket/Commands.fs +++ b/src/Paket/Commands.fs @@ -309,6 +309,7 @@ type PackArgs = | [] ReleaseNotes of string | [] LockDependencies | [] Symbols + | [] IncludeReferencedProjects with interface IArgParserTemplate with member this.Usage = @@ -323,6 +324,7 @@ with | ReleaseNotes(_) -> "Specify relase notes for the package." | LockDependencies -> "Get the version requirements from paket.lock instead of paket.dependencies." | Symbols -> "Build symbol/source packages in addition to library/content packages." + | IncludeReferencedProjects -> "Include symbol/source from referenced projects." type PushArgs = | [][] Url of string diff --git a/src/Paket/Program.fs b/src/Paket/Program.fs index e0c5cb59a0..0279705edc 100644 --- a/src/Paket/Program.fs +++ b/src/Paket/Program.fs @@ -226,7 +226,8 @@ let pack (results : ParseResults<_>) = excludedTemplates = results.GetResults <@ PackArgs.ExcludedTemplate @>, workingDir = Environment.CurrentDirectory, lockDependencies = results.Contains <@ PackArgs.LockDependencies @>, - symbols = results.Contains <@ PackArgs.Symbols @>) + symbols = results.Contains <@ PackArgs.Symbols @>, + includeReferencedProjects = results.Contains <@ PackArgs.IncludeReferencedProjects @>) let findPackages (results : ParseResults<_>) = let maxResults = defaultArg (results.TryGetResult <@ FindPackagesArgs.MaxResults @>) 10000 diff --git a/tests/Paket.Tests/ProjectFile/InterProjectDependencySpecs.fs b/tests/Paket.Tests/ProjectFile/InterProjectDependencySpecs.fs index f37820e41b..b7b54b2810 100644 --- a/tests/Paket.Tests/ProjectFile/InterProjectDependencySpecs.fs +++ b/tests/Paket.Tests/ProjectFile/InterProjectDependencySpecs.fs @@ -29,7 +29,7 @@ let ``should detect path for dependencies in Project2 proj file``() = |> List.map (fun p -> p.Path) paths.[0].EndsWith(normalizePath "src/Paket/Paket.fsproj") |> shouldEqual true - paths.[1].EndsWith(normalizePath "Paket.Core/Paket.Core.fsproj") |> shouldEqual true + paths.[1].EndsWith(normalizePath "src/Paket.Core/Paket.Core.fsproj") |> shouldEqual true [] let ``should detect relative path for dependencies in Project2 proj file``() = @@ -37,8 +37,8 @@ let ``should detect relative path for dependencies in Project2 proj file``() = ProjectFile.TryLoad("./ProjectFile/TestData/Project2.fsprojtest").Value.GetInterProjectDependencies() |> List.map (fun p -> p.RelativePath) - paths.[0] |> shouldEqual "..\\..\\src\\Paket\\Paket.fsproj" - paths.[1] |> shouldEqual "..\\Paket.Core\\Paket.Core.fsproj" + paths.[0] |> shouldEqual "..\\..\\..\\..\\src\\Paket\\Paket.fsproj" + paths.[1] |> shouldEqual "..\\..\\..\\..\\src\\Paket.Core\\Paket.Core.fsproj" [] let ``should detect Guids for dependencies in Project2 proj file``() = @@ -46,4 +46,20 @@ let ``should detect Guids for dependencies in Project2 proj file``() = p.GetProjectGuid() |> shouldEqual (Guid.Parse "e789c72a-5cfd-436b-8ef1-61aa2852a89f") p.GetInterProjectDependencies() |> List.map (fun p -> p.GUID.ToString()) - |> shouldEqual ["09b32f18-0c20-4489-8c83-5106d5c04c93"; "7bab0ae2-089f-4761-b138-a717aa2f86c5"] \ No newline at end of file + |> shouldEqual ["09b32f18-0c20-4489-8c83-5106d5c04c93"; "7bab0ae2-089f-4761-b138-a717aa2f86c5"] + +[] +let ``should not add dependencies in referenced projects for GetCompileItems false``() = + let p = ProjectFile.TryLoad("../../ProjectFile/TestData/Project2.fsprojtest").Value + p.GetCompileItems(false) + |> Seq.filter (fun ci -> ci.Include.Contains("Program.fs")) + |> Seq.length + |> shouldEqual 0 + +[] +let ``should add dependencies in referenced projects for GetCompileItems true``() = + let p = ProjectFile.TryLoad("../../ProjectFile/TestData/Project2.fsprojtest").Value + p.GetCompileItems(true) + |> Seq.filter (fun ci -> ci.Include.Contains("Program.fs")) + |> Seq.length + |> shouldBeGreaterThan 0 diff --git a/tests/Paket.Tests/ProjectFile/TestData/Project2.fsprojtest b/tests/Paket.Tests/ProjectFile/TestData/Project2.fsprojtest index 9e6619e4a7..d305eb7856 100644 --- a/tests/Paket.Tests/ProjectFile/TestData/Project2.fsprojtest +++ b/tests/Paket.Tests/ProjectFile/TestData/Project2.fsprojtest @@ -94,12 +94,12 @@ - + Paket {09b32f18-0c20-4489-8c83-5106d5c04c93} True - + Paket.Core {7bab0ae2-089f-4761-b138-a717aa2f86c5} True