├── .editorconfig ├── MSBuildGitHash ├── Logo.png ├── build │ ├── MSBuildGitHash.props │ └── MSBuildGitHash.targets └── MsBuildGitHash.csproj ├── MSBuildGitHash.Tests ├── Data │ ├── Directory.Build.targets │ ├── Program.vb │ ├── Program.cs │ ├── Directory.Build.props │ ├── Sdk1 │ │ └── Proj.csproj │ ├── SdkVb │ │ └── Proj.vbproj │ ├── Sdk2 │ │ └── Proj.csproj │ ├── Legacy1 │ │ └── Proj.csproj │ └── Legacy2 │ │ └── Proj.csproj ├── MSBuildGitHash.Tests.csproj ├── XUnitTestLogger.cs ├── App.config └── MSBuildGitHashTests.cs ├── LICENSE.txt ├── MsBuildGitHash.sln ├── README.md └── .gitignore /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | [*.cs] 3 | indent_style = tab 4 | indent_size = 4 5 | -------------------------------------------------------------------------------- /MSBuildGitHash/Logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarkPflug/MSBuildGitHash/HEAD/MSBuildGitHash/Logo.png -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Directory.Build.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Program.vb: -------------------------------------------------------------------------------- 1 | Module Program 2 | Sub Main() 3 | System.Console.WriteLine("Hello, world") 4 | End Sub 5 | End Module 6 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Program.cs: -------------------------------------------------------------------------------- 1 | static class Program 2 | { 3 | static void Main() 4 | { 5 | System.Console.WriteLine("Hello, world"); 6 | } 7 | } 8 | 9 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Directory.Build.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | $(MSBuildThisFileDirectory)../../../../../MSBuildGitHash/Build/ 4 | $(BuildRoot)MSBuildGitHash.props 5 | $(BuildRoot)MSBuildGitHash.targets 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Sdk1/Proj.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://github.com/MarkPflug/MSBuildGitHash 4 | git 5 | net461 6 | 3.2.1 7 | Exe 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/SdkVb/Proj.vbproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://github.com/MarkPflug/MSBuildGitHash 4 | git 5 | net461 6 | 3.2.1 7 | Exe 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Sdk2/Proj.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://github.com/MarkPflug/MSBuildGitHash 4 | git 5 | net461 6 | 3.2.1 7 | Exe 8 | True 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mark Pflug 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Legacy1/Proj.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | v4.6.1 8 | 3.2.1 9 | Exe 10 | bin\ 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/Data/Legacy2/Proj.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | v4.6.1 8 | 3.2.1 9 | Exe 10 | bin\ 11 | True 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/MSBuildGitHash.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net461 5 | false 6 | 7 | 8 | 9 | 10 | 11 | runtime 12 | 13 | 14 | 15 | runtime 16 | 17 | 18 | runtime 19 | 20 | 21 | 22 | 23 | all 24 | runtime; build; native; contentfiles; analyzers 25 | 26 | 27 | 28 | 29 | 30 | PreserveNewest 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /MSBuildGitHash/build/MSBuildGitHash.props: -------------------------------------------------------------------------------- 1 | 2 | 3 | git describe --long --always --dirty --exclude=* --abbrev=7 4 | True 5 | ^[0-9A-Fa-f]{4,32}(-dirty|-broken)%3F%24 6 | -dirty 7 | 8 | 9 | 10 | 11 | 12 | 13 | Warn 14 | 15 | 16 | False 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | $(MSBuildGitHashCommand) 28 | $(MSBuildGitHashValidateRegex) 29 | Error 30 | Warn 31 | 32 | 33 | git describe --tag 34 | True 35 | 36 | 37 | -------------------------------------------------------------------------------- /MSBuildGitHash/MsBuildGitHash.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard1.0 5 | MSBuildGitHash 6 | 2.0.2 7 | https://github.com/MarkPflug/MSBuildGitHash 8 | https://markpflug.github.io/MarkPflug.png 9 | Logo.png 10 | msbuild git hash version 11 | true 12 | git 13 | https://github.com/MarkPflug/MSBuildGitHash 14 | Mark Pflug 15 | MSBuildGitHash 16 | Embeds the git repository hash in your assembly. 17 | MSBuild targets for compiling a Git repository hash into .NET assemblies. 18 | LICENSE.txt 19 | true 20 | build 21 | Copyright © Mark Pflug $([System.DateTime]::UtcNow.Year) 22 | false 23 | true 24 | 25 | 26 | 27 | 28 | PreserveNewest 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /MsBuildGitHash.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.29613.14 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MsBuildGitHash", "MSBuildGitHash\MsBuildGitHash.csproj", "{FFD42F2E-1E9E-49E8-B54C-FF0D30183D52}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MSBuildGitHash.Tests", "MSBuildGitHash.Tests\MSBuildGitHash.Tests.csproj", "{731625E3-A06B-4DC5-A325-1463AEF519B5}" 9 | EndProject 10 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{32A5411C-E1C9-4D83-9400-18D3195B584E}" 11 | ProjectSection(SolutionItems) = preProject 12 | README.md = README.md 13 | EndProjectSection 14 | EndProject 15 | Global 16 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 17 | Debug|Any CPU = Debug|Any CPU 18 | Release|Any CPU = Release|Any CPU 19 | EndGlobalSection 20 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 21 | {FFD42F2E-1E9E-49E8-B54C-FF0D30183D52}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 22 | {FFD42F2E-1E9E-49E8-B54C-FF0D30183D52}.Debug|Any CPU.Build.0 = Debug|Any CPU 23 | {FFD42F2E-1E9E-49E8-B54C-FF0D30183D52}.Release|Any CPU.ActiveCfg = Release|Any CPU 24 | {FFD42F2E-1E9E-49E8-B54C-FF0D30183D52}.Release|Any CPU.Build.0 = Release|Any CPU 25 | {731625E3-A06B-4DC5-A325-1463AEF519B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 26 | {731625E3-A06B-4DC5-A325-1463AEF519B5}.Debug|Any CPU.Build.0 = Debug|Any CPU 27 | {731625E3-A06B-4DC5-A325-1463AEF519B5}.Release|Any CPU.ActiveCfg = Release|Any CPU 28 | {731625E3-A06B-4DC5-A325-1463AEF519B5}.Release|Any CPU.Build.0 = Release|Any CPU 29 | EndGlobalSection 30 | GlobalSection(SolutionProperties) = preSolution 31 | HideSolutionNode = FALSE 32 | EndGlobalSection 33 | GlobalSection(ExtensibilityGlobals) = postSolution 34 | SolutionGuid = {A7CA475B-B60B-48F8-A797-E2EBAB89F5B6} 35 | EndGlobalSection 36 | EndGlobal 37 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/XUnitTestLogger.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Framework; 2 | using System.Collections; 3 | using Xunit.Abstractions; 4 | 5 | class XUnitTestLogger : ILogger 6 | { 7 | static bool DumpEnv = false; 8 | static bool Verbose = true; 9 | 10 | ITestOutputHelper o; 11 | 12 | public XUnitTestLogger(ITestOutputHelper o) 13 | { 14 | this.o = o; 15 | } 16 | 17 | public LoggerVerbosity Verbosity { get; set; } 18 | public string Parameters { get; set; } 19 | 20 | public void Initialize(IEventSource eventSource) 21 | { 22 | eventSource.AnyEventRaised += EventSource_AnyEventRaised; 23 | eventSource.BuildStarted += EventSource_BuildStarted; 24 | eventSource.ProjectStarted += EventSource_ProjectStarted; 25 | eventSource.MessageRaised += EventSource_MessageRaised; 26 | eventSource.ErrorRaised += EventSource_ErrorRaised; 27 | } 28 | 29 | private void EventSource_ErrorRaised(object sender, BuildErrorEventArgs e) 30 | { 31 | o.WriteLine(e.Message + " " + e.File + "(" + e.LineNumber + "," + e.ColumnNumber + ")"); 32 | } 33 | 34 | private void EventSource_MessageRaised(object sender, BuildMessageEventArgs e) 35 | { 36 | if (e.Message.StartsWith("DEBUG:")) 37 | { 38 | o.WriteLine(e.Message); 39 | } 40 | } 41 | 42 | private void EventSource_ProjectStarted(object sender, ProjectStartedEventArgs e) 43 | { 44 | if (DumpEnv) 45 | { 46 | o.WriteLine("Initial Properties:"); 47 | foreach (DictionaryEntry kvp in e.Properties) 48 | { 49 | o.WriteLine($"{kvp.Key} {kvp.Value}"); 50 | } 51 | } 52 | } 53 | 54 | private void EventSource_BuildStarted(object sender, BuildStartedEventArgs e) 55 | { 56 | if (DumpEnv) 57 | { 58 | o.WriteLine("Environment:"); 59 | foreach (var kvp in e.BuildEnvironment) 60 | { 61 | o.WriteLine($"{kvp.Key}: {kvp.Value}"); 62 | } 63 | } 64 | } 65 | 66 | private void EventSource_AnyEventRaised(object sender, BuildEventArgs e) 67 | { 68 | if (Verbose) 69 | { 70 | o.WriteLine(e.Message); 71 | } 72 | } 73 | 74 | public void Shutdown() 75 | { 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /MSBuildGitHash.Tests/MSBuildGitHashTests.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Build.Evaluation; 2 | using Microsoft.Build.Framework; 3 | using Microsoft.Build.Locator; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Diagnostics; 8 | using System.Linq; 9 | using System.Reflection; 10 | using Xunit; 11 | using Xunit.Abstractions; 12 | 13 | class MsBuildFixture : IDisposable 14 | { 15 | public MsBuildFixture() 16 | { 17 | MSBuildLocator.RegisterDefaults(); 18 | } 19 | 20 | public void Dispose() 21 | { 22 | MSBuildLocator.Unregister(); 23 | } 24 | } 25 | 26 | [CollectionDefinition("MSBuild")] 27 | public class MSBuildCollection : ICollectionFixture 28 | { 29 | } 30 | 31 | [Collection("MSBuild")] 32 | public class MSBuildGitHashTests 33 | { 34 | readonly ILogger logger; 35 | ITestOutputHelper o; 36 | 37 | static readonly Dictionary gp = 38 | new Dictionary 39 | { 40 | ["Configuration"] = "Debug", 41 | ["Platform"] = "AnyCPU", 42 | }; 43 | 44 | public MSBuildGitHashTests(ITestOutputHelper o) 45 | { 46 | this.o = o; 47 | this.logger = new XUnitTestLogger(o); 48 | } 49 | 50 | string GetOutput(string exePath, string args) 51 | { 52 | var psi = new ProcessStartInfo(exePath, args) 53 | { 54 | UseShellExecute = false, 55 | RedirectStandardOutput = true, 56 | CreateNoWindow = true, 57 | }; 58 | var proc = Process.Start(psi); 59 | var text = proc.StandardOutput.ReadToEnd(); 60 | proc.WaitForExit(); 61 | return text; 62 | } 63 | 64 | void LogProps(Project proj) 65 | { 66 | foreach (var kvp in Environment.GetEnvironmentVariables().Cast().OrderBy(e => e.Key)) 67 | { 68 | o.WriteLine(kvp.Key + ": " + kvp.Value); 69 | } 70 | 71 | foreach (var prop in proj.AllEvaluatedProperties.OrderBy(p => p.Name)) 72 | { 73 | o.WriteLine(prop.Name + ": " + prop.EvaluatedValue + " (" + prop.UnevaluatedValue + ")"); 74 | } 75 | } 76 | 77 | string BuildProject(string projFile) 78 | { 79 | var pc = new ProjectCollection(gp); 80 | var proj = pc.LoadProject(projFile); 81 | var restored = proj.Build("Restore", new[] { logger }); 82 | if (!restored) 83 | { 84 | LogProps(proj); 85 | } 86 | Assert.True(restored, "Failed to restore packages"); 87 | var result = proj.Build(logger); 88 | LogProps(proj); 89 | var outputPath = proj.GetPropertyValue("TargetPath"); 90 | Assert.True(result, "Build failed"); 91 | return outputPath; 92 | } 93 | 94 | const string InfoVersionPattern = @"^\d+.\d+.\d+\+[0-9a-f]{7}(-dirty)?$"; 95 | const string InfoVersionShortPattern = @"^[0-9a-f]{7}(-dirty)?$"; 96 | 97 | [Theory] 98 | [InlineData("Data/Sdk1/Proj.csproj")] 99 | [InlineData("Data/SdkVb/Proj.vbproj")] 100 | public void SdkProjectTest(string projectFile) 101 | { 102 | var exepath = BuildProject(projectFile); 103 | var v = FileVersionInfo.GetVersionInfo(exepath).ProductVersion; 104 | Assert.Matches(InfoVersionPattern, v); 105 | var asm = Assembly.LoadFile(exepath); 106 | var attrs = asm.GetCustomAttributes(); 107 | var attr = attrs.FirstOrDefault(a => a.Key == "GitRepository"); 108 | Assert.NotNull(attr); 109 | Assert.Equal("https://github.com/MarkPflug/MSBuildGitHash", attr.Value); 110 | } 111 | 112 | [Theory] 113 | [InlineData("Data/Legacy2/Proj.csproj")] 114 | [InlineData("Data/Sdk2/Proj.csproj")] 115 | public void ProjectInfoVersionTest(string projectFile) 116 | { 117 | var exepath = BuildProject(projectFile); 118 | var v = FileVersionInfo.GetVersionInfo(exepath).ProductVersion; 119 | Assert.Matches(InfoVersionShortPattern, v); 120 | var asm = Assembly.LoadFile(exepath); 121 | var attr = asm.GetCustomAttribute(); 122 | Assert.NotNull(attr); 123 | Assert.NotNull(attr.InformationalVersion); 124 | } 125 | 126 | [Fact] 127 | public void LegacyProjectTest() 128 | { 129 | var exepath = BuildProject("Data/Legacy1/Proj.csproj"); 130 | var v = FileVersionInfo.GetVersionInfo(exepath).ProductVersion; 131 | Assert.Matches(InfoVersionPattern, v); 132 | } 133 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSBuildGitHash 2 | Includes the Git repository hash in your compiled .NET assemblies. 3 | This allows you to easily correlate an assembly to exact version of the code that produced it. 4 | 5 | ## Nuget 6 | 7 | This project is available as a nuget package: https://www.nuget.org/packages/MSBuildGitHash. 8 | 9 | ## Usage 10 | By 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". 11 | 12 | Basic 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 `False` in your project. 13 | 14 | ## Customization 15 | 16 | ### Git hash format 17 | 18 | By 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: 19 | 20 | ```xml 21 | 22 | git rev-parse HEAD 23 | 24 | ``` 25 | 26 | ### Git hash length 27 | 28 | Some 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: 29 | 30 | ```xml 31 | 32 | git describe --long --always --dirty --exclude=* --abbrev=8 33 | 34 | ``` 35 | 36 | ### Informational Version (aka Product Version) format 37 | 38 | By default, the git hash is appended to the Informational Version attribute value. 39 | 40 | Alternatively, the git hash can replace the Informational Version attribute value by setting `MSBuildGitHashReplaceInfoVersion` to `True` in your .csproj file: 41 | 42 | ```xml 43 | 44 | True 45 | 46 | ``` 47 | ### Command Output to Assembly Metadata 48 | 49 | If 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: 50 | 51 | ```xml 52 | 53 | your command 54 | optional regex to validate output 55 | 56 | ``` 57 | 58 | ```xml 59 | 60 | 61 | git describe 62 | 63 | 64 | git describe --tag --abbrev=0 65 | 66 | 67 | ``` 68 | 69 | ### Extract Assembly Metadata 70 | 71 | ```csharp 72 | using System.Reflection; 73 | 74 | string gitHash = Assembly 75 | .GetEntryAssembly() 76 | .GetCustomAttributes() 77 | .FirstOrDefault(attr => attr.Key == "GitHash")?.Value; 78 | ``` 79 | 80 | ## Version History 81 | _2.0.2_ 82 | - Fix issues introduced by changes from the Microsoft.NET.Sdk. 83 | 84 | _2.0.1_ 85 | - Restores the ability to use `MSBuildGitHashSuppressDirtyWarning` to suppress warnings that was lost during the 2.0 refactor. 86 | 87 | _2.0.0_ 88 | - Now includes the most recent git tag as metadata as well, if the repository has any tags. 89 | - Significant refactoring to allow more easily adding additional assembly metadata. Thanks [@zhilbug](https://github.com/zhilbug) for the bulk of the work on this. 90 | - 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. 91 | 92 | _1.0.2_ 93 | - MSBuildGitHash is now properly marked as a development dependency, and so won't show up as a transitive dependency in your package. 94 | 95 | _1.0.1_ 96 | - Fixes an issue where git tags would appear in hash version, causing validation failure. 97 | 98 | _1.0.0_ 99 | - Adds the ability to disable error when running outside a git repository via `false`. Will emit a warning instead of error in such case. 100 | Can be specified on MSBuild command line as `/p:MSBuildGitHashValidateSuccess=false` or by setting an environment variable of the same name/value. 101 | 102 | _0.5.3_ 103 | - Emits a warning when the repository is dirty. Can be suppressed with `True`. 104 | 105 | _0.5.2_ 106 | - Adds ability to replace assembly InformationalVersion via `MSBuildGitHashReplaceInfoVersion`. Thanks @Br3nt 107 | 108 | _0.5.1_ 109 | - Fix for #15, to allow supression of AssemblyInformationalVersionAttribute. 110 | 111 | _0.5.0_ 112 | - Removed framework dependency from nupkg. 113 | 114 | _0.4.1_ 115 | - No functional change. 116 | - Minor build script cleanup. 117 | 118 | _0.4.0_ 119 | - Adds an AssemblyInformationalVersion attribute containing the git version. This value shows up in the standard Windows properties dialog. 120 | - No longer uses temp files in "obj" folder to operate. 121 | - Replace remote repository to use standard "RepositoryUrl" used by nuget. 122 | - Working unit tests. 123 | 124 | _0.3.0_ 125 | - Adds option to include git remote repository url as well. 126 | 127 | _0.2.0_ 128 | - Adds optional validation that the hash value looks correct. 129 | - Improved build error message when git commands fail. 130 | 131 | _0.1.0_ 132 | - Base functionality. 133 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # MSTest test Results 33 | [Tt]est[Rr]esult*/ 34 | [Bb]uild[Ll]og.* 35 | 36 | # NUNIT 37 | *.VisualState.xml 38 | TestResult.xml 39 | 40 | # Build Results of an ATL Project 41 | [Dd]ebugPS/ 42 | [Rr]eleasePS/ 43 | dlldata.c 44 | 45 | # .NET Core 46 | project.lock.json 47 | project.fragment.lock.json 48 | artifacts/ 49 | **/Properties/launchSettings.json 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # Visual Studio code coverage results 117 | *.coverage 118 | *.coveragexml 119 | 120 | # NCrunch 121 | _NCrunch_* 122 | .*crunch*.local.xml 123 | nCrunchTemp_* 124 | 125 | # MightyMoose 126 | *.mm.* 127 | AutoTest.Net/ 128 | 129 | # Web workbench (sass) 130 | .sass-cache/ 131 | 132 | # Installshield output folder 133 | [Ee]xpress/ 134 | 135 | # DocProject is a documentation generator add-in 136 | DocProject/buildhelp/ 137 | DocProject/Help/*.HxT 138 | DocProject/Help/*.HxC 139 | DocProject/Help/*.hhc 140 | DocProject/Help/*.hhk 141 | DocProject/Help/*.hhp 142 | DocProject/Help/Html2 143 | DocProject/Help/html 144 | 145 | # Click-Once directory 146 | publish/ 147 | 148 | # Publish Web Output 149 | *.[Pp]ublish.xml 150 | *.azurePubxml 151 | # TODO: Comment the next line if you want to checkin your web deploy settings 152 | # but database connection strings (with potential passwords) will be unencrypted 153 | *.pubxml 154 | *.publishproj 155 | 156 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 157 | # checkin your Azure Web App publish settings, but sensitive information contained 158 | # in these scripts will be unencrypted 159 | PublishScripts/ 160 | 161 | # NuGet Packages 162 | *.nupkg 163 | # The packages folder can be ignored because of Package Restore 164 | **/packages/* 165 | # except build/, which is used as an MSBuild target. 166 | !**/packages/build/ 167 | # Uncomment if necessary however generally it will be regenerated when needed 168 | #!**/packages/repositories.config 169 | # NuGet v3's project.json files produces more ignorable files 170 | *.nuget.props 171 | *.nuget.targets 172 | 173 | # Microsoft Azure Build Output 174 | csx/ 175 | *.build.csdef 176 | 177 | # Microsoft Azure Emulator 178 | ecf/ 179 | rcf/ 180 | 181 | # Windows Store app package directories and files 182 | AppPackages/ 183 | BundleArtifacts/ 184 | Package.StoreAssociation.xml 185 | _pkginfo.txt 186 | 187 | # Visual Studio cache files 188 | # files ending in .cache can be ignored 189 | *.[Cc]ache 190 | # but keep track of directories ending in .cache 191 | !*.[Cc]ache/ 192 | 193 | # Others 194 | ClientBin/ 195 | ~$* 196 | *~ 197 | *.dbmdl 198 | *.dbproj.schemaview 199 | *.jfm 200 | *.pfx 201 | *.publishsettings 202 | orleans.codegen.cs 203 | 204 | # Since there are multiple workflows, uncomment next line to ignore bower_components 205 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 206 | #bower_components/ 207 | 208 | # RIA/Silverlight projects 209 | Generated_Code/ 210 | 211 | # Backup & report files from converting an old project file 212 | # to a newer Visual Studio version. Backup files are not needed, 213 | # because we have git ;-) 214 | _UpgradeReport_Files/ 215 | Backup*/ 216 | UpgradeLog*.XML 217 | UpgradeLog*.htm 218 | 219 | # SQL Server files 220 | *.mdf 221 | *.ldf 222 | *.ndf 223 | 224 | # Business Intelligence projects 225 | *.rdl.data 226 | *.bim.layout 227 | *.bim_*.settings 228 | 229 | # Microsoft Fakes 230 | FakesAssemblies/ 231 | 232 | # GhostDoc plugin setting file 233 | *.GhostDoc.xml 234 | 235 | # Node.js Tools for Visual Studio 236 | .ntvs_analysis.dat 237 | node_modules/ 238 | 239 | # Typescript v1 declaration files 240 | typings/ 241 | 242 | # Visual Studio 6 build log 243 | *.plg 244 | 245 | # Visual Studio 6 workspace options file 246 | *.opt 247 | 248 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 249 | *.vbw 250 | 251 | # Visual Studio LightSwitch build output 252 | **/*.HTMLClient/GeneratedArtifacts 253 | **/*.DesktopClient/GeneratedArtifacts 254 | **/*.DesktopClient/ModelManifest.xml 255 | **/*.Server/GeneratedArtifacts 256 | **/*.Server/ModelManifest.xml 257 | _Pvt_Extensions 258 | 259 | # Paket dependency manager 260 | .paket/paket.exe 261 | paket-files/ 262 | 263 | # FAKE - F# Make 264 | .fake/ 265 | 266 | # JetBrains Rider 267 | .idea/ 268 | *.sln.iml 269 | 270 | # CodeRush 271 | .cr/ 272 | 273 | # Python Tools for Visual Studio (PTVS) 274 | __pycache__/ 275 | *.pyc 276 | 277 | # Cake - Uncomment if you are using it 278 | # tools/** 279 | # !tools/packages.config 280 | 281 | # Telerik's JustMock configuration file 282 | *.jmconfig 283 | 284 | # BizTalk build output 285 | *.btp.cs 286 | *.btm.cs 287 | *.odx.cs 288 | *.xsd.cs 289 | 290 | # windows exectuables and libs 291 | *.exe 292 | *.com 293 | *.dll 294 | -------------------------------------------------------------------------------- /MSBuildGitHash/build/MSBuildGitHash.targets: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | true 5 | true 6 | $(MSBuildGitHashValidate) 7 | 8 | 9 | 10 | 11 | $(RepositoryUrl) 12 | 13 | 14 | 15 | 20 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | $(ConsoleOutput) 32 | $(ExitCode) 33 | 34 | 35 | 36 | 40 | 41 | 45 | 46 | 47 | $(ConsoleOutput) 48 | $(Value.Length) 49 | $(Value) 50 | $(Value.Substring(0,32)) 51 | 52 | $([System.Text.RegularExpressions.Regex]::IsMatch('$(Value)', '%(AssemblyMetadataCommand.ValidateRegex)')) 53 | True 54 | 55 | 56 | 60 | 61 | 63 | 64 | $(Value) 65 | 66 | 67 | 68 | 69 | 70 | 74 | 75 | 76 | %(AssemblyMetadata.Value) 77 | 78 | 79 | 80 | 81 | 85 | $(MSBuildGitHashValue) 88 | 89 | 90 | 91 | 92 | 93 | false 94 | %(Value) 95 | 96 | 97 | 98 | $([System.Text.RegularExpressions.Regex]::IsMatch(%(Value), $(MSBuildGitHashDirtyRegex))) 99 | 100 | 101 | 105 | 106 | 107 | 108 | 113 | 114 | $(Version)+$(MSBuildGitHashValue) 115 | $(MSBuildGitHashValue) 116 | 117 | 118 | 119 | 122 | <_Parameter1>$(MSBuildGitHashVersionAttribute) 123 | 124 | 125 | 126 | 127 | 131 | 134 | 135 | <_Parameter1>%(AssemblyMetadata.Identity) 136 | <_Parameter2>%(AssemblyMetadata.Value) 137 | 138 | 139 | 140 | 141 | 145 | 146 | 147 | .cs 148 | .vb 149 | C# 150 | VisualBasic 151 | $(IntermediateOutputPath)MSBuildGitHashAssemblyInfo$(LanguageExt) 152 | 153 | 154 | 158 | 159 | 160 | 163 | 164 | 165 | 166 | 167 | --------------------------------------------------------------------------------