gpt4 book ai didi

visual-studio - 如何让 Visual Studio 使用 FAKE 来构建我的解决方案?

转载 作者:行者123 更新时间:2023-12-04 02:01:54 26 4
gpt4 key购买 nike

我正在寻找一种在执行“构建解决方案”(Ctrl + F6)时调用我的 FAKE 构建脚本的解决方案。指定默认目标以外的目标的方法的奖励积分。

最佳答案

我用另一种方式解决了这个问题。它需要手动编辑 csproj 文件,诀窍在于有条件地覆盖内置 Build , CleanRebuild目标。

首先我创建了自定义 fake.targets文件并将其保存在 Targets解决方案级别的文件夹:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Exec Command="packages\FAKE\tools\FAKE.exe build.fsx Build proj=$(ProjectPath) conf=$(Configuration) plat=$(Platform)" WorkingDirectory="..\" />
</Target>

<Target Name="Rebuild">
<Exec Command="packages\FAKE\tools\FAKE.exe build.fsx Rebuild proj=$(ProjectPath) conf=$(Configuration) plat=$(Platform)" WorkingDirectory="..\" />
</Target>

<Target Name="Clean">
<Exec Command="packages\FAKE\tools\FAKE.exe build.fsx Clean proj=$(ProjectPath) conf=$(Configuration) plat=$(Platform)" WorkingDirectory="..\" />
</Target>
</Project>

接下来,在 <Project />底部每个部分 *.csproj我添加的项目文件:

<PropertyGroup>
<FakeTargetsPath>..\Targets\fake.targets</FakeTargetsPath>
</PropertyGroup>
<Import Project="$(FakeTargetsPath)" Condition="Exists($(FakeTargetsPath)) And '$(RealBuild)'!='true'" />

注: FakeTargetsPath相对于 csproj文件。

最后一步是创建 build.fsx使用 RealBuild = true 调用 MSBuild :

#r @"packages/FAKE/tools/FakeLib.dll"
open Fake

let solution = "solution.sln"

let commonBuild target =
let project = getBuildParamOrDefault "proj" solution
let configuration = getBuildParamOrDefault "conf" "Release"
let platform = getBuildParamOrDefault "plat" "AnyCPU"
let setParams defaults =
{ defaults with
Verbosity = Some(Quiet)
Targets = [ target ]
Properties =
[
"Configuration", configuration
"Platform", platform
"RealBuild", "true"
]
}

build setParams project

Target "Build" (fun _ ->
commonBuild "Build"
)

Target "Clean" (fun _ ->
commonBuild "Clean"
)

Target "Rebuild" (fun _ ->
commonBuild "Rebuild"
)

RunTargetOrDefault "Build"

关于visual-studio - 如何让 Visual Studio 使用 FAKE 来构建我的解决方案?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30218608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com