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.
Build Solution - compiles code files (dll and exe) that have changed. Rebuild Solution - Deletes all compiled files and Compiles them again regardless of whether or not the code has changed.
You can hit Ctrl + Break on the keyboard to cancel/stop a build that is currently in progress.
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.
First I created custom fake.targets
file and saved it in Targets
folder at the solution level:
<?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:
<PropertyGroup>
<FakeTargetsPath>..\Targets\fake.targets</FakeTargetsPath>
</PropertyGroup>
<Import Project="$(FakeTargetsPath)" Condition="Exists($(FakeTargetsPath)) And '$(RealBuild)'!='true'" />
Note: FakeTargetsPath
is relative to the csproj
file.
Last step was to create build.fsx
that invokes MSBuild with RealBuild = true
:
#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"
The closest I found so far is to define FAKE as an external tool via
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With