Skip to content

Commit

Permalink
renew assemblyinfo api
Browse files Browse the repository at this point in the history
  • Loading branch information
matthid committed Jul 26, 2017
1 parent cff217f commit 3dba2f4
Show file tree
Hide file tree
Showing 7 changed files with 188 additions and 102 deletions.
3 changes: 2 additions & 1 deletion FAKE.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26430.6
VisualStudioVersion = 15.0.26430.16
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{06A2CB89-4DFC-4436-AB46-B3E81AFDE294}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -79,6 +79,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "markdown", "markdown", "{B9
help\markdown\fake-migrate-to-fake-5.md = help\markdown\fake-migrate-to-fake-5.md
help\markdown\fake-what-is-fake.md = help\markdown\fake-what-is-fake.md
help\markdown\help-users.md = help\markdown\help-users.md
help\markdown\legacy-assemblyinfo.md = help\markdown\legacy-assemblyinfo.md
help\markdown\legacy-commandline.md = help\markdown\legacy-commandline.md
help\markdown\legacy-core-targets.md = help\markdown\legacy-core-targets.md
help\markdown\legacy-gettingstarted.md = help\markdown\legacy-gettingstarted.md
Expand Down
3 changes: 0 additions & 3 deletions build.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -731,9 +731,6 @@ Target "DotnetPackage" (fun _ ->

// Publish portable as well (see https://docs.microsoft.com/en-us/dotnet/articles/core/app-types)
let netcoreFsproj = "src/app/Fake.netcore/Fake.netcore.fsproj"
let oldContent = File.ReadAllText netcoreFsproj

// File.WriteAllText(netcoreJson, newContent)
let outDir = nugetDir @@ "Fake.netcore" @@ "portable"
DotnetPublish (fun c ->
{ c with
Expand Down
44 changes: 22 additions & 22 deletions help/markdown/dotnet-assemblyinfo.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Generating AssemblyInfo files

**Note: This documentation is for FAKE.exe before version 5 (or the non-netcore version). The documentation needs te be updated, please help! **
**Note: This documentation is for FAKE.exe after version 5. The documentation for previous version (<=4) can be found [here](legacy-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
open Fake.Core

Target.Create "BuildApp" (fun _ ->
AssemblyInfoFile.CreateCSharp "./src/app/Calculator/Properties/AssemblyInfo.cs"
[AssemblyInfo.Title "Calculator Command line tool"
AssemblyInfo.Description "Sample project for FAKE - F# MAKE"
AssemblyInfo.Guid "A539B42C-CB9F-4a23-8E57-AF4E7CEE5BAA"
AssemblyInfo.Product "Calculator"
AssemblyInfo.Version version
AssemblyInfo.FileVersion version]

AssemblyInfoFile.CreateCSharp "./src/app/CalculatorLib/Properties/AssemblyInfo.cs"
[AssemblyInfo.Title "Calculator library"
AssemblyInfo.Description "Sample project for FAKE - F# MAKE"
AssemblyInfo.Guid "EE5621DB-B86B-44eb-987F-9C94BCC98441"
AssemblyInfo.Product "Calculator"
AssemblyInfo.Version version
AssemblyInfo.FileVersion version]

MSBuild.MSBuildRelease buildDir "Build" appReferences
|> Log "AppBuild-Output: "
)

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

And set like this:

Attribute.Metadata("githash", commitHash)
AssemblyInfo.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):

Expand Down
71 changes: 71 additions & 0 deletions help/markdown/legacy-assemblyinfo.md
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")
Loading

0 comments on commit 3dba2f4

Please sign in to comment.