You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: help/markdown/fake-fake5-modules.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ Please read introduction about [Paket](https://fsprojects.github.io/Paket/) for
47
47
48
48
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.
49
49
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).
51
51
> However, to be fully compatible with existing tooling and infrastructure make sure to add `//` at the end of the `#r` string.
52
52
> See https://github.com/fsharp/FAKE/pull/1770 for details.
53
53
@@ -61,7 +61,7 @@ To reference a FAKE group explicitely you can put the following at the top of yo
61
61
```
62
62
63
63
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.
65
65
66
66
The last line `#load` is not required by FAKE 5, however
67
67
this way the file can still be edited in editors (after restoring packages initially).
Copy file name to clipboardExpand all lines: help/markdown/fake-gettingstarted.md
+257-2Lines changed: 257 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -55,6 +55,261 @@ Where you can add all the [fake modules](fake-fake5-modules.html) you need.
55
55
56
56
> 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.
57
57
58
-
## TBD.
58
+
## Example - Compiling and building your .NET application
59
59
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
+

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
+

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:
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:
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.
0 commit comments