markpflug / msbuildgithash Goto Github PK
View Code? Open in Web Editor NEWIncludes the Git repo hash in your compiled .NET assemblies
License: MIT License
Includes the Git repo hash in your compiled .NET assemblies
License: MIT License
Hi,
I have install the nuget package of this project on https://github.com/chucklu/Utility.
After I build the project, the git hash is not embedded in version of *.dll.
I also tried to run the unit test demo, only the demo for LegacyProjectTest works, SdkProjectTest demo failed with restore error. And the demo project is not a normal one, such as a project have AssemblyInfo.cs .
I also found you have used git bash in https://github.com/MarkPflug/Elemental.SysInfoTool, I clone this project and build it. When I verify the version, nothing related to git hash.
I managed to reproduce the problem in a new project by adding a one-letter annotated tag:
git tag -a B
I got the error:
MSBuildGitHash hash value starting with 'B-0-g91456ff' was invalid.
I would like to know if it's possible to combine the output of multiple commands.
git branch --show-current
git rev-list --all --count
git describe --long --always --dirty
Which will create something like:
develop-9657-8f52fbc74-dirty
It would be nice to have the option to add an additional attribute for e.g. the git commit date which I like to use as "code base date".
MSBuildGitHash 2.0.1 doesn't seem to generate an informational version with .netcore3.1
Steps to reproduce:
(Used .net core 3.1.6)
=> The informational version is still 1.0.0. (the default) but the AssemblyMetadata GitHash is included correctly.
On a fresh install of 0.5.0 the build fails with the above error. The build succeeds if I add the MSBuildGitHashCommand to the .csproj, but the README made it seem like that was optional.
Under: Git hash format
(first 8 hex characters)
should be
(first 7 hex characters)
hi, we're currently using this, but a couple of use cases came up and wanted to see if you think these would fit in your vision or if it's better for us to fork.
git describe --tag
(which generally is a tag). Are you open to adding a 2nd overridable command that ends up with metadata name GitDescribe ?if these do align, we can get a PR going. let me know your thoughts.
I want to disable MSBuildGitHash in Debug config because it increases compilation time, but useless in debug for me.
Also it seems that project may rebuild because of MSBuildGitHash even if nothing changed in the project.
For example when I edit tests main project also recompiled even if it wasn't changed.
i like the
[assembly: AssemblyMetadata("GitHash"
but i do NOT want to modify the AssemblyInformationalVersionAttribute is there anyway to opt out of that part of this?
Is it possible to ignore a missing .git folder and include a dummy value?
Sometimes we download old commits of our software to quickly test items out and the build will obviously fail due to there being no git repo. This is not immediately obvious to some of our team members.
Or alternatively just make it a warning?
Thanks
Hi there,
A great library, I noticed in v2.0.0 that <MSBuildGitHashSuppressDirtyWarning>true</MSBuildGitHashSuppressDirtyWarning>
no longer works and the message gets emitted
As a sidenote I noticed when using Resharper I tend to get messages on the bottom stating sync solution I think it's every time a file might be getting changed while developing. Not sure if it's related, but if it is, is there is a way to prevent MSBuildGitHash from running locally?
If I make some changes, then build, then commit and then build again without making additional changes, the Git hash will not be updated.
This is because without source files being touched the MSBuild Targets will not be executed at all and the project will show "Everything up-to-date".
The best solution would be to check if the HEAD has changed and regenerate the AssemblyInfo.cs only if the commit has changed, but do nothing if the commit wasn't changed.
A slightly worse solution would be to always regenerate but this would break the "Everything up-to-date" - the project will always be built even if nothing was changed including the commit.
by default
git describe --long --always --dirty
Can use the tags leading to errors
Example:
MSBuildGitHash hash value starting with 'docker-version-dirty' was invalid.
that is the shortend value of
docker-version-0-g662b733-dirty
this fixs that issue
git describe --match=NeVeRmAtCh --always --abbrev=7 --dirty
<PropertyGroup>
<MSBuildGitHashCommand>git describe --match=NeVeRmAtCh --always --abbrev=7 --dirty</MSBuildGitHashCommand>
</PropertyGroup>
The following message
fatal: No names found, cannot describe anything.
is added to the output when you build, it does not stop the build itself and the version number seems correct, I think this might be looking for a tag and failing if there are none.
the issue goes away if you restore the old version.
On 2 of my machines MSBuildGitHash is working like a charm. However, I do have one machine which is not connected to the internet (and will not be connected). On this machine my project starts throwing many compilation errors (e.g. Type Exception not known
, ...). Once I uninstall MSBuildGitHash everything is working like normal.
I copied my whole project including packages
folder which contains MSBuildGitHash from a machine (with network connection) where everything works smoothly onto the machine which shows these wired errors.
Any ideas or do you need additional information?
This is for other people's future reference. I was using the MSBuildGitHash Nuget package v2.0.2.
While trying to run some custom git commands to capture additional information, I ran into problems with character sequences that needed to be escaped.
%
needs to be escaped as %%
ae
needs to be escaped as a%e
cd
needs to be escaped as c%d
These are the git commands I was trying to run:
git show --quiet --format=%ae
git show --quiet --format=%an
git show --quiet --format=%cd --date=iso-strict
git show --quiet --format=%B
git show --quiet --format=%H
This is the corresponding ItemGroup with correctly escaped character sequences:
<ItemGroup>
<AssemblyMetadataCommand Include="GitAuthorEmail">
<Command>git show --quiet --format=%%a%e</Command>
</AssemblyMetadataCommand>
<AssemblyMetadataCommand Include="GitAuthorName">
<Command>git show --quiet --format=%%an</Command>
</AssemblyMetadataCommand>
<AssemblyMetadataCommand Include="GitCommitDate">
<Command>git show --quiet --format=%%c%d --date=iso-strict</Command>
</AssemblyMetadataCommand>
<AssemblyMetadataCommand Include="GitCommitMessage">
<Command>git show --quiet --format=%%B</Command>
</AssemblyMetadataCommand>
<AssemblyMetadataCommand Include="GitFullHash">
<Command>git show --quiet --format=%%H</Command>
</AssemblyMetadataCommand>
</ItemGroup>
There may be other character sequences that require escaping which I am not yet aware of.
Is there a way to deativate the standard output from git describe?
I tried to pipe the git describe
output to /dev/null
but it doesn't seem to work.
I failed to build my solution with error:
C:\repo\packages\MSBuildGitHash.0.2.0\build\MSBuildGitHash.targets(29,5): error : MSBuildGitHash hash value starting with 'Roll_1.0-232-g474e3a4-dirty' was invalid.
Where "Roll_1.0" is a label used some time ago in history.
It seems that MSBuildGitHash doesn't work with labels.
It is said that I can somehow customize the validation but there is no any wiki how to do it,
This is a rehash (he!) of #5 When building again after moving to a revision with changes only on files outside the project, msbuild thinks the project is up-to-date and fails to rebuild it.
Thanks for making this cool package. For those of us that aren't intimate with MSBuild, this is a real time saver.
Given the name of this package, I was somewhat surprised to find that the git hash isn't what is provided. For that you would want to do something like git rev-parse HEAD
in stead of git describe
.
It would probably improve the utility of this package if it were possible to override the specific git command used to extract version information. As it stands, I had to include your targets directly in my .csproj and modify the git command there in order to actually get the git hash.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.