Skip to content

Commit 83ec58e

Browse files
committed
wip add flag for multiple package versions
1 parent a600d07 commit 83ec58e

File tree

4 files changed

+144
-1
lines changed

4 files changed

+144
-1
lines changed

Content/.template.config/template.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727
"description": "The target framework of the build project (net6.0 or net7.0). default is net6.0",
2828
"type": "parameter",
2929
"replaces": "{TFM}",
30+
"datatype": "choice",
31+
"choices": [
32+
"net6.0",
33+
"net7.0"
34+
],
3035
"defaultValue": "net6.0"
36+
},
37+
"individuaPackageVersions": {
38+
"description": "If set, the build project will support individual package versions and release notes per project.",
39+
"type": "parameter"
3140
}
3241
}
3342
}

Content/BasicTasks.fs

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,65 @@ let clean = BuildTask.create "Clean" [] {
2424
|> Shell.cleanDirs
2525
}
2626

27+
#if (individuaPackageVersions)
28+
29+
/// builds the solution file (dotnet build solution.sln)
30+
let buildSolution =
31+
BuildTask.create "BuildSolution" [ clean ] {
32+
solutionFile
33+
|> DotNet.build (fun p ->
34+
let msBuildParams =
35+
{p.MSBuildParams with
36+
Properties = ([
37+
"warnon", "3390"
38+
])
39+
}
40+
{
41+
p with
42+
MSBuildParams = msBuildParams
43+
}
44+
)
45+
}
46+
47+
/// builds the individual project files (dotnet build project.*proj)
48+
///
49+
/// The following MSBuild params are set for each project accordingly to the respective ProjectInfo:
50+
///
51+
/// - AssemblyVersion
52+
///
53+
/// - AssemblyInformationalVersion
54+
///
55+
/// - warnon:3390 for xml doc formatting warnings on compilation
56+
let build = BuildTask.create "Build" [clean] {
57+
projects
58+
|> List.iter (fun pInfo ->
59+
let proj = pInfo.ProjFile
60+
proj
61+
|> DotNet.build (fun p ->
62+
let msBuildParams =
63+
{p.MSBuildParams with
64+
Properties = ([
65+
"AssemblyVersion", pInfo.AssemblyVersion
66+
"InformationalVersion", pInfo.AssemblyInformationalVersion
67+
"warnon", "3390"
68+
])
69+
}
70+
{
71+
p with
72+
MSBuildParams = msBuildParams
73+
}
74+
// Use this if you want to speed up your build. Especially helpful in large projects
75+
// Ensure that the order in your project list is correct (e.g. projects that are depended on are built first)
76+
//|> DotNet.Options.withCustomParams (Some "--no-dependencies")
77+
)
78+
)
79+
}
80+
81+
#else
82+
2783
let build = BuildTask.create "Build" [clean] {
2884
solutionFile
2985
|> DotNet.build id
30-
}
86+
}
87+
88+
#endif

Content/ProjectInfo.fs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,70 @@
22

33
open Fake.Core
44

5+
#if (individuaPackageVersions)
6+
7+
/// Contains relevant information about a project (e.g. version info, project location)
8+
type ProjectInfo = {
9+
Name: string
10+
ProjFile: string
11+
ReleaseNotes: ReleaseNotes.ReleaseNotes Option
12+
PackageVersionTag: string
13+
mutable PackagePrereleaseTag: string
14+
AssemblyVersion: string
15+
AssemblyInformationalVersion: string
16+
} with
17+
/// creates a ProjectInfo given a name, project file path, and release notes file path.
18+
/// version info is created from the version header of the uppermost release notes entry.
19+
/// Assembly version is set to X.0.0, where X is the major version from the releas enotes.
20+
static member create(
21+
name: string,
22+
projFile: string,
23+
releaseNotesPath: string
24+
): ProjectInfo =
25+
let release = releaseNotesPath |> ReleaseNotes.load
26+
let stableVersion = release.NugetVersion |> SemVer.parse
27+
let stableVersionTag = $"{stableVersion.Major}.{stableVersion.Minor}.{stableVersion.Patch}"
28+
let assemblyVersion = $"{stableVersion.Major}.0.0"
29+
let assemblyInformationalVersion = stableVersionTag
30+
{
31+
Name = name
32+
ProjFile = projFile
33+
ReleaseNotes = Some release
34+
PackagePrereleaseTag = ""
35+
PackageVersionTag = stableVersionTag
36+
AssemblyVersion = assemblyVersion
37+
AssemblyInformationalVersion = assemblyInformationalVersion
38+
}
39+
static member create(
40+
name: string,
41+
projFile: string
42+
): ProjectInfo =
43+
{
44+
Name = name
45+
ProjFile = projFile
46+
ReleaseNotes = None
47+
PackagePrereleaseTag = ""
48+
PackageVersionTag = ""
49+
AssemblyVersion = ""
50+
AssemblyInformationalVersion = ""
51+
}
52+
53+
let individualProjects =
54+
[
55+
// add relative paths (from project root) to your projects here, including individual reslease notes files
56+
// e.g. ProjectInfo.create("MyProject", "src/MyProject/MyProject.fsproj", "src/MyProject/RELEASE_NOTES.md")
57+
]
58+
59+
#endif
60+
561
let project = "{PROJECTNAME}"
662

763
let testProjects =
864
[
965
// add relative paths (from project root) to your testprojects here
66+
#if (individuaPackageVersions)
67+
// e.g. ProjectInfo.create("MyTestProject", "tests/MyTestProject/MyTestProject.fsproj")
68+
#endif
1069
]
1170

1271
let solutionFile = $"{project}.sln"

Content/TestTasks.fs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@ open Fake.DotNet
66
open ProjectInfo
77
open BasicTasks
88

9+
#if (individuaPackageVersions)
10+
11+
let buildTests =
12+
BuildTask.create "BuildTests" [clean; build] {
13+
testProjects
14+
|> List.iter (fun pInfo ->
15+
let proj = pInfo.ProjFile
16+
proj
17+
|> DotNet.build (fun p ->
18+
p
19+
|> DotNet.Options.withCustomParams (Some "--no-dependencies")
20+
)
21+
)
22+
}
23+
24+
#endif
25+
926
let runTests = BuildTask.create "RunTests" [clean; build] {
1027
testProjects
1128
|> Seq.iter (fun testProject ->

0 commit comments

Comments
 (0)