如何分别构建每个项目

How to build each Project separately

我有几个测试项目,其中包含一个同名文件:"loc.xml"。 如果我构建所有测试项目,那么我的 "loc.xml" 每次都会被覆盖。

有没有办法在单独的文件夹中构建每个项目?

实际上我用这个:

Target "BuildUnitTests" (fun _ ->
   trace "Building unit tests..."
   !! @"source\test\**\*.csproj"
     |> MSBuildRelease BuildParams.TestsOutputDir "Rebuild"
     |> Log "AppBuild-Output: "
)

如果您使用 Visual Studio,不同的项目应该自动构建到不同的文件夹中。

但是,您可以在属性中更改每个项目的构建路径(项目属性 -> 构建 -> 输出路径)。

您可以通过从 !! @"source\test\**\*.csproj" 遍历 glob 中的每个项目并指定构建目录作为 MSBuild 的选项来实现此目的。

这是一个非常基本的 build.fsx 文件,它执行以下操作:

  • 通配模式 source/test/**/*.csproj
  • 的所有文件
  • 迭代 glob 并将其发送到解析单元测试文件名的函数
  • 将构建目录设置为bin/PROJECT_NAME
  • 将项目文件发送到 MSBuild 函数,使用参数使其在 Release 模式下构建,输出目录的一个选项。

在你 运行 它之后,你应该在 bin 中有一堆子文件夹,它们的名称与你的单元测试项目名称相似,并且每个构建的工件应该在正确的文件夹中.


#I "packages/FAKE/tools"
#r "FakeLib.dll"

open System.IO
open Fake

let buildProject (projectName : string) =
    // Just setting a release configuration by default...
    let properties = [ ("Configuration", "Release") ]

    let bareName = Path.GetFileNameWithoutExtension(projectName)
    let buildDir = sprintf "bin/%s" bareName
    trace <| sprintf "Building %s" bareName

    // MSBuildHelper's functions all expect a list so you have to pass
    // projectName as part of a list.
    // We are using 'naked' MSBuild so we have to specify all the
    // options/arguments ourselves
    MSBuild buildDir "Rebuild" properties [projectName]
    |> ignore

Target "Build" <| fun () ->
    !! "source/test/**/*.csproj" 
    |> Seq.iter buildProject

Target "All" DoNothing
"Build" ==> "All"

RunTargetOrDefault "All"