Skip to content

Commit 4c00c87

Browse files
committed
renew assemblyinfo api
1 parent b791c1c commit 4c00c87

File tree

6 files changed

+186
-101
lines changed

6 files changed

+186
-101
lines changed

build.fsx

-3
Original file line numberDiff line numberDiff line change
@@ -750,9 +750,6 @@ Target "DotnetPackage" (fun _ ->
750750

751751
// Publish portable as well (see https://docs.microsoft.com/en-us/dotnet/articles/core/app-types)
752752
let netcoreFsproj = "src/app/Fake.netcore/Fake.netcore.fsproj"
753-
let oldContent = File.ReadAllText netcoreFsproj
754-
755-
// File.WriteAllText(netcoreJson, newContent)
756753
let outDir = nugetDir @@ "Fake.netcore" @@ "portable"
757754
DotnetPublish (fun c ->
758755
{ c with

help/markdown/dotnet-assemblyinfo.md

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
# Generating AssemblyInfo files
22

3-
**Note: This documentation is for FAKE.exe before version 5 (or the non-netcore version). The documentation needs te be updated, please help! **
3+
**Note: This documentation is for FAKE.exe after version 5. The documentation for previous version (<=4) can be found [here](legacy-assemblyinfo.html)! **
44

55
In this article the AssemblyInfo task is used in order to set specific version information to .NET assemblies.
66

77
If you succeeded with the [Getting Started tutorial](gettingstarted.html), then you just have to modify your *BuildApp* target to the following:
88

9-
open Fake.AssemblyInfoFile
10-
11-
Target "BuildApp" (fun _ ->
12-
CreateCSharpAssemblyInfo "./src/app/Calculator/Properties/AssemblyInfo.cs"
13-
[Attribute.Title "Calculator Command line tool"
14-
Attribute.Description "Sample project for FAKE - F# MAKE"
15-
Attribute.Guid "A539B42C-CB9F-4a23-8E57-AF4E7CEE5BAA"
16-
Attribute.Product "Calculator"
17-
Attribute.Version version
18-
Attribute.FileVersion version]
19-
20-
CreateCSharpAssemblyInfo "./src/app/CalculatorLib/Properties/AssemblyInfo.cs"
21-
[Attribute.Title "Calculator library"
22-
Attribute.Description "Sample project for FAKE - F# MAKE"
23-
Attribute.Guid "EE5621DB-B86B-44eb-987F-9C94BCC98441"
24-
Attribute.Product "Calculator"
25-
Attribute.Version version
26-
Attribute.FileVersion version]
27-
28-
MSBuildRelease buildDir "Build" appReferences
9+
open Fake.Core
10+
11+
Target.Create "BuildApp" (fun _ ->
12+
AssemblyInfoFile.CreateCSharp "./src/app/Calculator/Properties/AssemblyInfo.cs"
13+
[AssemblyInfo.Title "Calculator Command line tool"
14+
AssemblyInfo.Description "Sample project for FAKE - F# MAKE"
15+
AssemblyInfo.Guid "A539B42C-CB9F-4a23-8E57-AF4E7CEE5BAA"
16+
AssemblyInfo.Product "Calculator"
17+
AssemblyInfo.Version version
18+
AssemblyInfo.FileVersion version]
19+
20+
AssemblyInfoFile.CreateCSharp "./src/app/CalculatorLib/Properties/AssemblyInfo.cs"
21+
[AssemblyInfo.Title "Calculator library"
22+
AssemblyInfo.Description "Sample project for FAKE - F# MAKE"
23+
AssemblyInfo.Guid "EE5621DB-B86B-44eb-987F-9C94BCC98441"
24+
AssemblyInfo.Product "Calculator"
25+
AssemblyInfo.Version version
26+
AssemblyInfo.FileVersion version]
27+
28+
MSBuild.MSBuildRelease buildDir "Build" appReferences
2929
|> Log "AppBuild-Output: "
3030
)
3131

@@ -53,7 +53,7 @@ If your solution is inside a git repository you can get the git hash like this (
5353

5454
And set like this:
5555

56-
Attribute.Metadata("githash", commitHash)
56+
AssemblyInfo.Metadata("githash", commitHash)
5757

5858
One of the easiest ways to retrieve this hash is to load use a reflector program, like [ILSpy](https://github.com/icsharpcode/ILSpy):
5959

help/markdown/legacy-assemblyinfo.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Generating AssemblyInfo files
2+
3+
**Note: This documentation is for FAKE.exe before version 5 (or the non-netcore version). The documentation for FAKE 5 can be found [here](dotnet-assemblyinfo.html)! **
4+
5+
In this article the AssemblyInfo task is used in order to set specific version information to .NET assemblies.
6+
7+
If you succeeded with the [Getting Started tutorial](gettingstarted.html), then you just have to modify your *BuildApp* target to the following:
8+
9+
open Fake.AssemblyInfoFile
10+
11+
Target "BuildApp" (fun _ ->
12+
CreateCSharpAssemblyInfo "./src/app/Calculator/Properties/AssemblyInfo.cs"
13+
[Attribute.Title "Calculator Command line tool"
14+
Attribute.Description "Sample project for FAKE - F# MAKE"
15+
Attribute.Guid "A539B42C-CB9F-4a23-8E57-AF4E7CEE5BAA"
16+
Attribute.Product "Calculator"
17+
Attribute.Version version
18+
Attribute.FileVersion version]
19+
20+
CreateCSharpAssemblyInfo "./src/app/CalculatorLib/Properties/AssemblyInfo.cs"
21+
[Attribute.Title "Calculator library"
22+
Attribute.Description "Sample project for FAKE - F# MAKE"
23+
Attribute.Guid "EE5621DB-B86B-44eb-987F-9C94BCC98441"
24+
Attribute.Product "Calculator"
25+
Attribute.Version version
26+
Attribute.FileVersion version]
27+
28+
MSBuildRelease buildDir "Build" appReferences
29+
|> Log "AppBuild-Output: "
30+
)
31+
32+
As you can see generating an AssemblyInfo.cs file is pretty easy with FAKE. You can read more about the C# and F# AssemblyInfo tasks in the [API docs](apidocs/fake-assemblyinfofile.html).
33+
34+
## Setting the version no.
35+
36+
The version parameter can be declared as a property or fetched from a build server like TeamCity:
37+
38+
let version =
39+
match buildServer with
40+
| TeamCity -> buildVersion
41+
| _ -> "0.2"
42+
43+
![alt text](pics/assemblyinfo/result.png "The file version is set by FAKE")
44+
45+
## Storing the githash in the AssemblyInfo
46+
47+
Storing the githash with the assembly can make it easier to identify exactly what code is running. There isn't an attribute that
48+
directly fits with doing this, but one way is by storing it as Metadata (warning: this attribute is only available in .NET 4.5 and above)
49+
50+
If your solution is inside a git repository you can get the git hash like this (remember to `open Fake.Git`):
51+
52+
let commitHash = Information.getCurrentHash()
53+
54+
And set like this:
55+
56+
Attribute.Metadata("githash", commitHash)
57+
58+
One of the easiest ways to retrieve this hash is to load use a reflector program, like [ILSpy](https://github.com/icsharpcode/ILSpy):
59+
60+
![alt text](pics/assemblyinfo/assemblymetadata.png "Checking the git hash of an assembly")
61+
62+
## Using the SolutionInfo approach
63+
64+
Some companies split their AssemblyInfo into a SolutionInfo.cs which is shared by all projects and a specific AssemblyInfo per project which contains the product data.
65+
All versioning data is generated by the AssemblyInfo task into the SolutionInfo.cs and the AssemblyInfo files are edited manually. This could look like this:
66+
67+
![alt text](pics/assemblyinfo/solutioninfo.png "SolutionInfo.cs is shared between projects")
68+
69+
The generated SolutionInfo.cs looks like this:
70+
71+
![alt text](pics/assemblyinfo/generated.png "Generated SolutionInfo.cs")

0 commit comments

Comments
 (0)