{"id":19991567,"url":"https://github.com/MarkPflug/MSBuildGitHash","last_synced_at":"2025-05-04T10:32:00.359Z","repository":{"id":41541786,"uuid":"97997115","full_name":"MarkPflug/MSBuildGitHash","owner":"MarkPflug","description":"Includes the Git repo hash in your compiled .NET assemblies","archived":false,"fork":false,"pushed_at":"2024-08-13T17:20:29.000Z","size":99,"stargazers_count":98,"open_issues_count":6,"forks_count":12,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-05-02T23:06:02.142Z","etag":null,"topics":["dotnet","git","msbuild"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MarkPflug.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-22T00:52:58.000Z","updated_at":"2025-01-31T12:19:13.000Z","dependencies_parsed_at":"2024-11-10T12:40:49.713Z","dependency_job_id":"df5939ba-406b-4a90-839a-7bfbbfe8e44a","html_url":"https://github.com/MarkPflug/MSBuildGitHash","commit_stats":{"total_commits":54,"total_committers":8,"mean_commits":6.75,"dds":0.537037037037037,"last_synced_commit":"61cfbb3cdef8ea23c96ee71a64a71a806f0e5064"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkPflug%2FMSBuildGitHash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkPflug%2FMSBuildGitHash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkPflug%2FMSBuildGitHash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MarkPflug%2FMSBuildGitHash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MarkPflug","download_url":"https://codeload.github.com/MarkPflug/MSBuildGitHash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252320447,"owners_count":21729127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dotnet","git","msbuild"],"created_at":"2024-11-13T04:51:48.640Z","updated_at":"2025-05-04T10:31:59.053Z","avatar_url":"https://github.com/MarkPflug.png","language":"C#","readme":"# MSBuildGitHash\nIncludes the Git repository hash in your compiled .NET assemblies. \nThis allows you to easily correlate an assembly to exact version of the code that produced it.\n\n## Nuget\n\nThis project is available as a nuget package: https://www.nuget.org/packages/MSBuildGitHash.\n\n## Usage\nBy default, including the nuget package (MSBuildGitHash) will automatically add the git repository hash to your assembly as a `System.Reflection.AssemblyMetadataAttribute` with they key \"GitHash\". As of 0.4.0, it will include the git repository URL as well. This value is taken from the `RepositoryUrl` MSBuild property which is also used by nuget. This is only used if the RepositoryType is `git`. The repository URL will be attached with the key \"GitRepository\". \n\nBasic validation is performed on the generated hash version to ensure that a git command error doesn't result in a bad value being attached. If the validation causes problems for some reason, it can be disabled by defining the `\u003cMSBuildGitHashValidate\u003eFalse\u003c/MSBuildGitHashValidate\u003e` in your project.\n\n## Customization\n\n### Git hash format\n\nBy default, the package will include the output of the command `git describe --long --always --dirty`. This produces a truncation (first 7 hex characters) of the full repository hash. You can customize the command that is executed by defining the `MSBuildGitHashCommand` property in your .csproj file. For example, if you want to include the full hash, you can add the following:\n\n```xml\n\u003cPropertyGroup\u003e\n  \u003cMSBuildGitHashCommand\u003egit rev-parse HEAD\u003c/MSBuildGitHashCommand\u003e\n\u003c/PropertyGroup\u003e\n```\n\n### Git hash length\n\nSome IDEs and also DevOps platforms show first 8 hex characters. To change the default length from 7 hex characters to 8 hex characters you can add the following:\n\n```xml\n\u003cPropertyGroup\u003e\n  \u003cMSBuildGitHashCommand\u003egit describe --long --always --dirty --exclude=* --abbrev=8\u003c/MSBuildGitHashCommand\u003e\n\u003c/PropertyGroup\u003e\n```\n\n### Informational Version (aka Product Version) format\n\nBy default, the git hash is appended to the Informational Version attribute value.\n\nAlternatively, the git hash can replace the Informational Version attribute value by setting `MSBuildGitHashReplaceInfoVersion` to `True` in your .csproj file:\n\n```xml\n\u003cPropertyGroup\u003e\n  \u003cMSBuildGitHashReplaceInfoVersion\u003eTrue\u003c/MSBuildGitHashReplaceInfoVersion\u003e\n\u003c/PropertyGroup\u003e\n```\n### Command Output to Assembly Metadata\n\nIf there are additional commands and output that are needed to be included in the meta data, you can do so by adding them using `AssemblyEmbed`. Examples:\n\n```xml\n\u003cAssemblyMetadataCommand Include=\"KeyNameForOutput\"\u003e\n  \u003cCommand\u003eyour command\u003c/Command\u003e\n  \u003cValidationRegex\u003eoptional regex to validate output\u003c/ValidationRegex\u003e\n\u003c/AssemblyMetadataCommand\u003e\n```\n\n```xml\n\u003cItemGroup\u003e\n  \u003cAssemblyMetadataCommand Include=\"GitDescription\"\u003e\n    \u003cCommand\u003egit describe\u003c/Command\u003e\n  \u003c/AssemblyMetadataCommand\u003e\n  \u003cAssemblyMetadataCommand Include=\"GitTag\"\u003e\n    \u003cCommand\u003egit describe --tag --abbrev=0\u003c/Command\u003e\n  \u003c/AssemblyMetadataCommand\u003e\n\u003c/ItemGroup\u003e\n```\n\n### Extract Assembly Metadata\n\n```csharp\nusing System.Reflection;\n\nstring gitHash = Assembly\n\t.GetEntryAssembly()\n\t.GetCustomAttributes\u003cAssemblyMetadataAttribute\u003e()\n\t.FirstOrDefault(attr =\u003e attr.Key == \"GitHash\")?.Value;\n```\n\n## Version History\n_2.0.2_\n- Fix issues introduced by changes from the Microsoft.NET.Sdk.\n\n_2.0.1_\n- Restores the ability to use `MSBuildGitHashSuppressDirtyWarning` to suppress warnings that was lost during the 2.0 refactor.\n\n_2.0.0_\n- Now includes the most recent git tag as metadata as well, if the repository has any tags.\n- Significant refactoring to allow more easily adding additional assembly metadata. Thanks [@zhilbug](https://github.com/zhilbug) for the bulk of the work on this.\n- This is a major version, because it has more potential to affect existing builds. Projects that don't include signification build customizations should continue to work without modification.\n\n_1.0.2_\n- MSBuildGitHash is now properly marked as a development dependency, and so won't show up as a transitive dependency in your package.\n\n_1.0.1_\n- Fixes an issue where git tags would appear in hash version, causing validation failure.\n\n_1.0.0_\n- Adds the ability to disable error when running outside a git repository via `\u003cMSBuildGitHashValidateSuccess\u003efalse`. Will emit a warning instead of error in such case.\n    Can be specified on MSBuild command line as `/p:MSBuildGitHashValidateSuccess=false` or by setting an environment variable of the same name/value.\n\n_0.5.3_ \n- Emits a warning when the repository is dirty. Can be suppressed with `\u003cMSBuildGitHashSuppressDirtyWarning\u003eTrue`.\n\n_0.5.2_ \n- Adds ability to replace assembly InformationalVersion via `MSBuildGitHashReplaceInfoVersion`. Thanks @Br3nt\n\n_0.5.1_ \n- Fix for #15, to allow supression of AssemblyInformationalVersionAttribute.\n\n_0.5.0_\n- Removed framework dependency from nupkg.\n\n_0.4.1_\n- No functional change.\n- Minor build script cleanup.\n\n_0.4.0_\n- Adds an AssemblyInformationalVersion attribute containing the git version. This value shows up in the standard Windows properties dialog.\n- No longer uses temp files in \"obj\" folder to operate.\n- Replace remote repository to use standard \"RepositoryUrl\" used by nuget.\n- Working unit tests.\n\n_0.3.0_\n- Adds option to include git remote repository url as well.\n\n_0.2.0_\n- Adds optional validation that the hash value looks correct.\n- Improved build error message when git commands fail.\n\n_0.1.0_\n- Base functionality.\n","funding_links":[],"categories":["C\\#"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarkPflug%2FMSBuildGitHash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMarkPflug%2FMSBuildGitHash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMarkPflug%2FMSBuildGitHash/lists"}