Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/picrap/versionstitcher
Injects repository information (such as changeset, branch...) in assembly after it is compiled.
https://github.com/picrap/versionstitcher
assembly git msbuild-task version
Last synced: 3 months ago
JSON representation
Injects repository information (such as changeset, branch...) in assembly after it is compiled.
- Host: GitHub
- URL: https://github.com/picrap/versionstitcher
- Owner: picrap
- License: mit
- Created: 2015-11-12T20:21:09.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T09:40:22.000Z (5 months ago)
- Last Synced: 2024-08-28T11:02:03.350Z (5 months ago)
- Topics: assembly, git, msbuild-task, version
- Language: C#
- Size: 3.52 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# VersionStitcher
Injects repository (git only for now) information (such as changeset, branch...) in assembly after it is compiled. It also falls back to environment variable if repository value is not found (or simply does not exist).
Available as a [NuGet package](https://www.nuget.org/packages/VersionStitcher/).
Current build status: [![Build status](https://ci.appveyor.com/api/projects/status/eblfjohu6qsa6cee/branch/master?svg=true)](https://ci.appveyor.com/project/picrap/versionstitcher/branch/master)## String injection
VersionStitcher can replace known patterns in assembly attributes and any literal string in the assembly.
### How it works
Add special tags in the application strings, such as:
```csharp
Console.WriteLine("Hi, I'm on {Version.CommitShortID}");
```
After build it will output something like:
`Hi, I'm on 1fab21ca`### Recognized commands
Pattern | Value
:------ | :------
`{Version.BuildTime}` | Build time
`{Version.BuildTimeUTC}` | Build time, UTC version
`{Version.BranchName}` | Name of current branch
`{Version.BranchRemoteName}` | Name of upstream branch
`{Version.CommitID}` | Full commit ID (the SHA1 in git)
`{Version.CommitShortID}` | Short commit ID
`{Version.CommitMessage}` | Commit message
`{Version.CommitAuthor}` | Author of commit
`{Version.CommitTime}` | Commit time
`{Version.CommitTimeIso}` | Commit time, ISO 8601 format
`{Version.CommitTags}` | Name of all tags related to this commit, if any, ordered by name, separated by space
`{Version.IsDirty}` | Literal boolean indicating whether changes are pending
`{Version.IsDirtyLiteral}` | "" or "dirty", depending on the `IsDirty` valueThere is also the special command `{Version.Help}` which displays all available commands and their values.
When used outside of a git repository, the only available values are the `Build*` values.
When a value is not found (a repository value outside repository) or does not exist (`{Version.AgeOfTheCaptain}`), then VersionSticher tries to find it in environment variables (`%CommitTime%` or `%AgeOfTheCaptain%`, for example).## Dynamic version injection
### How it works
Assembly version, file version and product version can also be injected by code, this allows a better version than the usual "1.0.*" (Yay!).
To do this, you need to write a class named `Assembly` at root namespace (by convention, we suggest to place it in the `AssemblyInfo.cs` file, to be near the other assembly version).### Sample code
This class can contain up to three methods:
```csharp
// Once used, this class is stripped out of the assembly
internal static class Assembly
{
// this method is mandatory and must return a System.Version
// the buildTime parameter is optional. It's OK if you don't require one.
// This will update the .NET assembly version ...
// ... as well as the Win32 resource version (the "Assembly Version" String from StringTables)
public static Version GetVersion(DateTime buildTime)
{
return new Version(10, buildTime.Year, buildTime.Month, buildTime.Day);
}
// This method is optional. If not specified it uses the value returned by GetVersion() above
// It can also have a parameter of type DateTime which will receive the build time as argument.
// It can return a System.Version or System.String
// (in which the string is parsed to get a version when needed or kept literal)
// It updates or adds the AssemblyFileVersionAttribute ...
// ... as well as Win32 resource version (the FILEVERSION from VS_FIXEDFILEINFO,
// and "FileVersion" String from any version-related StringTable)
public static Version GetFileVersion()
{
return new Version(30, 40, 50);
}// This method is optional too. If not specified it uses the value returned by GetFileVersion()
// or GetVersion() above
// It can also have a parameter of type DateTime which will receive the build time as argument.
// It can return a System.Version or System.String
// (in which the string is parsed to get a version when needed or kept literal)
// It updates or adds the AssemblyInformationalVersionAttribute ...
// ... as well as Win32 resource version (the PRODUCTVERSION from VS_FIXEDFILEINFO,
// and "ProductVersion" String from any version-related StringTable)
public static Version GetProductVersion()
{
return new Version(60, 70, 80, 90);
}
}
```