Change request: A way to conditionally disable MSBuildGitHash
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.
An easy way to do this would be to add a condition to the PackageReference:
<PackageReference Include="MSBuildGitHash" Condition="$(Configuration) != 'Debug'"/>
This raising an interesting point though. This package should include proper build logic to avoid a full rebuild if the repository version is unchanged. I'll have to think about how to best achieve that, which might take me a while to get to. In the mean time I hope the above workaround is sufficient for you.
It doesn't work in VS 17 & VS 19 (see https://stackoverflow.com/questions/48590270/packagereference-condition-is-ignored) But this workaround works:
<Choose>
<When Condition=" '$(Configuration)' != 'Debug' ">
<ItemGroup>
<PackageReference Include="MSBuildGitHash">
<Version>2.0.2</Version>
</PackageReference>
</ItemGroup>
</When>
</Choose>
Unfortunatelly it is not compatible with Manage NuGet packages VS UI. It doesn't see the package. And I hope that when I will manage another packages, this workaround will not be broken.
So I would like to have some conditional property like MSBuildGitHashValidate that can disable the package.
Unfortunatelly it is not compatible with Manage NuGet packages VS UI. It doesn't see the package. And I hope that when I will manage another packages, this workaround will not be broken.
Also with this workaround when installing new package VS tries to remove MSBuildGitHash if current config is Debug.
Any chances for fix?
I'm probably not going to make any further changes to this package as there is a better way to do this now . The .NET project system and MSBuild have changed significantly since I created this package, and trying to keep up with those changes is difficult. Fortunately, some of those changes have made it easier to do this without needing a nuget package. See the update that I provided to this SO answer: https://stackoverflow.com/questions/15141338/embed-git-commit-hash-in-a-net-dll/45248069#45248069
This new technique is what I've been using for my projects, and I'm happier with it than I was with needing this custom package.
AddSourceRevisionToInformationalVersion/SourceRevisionId awesome undocumented something. It still looks like MS Build magic :) While using NuGet package is straightforward (and documented) way to add this functionality without MS Build knowledge. And also good way to reuse this functionality (compared to copy-paste from .csproj to .csproj) until it will be added to CSPROJ editor in VS.