Skip to content

Commit 25eb3b1

Browse files
committed
CSHARP-1707: Modify build scripts to also build and test against .NET Core.
1 parent ccb8a0c commit 25eb3b1

File tree

3 files changed

+98
-26
lines changed

3 files changed

+98
-26
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,6 @@ src/packages
5959
artifacts
6060
packages
6161
Tools/FAKE
62+
Tools/FAKE.Dotnet
6263
Tools/xunit.runner.console
6364

build.cmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@echo off
22
Tools\NuGet\NuGet.exe install FAKE -OutputDirectory Tools -ExcludeVersion
3+
Tools\NuGet\NuGet.exe install FAKE.Dotnet -OutputDirectory Tools -ExcludeVersion
34
Tools\NuGet\NuGet.exe install xunit.runner.console -OutputDirectory Tools -ExcludeVersion
45
Tools\FAKE\tools\Fake.exe build\build.fsx %*

build/build.fsx

Lines changed: 96 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
#r @"../Tools/FAKE/tools/FakeLib.dll"
2+
#r @"../Tools/FAKE.Dotnet/tools/Fake.Dotnet.dll"
3+
24
open System
35
open Fake
46
open Fake.AssemblyInfoFile
7+
open Fake.Dotnet
58
open Fake.Testing.XUnit2
69

710
let config = getBuildParamOrDefault "config" "Release"
@@ -31,11 +34,13 @@ let buildDir = baseDir @@ "build"
3134
let landingDocsDir = baseDir @@ "docs" @@ "landing"
3235
let refDocsDir = baseDir @@ "docs" @@ "reference"
3336
let srcDir = baseDir @@ "src"
37+
let testsDir = baseDir @@ "tests"
3438
let toolsDir = baseDir @@ "tools"
3539

3640
let artifactsDir = baseDir @@ "artifacts"
3741
let binDir = artifactsDir @@ "bin"
38-
let binDir45 = binDir @@ "net45"
42+
let binDirNet45 = binDir @@ "net45"
43+
let binDirNetStandard16 = binDir @@ "netstandard16"
3944
let testResultsDir = artifactsDir @@ "test_results"
4045
let tempDir = artifactsDir @@ "tmp"
4146

@@ -46,9 +51,33 @@ let slnFile =
4651

4752
let asmFile = srcDir @@ "MongoDB.Shared" @@ "GlobalAssemblyInfo.cs"
4853
let apiDocsFile = baseDir @@ "Docs" @@ "Api" @@ "CSharpDriverDocs.shfbproj"
49-
let installerFile = baseDir @@ "Installer" @@ "CSharpDriverInstaller.wixproj"
5054
let versionFile = artifactsDir @@ "version.txt"
5155

56+
let dotNetSrcProjects = [
57+
srcDir @@ "MongoDB.Bson.Dotnet" @@ "project.json"
58+
srcDir @@ "MongoDB.Driver.Core.Dotnet" @@ "project.json"
59+
srcDir @@ "MongoDB.Driver.Dotnet" @@ "project.json"
60+
srcDir @@ "MongoDB.Driver.Legacy.Dotnet" @@ "project.json"
61+
srcDir @@ "MongoDB.Driver.GridFS.Dotnet" @@ "project.json"
62+
]
63+
64+
let dotNetTestHelpersProjects = [
65+
testsDir @@ "MongoDB.Bson.TestHelpers.Dotnet" @@ "project.json"
66+
testsDir @@ "MongoDB.Driver.Core.TestHelpers.Dotnet" @@ "project.json"
67+
testsDir @@ "MongoDB.Driver.TestHelpers.Dotnet" @@ "project.json"
68+
testsDir @@ "MongoDB.Driver.Legacy.TestHelpers.Dotnet" @@ "project.json"
69+
]
70+
71+
let dotNetTestProjects = [
72+
testsDir @@ "MongoDB.Bson.Tests.Dotnet" @@ "project.json"
73+
testsDir @@ "MongoDB.Driver.Core.Tests.Dotnet" @@ "project.json"
74+
testsDir @@ "MongoDB.Driver.Tests.Dotnet" @@ "project.json"
75+
testsDir @@ "MongoDB.Driver.Legacy.Tests.Dotnet" @@ "project.json"
76+
testsDir @@ "MongoDB.Driver.GridFS.Tests.Dotnet" @@ "project.json"
77+
]
78+
79+
let dotNetProjects = List.concat [ dotNetSrcProjects; dotNetTestHelpersProjects; dotNetTestProjects ]
80+
5281
type NuspecFile = { File : string; Dependencies : string list; Symbols : bool; }
5382
let nuspecFiles =
5483
[ { File = buildDir @@ "MongoDB.Bson.nuspec"; Dependencies = []; Symbols = true; }
@@ -67,7 +96,7 @@ let apiDocsArtifactZipFile = artifactsDir @@ "ApiDocs-" + semVersion + "-html.zi
6796
let refDocsArtifactZipFile = artifactsDir @@ "RefDocs-" + semVersion + "-html.zip"
6897
let zipArtifactFile = artifactsDir @@ "CSharpDriver-" + semVersion + ".zip"
6998

70-
MSBuildDefaults <- { MSBuildDefaults with Verbosity = Some(Minimal) }
99+
MSBuildDefaults <- { MSBuildDefaults with Verbosity = Some(MSBuildVerbosity.Minimal) }
71100

72101
monoArguments <- "--runtime=v4.0.30319"
73102

@@ -103,7 +132,7 @@ Target "AssemblyInfo" (fun _ ->
103132
AssemblyMetadata = ["githash", githash]})
104133
)
105134

106-
Target "Build" (fun _ ->
135+
Target "BuildNet45" (fun _ ->
107136
!! "./**/packages.config"
108137
|> Seq.iter (RestorePackage (fun x -> { x with OutputPath = baseDir @@ "packages" }))
109138

@@ -115,25 +144,39 @@ Target "Build" (fun _ ->
115144
properties <- properties @ ["DefineConstants", "MONO"]
116145

117146
[slnFile]
118-
|> MSBuild binDir45 "Build" properties
147+
|> MSBuild binDirNet45 "Build" properties
119148
|> Log "Build: "
120149
)
121150

122-
Target "Test" (fun _ ->
123-
if not <| directoryExists binDir45 then new Exception(sprintf "Directory %s does not exist." binDir45) |> raise
151+
Target "InstallDotnet" (fun _ ->
152+
DotnetCliInstall Preview2ToolingOptions
153+
)
154+
155+
Target "BuildNetStandard16" (fun _ ->
156+
for project in dotNetProjects do
157+
DotnetRestore id project
158+
DotnetCompile (fun c ->
159+
{ c with
160+
Configuration = BuildConfiguration.Release
161+
})
162+
project
163+
)
164+
165+
Target "TestNet45" (fun _ ->
166+
if not <| directoryExists binDirNet45 then new Exception(sprintf "Directory %s does not exist." binDirNet45) |> raise
124167
ensureDirectory testResultsDir
125168

126-
let mutable testsDir = !! (binDir45 @@ "*Tests*.dll")
169+
let mutable testDlls = !! (binDirNet45 @@ "*Tests.dll")
127170
if isMono then
128-
testsDir <- testsDir -- (binDir45 @@ "*VB.Tests*.dll")
171+
testDlls <- testDlls -- (binDirNet45 @@ "*VB.Tests.dll")
129172

130173
let resultsOutputPath = testResultsDir @@ (getBuildParamOrDefault "testResults" "test-results.xml")
131174
let includeTraits =
132175
match getBuildParamOrDefault "Category" "" with
133176
| "" -> []
134177
| category -> [("Category", category)]
135178

136-
testsDir
179+
testDlls
137180
|> xUnit2 (fun p ->
138181
{ p with
139182
ErrorLevel = TestRunnerErrorLevel.Error
@@ -144,6 +187,13 @@ Target "Test" (fun _ ->
144187
})
145188
)
146189

190+
Target "TestNetStandard16" (fun _ ->
191+
for project in dotNetTestProjects do
192+
let args = sprintf "test %s" project
193+
let result = Dotnet DotnetOptions.Default args
194+
if not result.OK then failwithf "dotnet test failed with code %i" result.ExitCode
195+
)
196+
147197
Target "RefDocs" (fun _ ->
148198
DeleteFile refDocsArtifactZipFile
149199
ensureDirectory tempDir
@@ -188,7 +238,7 @@ Target "ApiDocs" (fun _ ->
188238
"HelpFileVersion", version]
189239

190240
[apiDocsFile]
191-
|> MSBuild binDir45 "" properties
241+
|> MSBuild binDirNet45 "" properties
192242
|> Log "Docs: "
193243

194244
Rename apiDocsArtifactFile (tempDir @@ "CSharpDriverDocs.chm")
@@ -208,21 +258,21 @@ Target "Zip" (fun _ ->
208258
checkFileExists releaseNotesFile
209259

210260
let files =
211-
[ binDir45 @@ "MongoDB.Bson.dll"
212-
binDir45 @@ "MongoDB.Bson.pdb"
213-
binDir45 @@ "MongoDB.Bson.xml"
214-
binDir45 @@ "MongoDB.Driver.Core.dll"
215-
binDir45 @@ "MongoDB.Driver.Core.pdb"
216-
binDir45 @@ "MongoDB.Driver.Core.xml"
217-
binDir45 @@ "MongoDB.Driver.dll"
218-
binDir45 @@ "MongoDB.Driver.pdb"
219-
binDir45 @@ "MongoDB.Driver.xml"
220-
binDir45 @@ "MongoDB.Driver.GridFS.dll"
221-
binDir45 @@ "MongoDB.Driver.GridFS.pdb"
222-
binDir45 @@ "MongoDB.Driver.GridFS.xml"
223-
binDir45 @@ "MongoDB.Driver.Legacy.dll"
224-
binDir45 @@ "MongoDB.Driver.Legacy.pdb"
225-
binDir45 @@ "MongoDB.Driver.Legacy.xml"
261+
[ binDirNet45 @@ "MongoDB.Bson.dll"
262+
binDirNet45 @@ "MongoDB.Bson.pdb"
263+
binDirNet45 @@ "MongoDB.Bson.xml"
264+
binDirNet45 @@ "MongoDB.Driver.Core.dll"
265+
binDirNet45 @@ "MongoDB.Driver.Core.pdb"
266+
binDirNet45 @@ "MongoDB.Driver.Core.xml"
267+
binDirNet45 @@ "MongoDB.Driver.dll"
268+
binDirNet45 @@ "MongoDB.Driver.pdb"
269+
binDirNet45 @@ "MongoDB.Driver.xml"
270+
binDirNet45 @@ "MongoDB.Driver.GridFS.dll"
271+
binDirNet45 @@ "MongoDB.Driver.GridFS.pdb"
272+
binDirNet45 @@ "MongoDB.Driver.GridFS.xml"
273+
binDirNet45 @@ "MongoDB.Driver.Legacy.dll"
274+
binDirNet45 @@ "MongoDB.Driver.Legacy.pdb"
275+
binDirNet45 @@ "MongoDB.Driver.Legacy.xml"
226276
licenseFile
227277
releaseNotesFile
228278
apiDocsArtifactFile ]
@@ -283,11 +333,31 @@ Target "NoOp" DoNothing
283333
Target "Docs" DoNothing
284334
Target "Package" DoNothing
285335
Target "Publish" DoNothing
336+
Target "Build" DoNothing
337+
Target "Test" DoNothing
286338

287339
"Clean"
288340
==> "AssemblyInfo"
341+
342+
"AssemblyInfo"
343+
==> "BuildNet45"
344+
345+
"AssemblyInfo"
346+
==> "InstallDotnet"
347+
==> "BuildNetStandard16"
348+
349+
"BuildNet45"
289350
==> "Build"
290351

352+
"BuildNetStandard16"
353+
==> "Build"
354+
355+
"TestNet45"
356+
==> "Test"
357+
358+
"TestNetStandard16"
359+
==> "Test"
360+
291361
"RefDocs"
292362
==> "ApiDocs"
293363
==> "Docs"

0 commit comments

Comments
 (0)