【问题标题】:FAKE: Get all projects referenced by a solution fileFAKE:获取解决方案文件引用的所有项目
【发布时间】:2016-01-27 10:02:32
【问题描述】:

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

这里我有一个具体的用例。我从 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 中是否有类似这个假设函数可用?

【问题讨论】:

    标签: f# f#-fake


    【解决方案1】:

    我没有找到开箱即用的解决方案文件的此类信息。使用少量的功能,替代方案是可能的:

    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"))
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-21
      • 2018-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多