Skip to content

Commit a982f1a

Browse files
committed
Bump version to 5.0.0-beta013
1 parent eeced8f commit a982f1a

File tree

3 files changed

+260
-5
lines changed

3 files changed

+260
-5
lines changed

help/markdown/fake-dotnetcore.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ The disadvantage is that you need to have a dotnet sdk installed.
7474
Create a file named `build.fsx` with the following contents:
7575
```fsharp
7676
#r "paket:
77-
nuget Fake.Core.Target"
77+
nuget Fake.Core.Target //"
7878
// include Fake modules, see Fake modules section
7979
8080
open Fake.Core

help/markdown/fake-fake5-modules.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Please read introduction about [Paket](https://fsprojects.github.io/Paket/) for
4747

4848
To be more independent from paket infrastructure (stand-alone-scripts and similar situations) there is a way to specify dependencies from within the script itself.
4949

50-
> We use the new syntax specified in https://github.com/fsharp/fslang-design/blob/master/tooling/FST-1027-fsi-references.md
50+
> We use the new syntax specified in [FST-1027](https://github.com/fsharp/fslang-design/blob/master/tooling/FST-1027-fsi-references.md).
5151
> However, to be fully compatible with existing tooling and infrastructure make sure to add `//` at the end of the `#r` string.
5252
> See https://github.com/fsharp/FAKE/pull/1770 for details.
5353
@@ -61,7 +61,7 @@ To reference a FAKE group explicitely you can put the following at the top of yo
6161
```
6262

6363

64-
This header will reference a `paket.dependencies` file and the `netcorebuild` group within.
64+
This header will reference the `paket.dependencies` file and the `netcorebuild` group within.
6565

6666
The last line `#load` is not required by FAKE 5, however
6767
this way the file can still be edited in editors (after restoring packages initially).

help/markdown/fake-gettingstarted.md

Lines changed: 257 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,261 @@ Where you can add all the [fake modules](fake-fake5-modules.html) you need.
5555
5656
> Note: Intellisense is shown for the full framework while the script is run as `netcoreapp20` therefore intellisense might show APIs which are not actually usable.
5757
58-
## TBD.
58+
## Example - Compiling and building your .NET application
5959

60-
The best way is currently to use the [quick start guide](fake-dotnetcore.html)
60+
### Getting started
61+
62+
Now open the *build.fsx* in Visual Studio or any text editor. It should look like this:
63+
64+
// include Fake lib
65+
#r @"packages/FAKE/tools/FakeLib.dll"
66+
open Fake
67+
68+
// Default target
69+
Target "Default" (fun _ ->
70+
trace "Hello World from FAKE"
71+
)
72+
73+
// start build
74+
RunTargetOrDefault "Default"
75+
76+
77+
As you can see the code is really simple. The first line includes the FAKE library and is vital for all FAKE build scripts.
78+
79+
After this header the *Default* target is defined. A target definition contains two important parts. The first is the name of the target (here "Default") and the second is an action (here a simple trace of "Hello world").
80+
81+
The last line runs the "Default" target - which means it executes the defined action of the target.
82+
83+
### Cleaning the last build output
84+
85+
A typical first step in most build scenarios is to clean the output of the last build. We can achieve this by modifying the *build.fsx* to the following:
86+
87+
// include Fake lib
88+
#r "packages/FAKE/tools/FakeLib.dll"
89+
open Fake
90+
91+
// Properties
92+
let buildDir = "./build/"
93+
94+
// Targets
95+
Target "Clean" (fun _ ->
96+
CleanDir buildDir
97+
)
98+
99+
Target "Default" (fun _ ->
100+
trace "Hello World from FAKE"
101+
)
102+
103+
// Dependencies
104+
"Clean"
105+
==> "Default"
106+
107+
// start build
108+
RunTargetOrDefault "Default"
109+
110+
We introduced some new concepts in this snippet. At first we defined a global property called "buildDir" with the relative path of a temporary build folder.
111+
112+
In the *Clean* target we use the CleanDir task to clean up this build directory. This simply deletes all files in the folder or creates the directory if necessary.
113+
114+
In the dependencies section we say that the *Default* target has a dependency on the *Clean* target. In other words *Clean* is a prerequisite of *Default* and will be run before the execution of *Default*:
115+
116+
![alt text](pics/gettingstarted/afterclean.png "We introduced a Clean target")
117+
118+
### Compiling the application
119+
120+
In the next step we want to compile our C# libraries, which means we want to compile all csproj-files under */src/app* with MSBuild:
121+
122+
// include Fake lib
123+
#r "packages/FAKE/tools/FakeLib.dll"
124+
open Fake
125+
126+
// Properties
127+
let buildDir = "./build/"
128+
129+
// Targets
130+
Target "Clean" (fun _ ->
131+
CleanDir buildDir
132+
)
133+
134+
Target "BuildApp" (fun _ ->
135+
!! "src/app/**/*.csproj"
136+
|> MSBuildRelease buildDir "Build"
137+
|> Log "AppBuild-Output: "
138+
)
139+
140+
Target "Default" (fun _ ->
141+
trace "Hello World from FAKE"
142+
)
143+
144+
// Dependencies
145+
"Clean"
146+
==> "BuildApp"
147+
==> "Default"
148+
149+
// start build
150+
RunTargetOrDefault "Default"
151+
152+
We defined a new build target named "BuildApp" which compiles all csproj-files with the MSBuild task and the build output will be copied to buildDir.
153+
154+
In order to find the right project files FAKE scans the folder *src/app/* and all subfolders with the given pattern. Therefore a similar FileSet definition like in NAnt or MSBuild (see [project page](https://github.com/fsharp/FAKE) for details) is used.
155+
156+
In addition the target dependencies are extended again. Now *Default* is dependent on *BuildApp* and *BuildApp* needs *Clean* as a prerequisite.
157+
158+
This means the execution order is: Clean ==> BuildApp ==> Default.
159+
160+
![alt text](pics/gettingstarted/aftercompile.png "We introduced a Build target")
161+
162+
### Compiling test projects
163+
164+
Now our main application will be built automatically and it's time to build the test project. We use the same concepts as before:
165+
166+
// include Fake lib
167+
#r "packages/FAKE/tools/FakeLib.dll"
168+
open Fake
169+
170+
// Properties
171+
let buildDir = "./build/"
172+
let testDir = "./test/"
173+
174+
// Targets
175+
Target "Clean" (fun _ ->
176+
CleanDirs [buildDir; testDir]
177+
)
178+
179+
Target "BuildApp" (fun _ ->
180+
!! "src/app/**/*.csproj"
181+
|> MSBuildRelease buildDir "Build"
182+
|> Log "AppBuild-Output: "
183+
)
184+
185+
Target "BuildTest" (fun _ ->
186+
!! "src/test/**/*.csproj"
187+
|> MSBuildDebug testDir "Build"
188+
|> Log "TestBuild-Output: "
189+
)
190+
191+
Target "Default" (fun _ ->
192+
trace "Hello World from FAKE"
193+
)
194+
195+
// Dependencies
196+
"Clean"
197+
==> "BuildApp"
198+
==> "BuildTest"
199+
==> "Default"
200+
201+
// start build
202+
RunTargetOrDefault "Default"
203+
204+
This time we defined a new target "BuildTest" which compiles all C# projects below *src/test/* in Debug mode and we put the target into our build order.
205+
206+
If we run build.bat again we get an error like this:
207+
208+
![alt text](pics/gettingstarted/compileerror.png "Compile error")
209+
210+
The problem is that we didn't download the NUnit package from nuget. So let's fix this in the build script:
211+
212+
// include Fake lib
213+
#r "packages/FAKE/tools/FakeLib.dll"
214+
open Fake
215+
216+
RestorePackages()
217+
// ...
218+
219+
With this simple command FAKE will use nuget.exe to install all the package dependencies.
220+
221+
You may experience this tutorial not quite working with the newest package versions. In this case you can edit the [`paket.dependencies` file](http://fsprojects.github.io/Paket/dependencies-file.html) to something like this:
222+
223+
source https://nuget.org/api/v2
224+
225+
nuget FAKE
226+
227+
http https://dist.nuget.org/win-x86-commandline/latest/nuget.exe NuGet/nuget.exe
228+
229+
nuget NUnit ~> 2.5.10
230+
231+
Again run Paket from the command line:
232+
233+
$ .paket/paket.exe install
234+
235+
This will fetch nuget.exe from nuget.org and also download an early version of NUnit that contains the NUnit runner. The edit to [`paket.dependencies`](http://fsprojects.github.io/Paket/dependencies-file.html) does not replace the RestorePackages() step. The NUnit.Test.CalculatorLib test project references the NUnit version 2.6.2 library, so we need that version too.
236+
237+
### Running the tests with NUnit
238+
239+
Now all our projects will be compiled and we can use FAKE's NUnit task in order to let NUnit test our assembly:
240+
241+
// include Fake lib
242+
#r "packages/FAKE/tools/FakeLib.dll"
243+
open Fake
244+
245+
RestorePackages()
246+
247+
// Properties
248+
let buildDir = "./build/"
249+
let testDir = "./test/"
250+
251+
// Targets
252+
Target "Clean" (fun _ ->
253+
CleanDirs [buildDir; testDir]
254+
)
255+
256+
Target "BuildApp" (fun _ ->
257+
!! "src/app/**/*.csproj"
258+
|> MSBuildRelease buildDir "Build"
259+
|> Log "AppBuild-Output: "
260+
)
261+
262+
Target "BuildTest" (fun _ ->
263+
!! "src/test/**/*.csproj"
264+
|> MSBuildDebug testDir "Build"
265+
|> Log "TestBuild-Output: "
266+
)
267+
268+
Target "Test" (fun _ ->
269+
!! (testDir + "/NUnit.Test.*.dll")
270+
|> NUnit (fun p ->
271+
{p with
272+
DisableShadowCopy = true;
273+
OutputFile = testDir + "TestResults.xml" })
274+
)
275+
276+
Target "Default" (fun _ ->
277+
trace "Hello World from FAKE"
278+
)
279+
280+
// Dependencies
281+
"Clean"
282+
==> "BuildApp"
283+
==> "BuildTest"
284+
==> "Test"
285+
==> "Default"
286+
287+
// start build
288+
RunTargetOrDefault "Default"
289+
290+
Our new *Test* target scans the test directory for test assemblies and runs them with the NUnit runner. FAKE automatically tries to locate the runner in one of your subfolders. See the [NUnit task documentation](apidocs/fake-nunitsequential.html) if you need to specify the tool path explicitly.
291+
292+
The mysterious part **(fun p -> ...)** simply overrides the default parameters of the NUnit task and allows to specify concrete parameters.
293+
294+
![alt text](pics/gettingstarted/alltestsgreen.png "All tests green")
295+
296+
Alternatively you could also run the tests in parallel using the [NUnitParallel](apidocs/fake-nunitparallel.html) task:
297+
298+
Target "Test" (fun _ ->
299+
!! (testDir + "/NUnit.Test.*.dll")
300+
|> NUnitParallel (fun p ->
301+
{p with
302+
DisableShadowCopy = true;
303+
OutputFile = testDir + "TestResults.xml" })
304+
)
305+
306+
307+
308+
## What's next?
309+
310+
- look at the [quick start guide](fake-dotnetcore.html) which has the same information in a more dense form.
311+
- Take a look at the various fake modules which basically have most of your use-cases covered.
312+
- Add fake build scripts to your projects and let us know.
313+
- Automate stuff with FAKE and use standalone scripts.
314+
- Write your own modules and let us know.
315+
- Contribute :)

0 commit comments

Comments
 (0)