-
Notifications
You must be signed in to change notification settings - Fork 585
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
188 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Generating AssemblyInfo files | ||
|
||
**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)! ** | ||
|
||
In this article the AssemblyInfo task is used in order to set specific version information to .NET assemblies. | ||
|
||
If you succeeded with the [Getting Started tutorial](gettingstarted.html), then you just have to modify your *BuildApp* target to the following: | ||
|
||
open Fake.AssemblyInfoFile | ||
|
||
Target "BuildApp" (fun _ -> | ||
CreateCSharpAssemblyInfo "./src/app/Calculator/Properties/AssemblyInfo.cs" | ||
[Attribute.Title "Calculator Command line tool" | ||
Attribute.Description "Sample project for FAKE - F# MAKE" | ||
Attribute.Guid "A539B42C-CB9F-4a23-8E57-AF4E7CEE5BAA" | ||
Attribute.Product "Calculator" | ||
Attribute.Version version | ||
Attribute.FileVersion version] | ||
|
||
CreateCSharpAssemblyInfo "./src/app/CalculatorLib/Properties/AssemblyInfo.cs" | ||
[Attribute.Title "Calculator library" | ||
Attribute.Description "Sample project for FAKE - F# MAKE" | ||
Attribute.Guid "EE5621DB-B86B-44eb-987F-9C94BCC98441" | ||
Attribute.Product "Calculator" | ||
Attribute.Version version | ||
Attribute.FileVersion version] | ||
|
||
MSBuildRelease buildDir "Build" appReferences | ||
|> Log "AppBuild-Output: " | ||
) | ||
|
||
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). | ||
|
||
## Setting the version no. | ||
|
||
The version parameter can be declared as a property or fetched from a build server like TeamCity: | ||
|
||
let version = | ||
match buildServer with | ||
| TeamCity -> buildVersion | ||
| _ -> "0.2" | ||
|
||
![alt text](pics/assemblyinfo/result.png "The file version is set by FAKE") | ||
|
||
## Storing the githash in the AssemblyInfo | ||
|
||
Storing the githash with the assembly can make it easier to identify exactly what code is running. There isn't an attribute that | ||
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) | ||
|
||
If your solution is inside a git repository you can get the git hash like this (remember to `open Fake.Git`): | ||
|
||
let commitHash = Information.getCurrentHash() | ||
|
||
And set like this: | ||
|
||
Attribute.Metadata("githash", commitHash) | ||
|
||
One of the easiest ways to retrieve this hash is to load use a reflector program, like [ILSpy](https://github.com/icsharpcode/ILSpy): | ||
|
||
![alt text](pics/assemblyinfo/assemblymetadata.png "Checking the git hash of an assembly") | ||
|
||
## Using the SolutionInfo approach | ||
|
||
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. | ||
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: | ||
|
||
![alt text](pics/assemblyinfo/solutioninfo.png "SolutionInfo.cs is shared between projects") | ||
|
||
The generated SolutionInfo.cs looks like this: | ||
|
||
![alt text](pics/assemblyinfo/generated.png "Generated SolutionInfo.cs") |
Oops, something went wrong.