I'm looking for a solution that invokes my FAKE build script when I do a "Build Solution" (Ctrl + F6). Bonus points for a way to specify a target other than the default.
我正在寻找一种解决方案,当我执行“构建解决方案”(Ctrl + F6)时调用我的FAKE构建脚本。奖励指向指定默认目标以外的目标的方式。
2 个解决方案
#1
The closest I found so far is to define FAKE as an external tool via
到目前为止我发现的最接近的是将FAKE定义为外部工具
Tools -> External tools...
Set it to use the output window and to prompt for arguments. Then, define a keyboard shortcut via
将其设置为使用输出窗口并提示参数。然后,通过定义键盘快捷键
Tools -> Options -> Environment -> Keyboard -> Tools.ExternalCommand6
When you invoke it you can provide a target or just press enter to build the default.
当您调用它时,您可以提供目标,或者只需按Enter键即可构建默认值。
#2
I solved this problem in another way. It requires manual edit of csproj files and the trick is in conditional override of builtin Build
, Clean
and Rebuild
targets.
我用另一种方式解决了这个问题。它需要手动编辑csproj文件,其技巧在于内置的Build,Clean和Rebuild目标的条件覆盖。
First I created custom fake.targets
file and saved it in Targets
folder at the solution level:
首先,我创建了自定义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>
Next, at the bottom of <Project />
section in each *.csproj
project file I added:
接下来,在每个* .csproj项目文件的
<PropertyGroup>
<FakeTargetsPath>..\Targets\fake.targets</FakeTargetsPath>
</PropertyGroup>
<Import Project="$(FakeTargetsPath)" Condition="Exists($(FakeTargetsPath)) And '$(RealBuild)'!='true'" />
Note: FakeTargetsPath
is relative to the csproj
file.
注意:FakeTargetsPath是相对于csproj文件的。
Last step was to create build.fsx
that invokes MSBuild with RealBuild = true
:
最后一步是创建使用RealBuild = true调用MSBuild的build.fsx:
#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"
#1
The closest I found so far is to define FAKE as an external tool via
到目前为止我发现的最接近的是将FAKE定义为外部工具
Tools -> External tools...
Set it to use the output window and to prompt for arguments. Then, define a keyboard shortcut via
将其设置为使用输出窗口并提示参数。然后,通过定义键盘快捷键
Tools -> Options -> Environment -> Keyboard -> Tools.ExternalCommand6
When you invoke it you can provide a target or just press enter to build the default.
当您调用它时,您可以提供目标,或者只需按Enter键即可构建默认值。
#2
I solved this problem in another way. It requires manual edit of csproj files and the trick is in conditional override of builtin Build
, Clean
and Rebuild
targets.
我用另一种方式解决了这个问题。它需要手动编辑csproj文件,其技巧在于内置的Build,Clean和Rebuild目标的条件覆盖。
First I created custom fake.targets
file and saved it in Targets
folder at the solution level:
首先,我创建了自定义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>
Next, at the bottom of <Project />
section in each *.csproj
project file I added:
接下来,在每个* .csproj项目文件的
<PropertyGroup>
<FakeTargetsPath>..\Targets\fake.targets</FakeTargetsPath>
</PropertyGroup>
<Import Project="$(FakeTargetsPath)" Condition="Exists($(FakeTargetsPath)) And '$(RealBuild)'!='true'" />
Note: FakeTargetsPath
is relative to the csproj
file.
注意:FakeTargetsPath是相对于csproj文件的。
Last step was to create build.fsx
that invokes MSBuild with RealBuild = true
:
最后一步是创建使用RealBuild = true调用MSBuild的build.fsx:
#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"