Skip to content
This repository has been archived by the owner on Dec 2, 2021. It is now read-only.
/ Fody.Stamp Public archive

:octocat: Stamps an assembly with git data

License

Notifications You must be signed in to change notification settings

304NotModified/Fody.Stamp

Repository files navigation

NuGet Status Build status

Icon

This is an add-in for Fody

Stamps an assembly with git data.

The nuget package

https://nuget.org/packages/Stamp.Fody/

PM> Install-Package Stamp.Fody

Add to FodyWeavers.xml

Add <Stamp/> to FodyWeavers.xml

<?xml version="1.0" encoding="utf-8" ?>
<Weavers>
  <Stamp />
</Weavers>

What it does

Extracts the git information from disk, combines it with the assembly version, and places it in the AssemblyInformationalVersionAttribute.

So if your assembly version is 1.0.0.0, the working branch is master and the last commit is 759e9ddb53271dfa9335a3b27e452749a9b22280 then the following attribute will be added to the assembly.

[assembly: AssemblyInformationalVersion("1.0.0.0 Head:'master' Sha:759e9ddb53271dfa9335a3b27e452749a9b22280")]

Templating the version

You can customize the string used in the AssemblyInformationalVersionAttribute by adding some tokens to the string, which Stamp will replace.

For example, if you add [assembly: AssemblyInformationalVersion("%version% Branch=%branch%")] then Stamp will change it to [assembly: AssemblyInformationalVersion("1.0.0.0 Branch=master")]

The tokens are:

  • %version% is replaced with the version (1.0.0.0)
  • %version1% is replaced with the major version only (1)
  • %version2% is replaced with the major and minor version (1.0)
  • %version3% is replaced with the major, minor, and revision version (1.0.0)
  • %version4% is replaced with the major, minor, revision, and build version (1.0.0.0)
  • %now% is replaced with the current short date
  • %utcnow% is replaced with the current utc short date
  • %githash% is replaced with the SHA1 hash of the branch tip of the repository
  • %shorthash% is replaced with the first eight characters of %githash%
  • %branch% is replaced with the branch name of the repository
  • %haschanges% is replaced with the string defined in the ChangeString attribute in the configuration, see below.
  • %user% is replaced with the current user name
  • %machinename% is replaced with the current machine name
  • %lasttag% -is replaced with the last git tag in this branch.

NOTE: if you already have an AssemblyInformationalVersion attribute and it doesn't use replacement tokens, it will not be modified at all.

Configuration

All config options are attributes of <Stamp /> element in FodyWeavers.xml

ChangeString

Define the string used to indicate that the code was built from a non clean repository.

Default is HasChanges

<Stamp ChangeString="New text" />

UseProjectGit

Define if you want to start Stamp to start searching for the Git repository in the ProjectDir (true) or the SolutionDir (false).

Default is false (SolutionDir)

<Stamp UseProjectGit='true' />

Icon

Stamp designed by Rohith M S from The Noun Project.