当我执行“构建解决方案”(Ctrl + F6)时,我正在寻找一个可以调用我的FAKE构建脚本的解决方案。奖励指向指定非默认目标的方式。
答案 0 :(得分:6)
我到目前为止最接近的是通过
将FAKE定义为外部工具 Tools -> External tools...
将其设置为使用输出窗口并提示参数。然后,通过
定义键盘快捷键 Tools -> Options -> Environment -> Keyboard -> Tools.ExternalCommand6
调用它时,您可以提供目标,或者只需按Enter键即可构建默认值。
答案 1 :(得分:6)
我以另一种方式解决了这个问题。它需要手动编辑csproj文件,其技巧在于内置Build
,Clean
和Rebuild
目标的条件覆盖。
首先,我创建了自定义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"