假:获取解决方案文件引用的所有项目



如何获取解决方案文件引用的项目?

在这里,我有一个具体的用例。我从ProjectScaffold窃取了这个目标CopyBinaries。它将项目生成的输出复制到单独的文件夹中。它不是很挑剔,会复制它找到的每个项目的输出。

Target "CopyBinaries" (fun _ ->
    !! "src/**/*.??proj"
    -- "src/**/*.shproj"
    |> Seq.map (fun f -> 
            ((System.IO.Path.GetDirectoryName f) </> "bin/Release", 
             binDir </> (System.IO.Path.GetFileNameWithoutExtension f)))
    |> Seq.iter (fun (fromDir, toDir) -> 
            CopyDir toDir fromDir (fun _ -> true))
)

如果我只想复制解决方案文件中显式引用的项目的输出怎么办。我想到了这样的事情:

Target "CopyBinaries" (fun _ ->
    !! solutionFile
    |> GetProjectFiles
    |> Seq.map (fun f -> 
            ((System.IO.Path.GetDirectoryName f) </> "bin/Release", 
             binDir </> (System.IO.Path.GetFileNameWithoutExtension f)))
    |> Seq.iter (fun (fromDir, toDir) -> 
            CopyDir toDir fromDir (fun _ -> true))
)

函数 GetProjectFiles 获取解决方案文件并提取引用的项目文件。

FAKE 中是否有类似的假设功能可用?

我没有发现任何开箱即用的有关解决方案文件的信息。对于少量功能,可以选择替代方案:

let root = directoryInfo "."
let solutionReferences baseDir = baseDir |> filesInDirMatching "*.sln" |> Seq.ofArray
let solutionNames paths = paths |> Seq.map (fun (f:System.IO.FileInfo) -> f.FullName)
let projectsInSolution solutions = solutions |> Seq.collect ReadFile |> Seq.filter (fun line -> line.StartsWith("Project"))
let projectNames projects = projects |> Seq.map (fun (line:string) -> (line.Split [|','|]).[1])
Target "SLN" ( fun () -> root |> solutionReferences |> solutionNames |> projectsInSolution |> projectNames |> Seq.iter (printfn "%s"))

这可以合并,并将功能跳到您喜欢的任何分组中。您可能已经发现了这一点或其他原因,但每个人都知道有选择是件好事。谢谢。日安。

最新更新