Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change request: A way to conditionally disable MSBuildGitHash #26

Open
OlegFedko opened this issue Jul 30, 2020 · 5 comments
Open

Change request: A way to conditionally disable MSBuildGitHash #26

OlegFedko opened this issue Jul 30, 2020 · 5 comments

Comments

@OlegFedko
Copy link

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.

@OlegFedko OlegFedko changed the title Change request: A way to conditonally disable MSBuildGitHash Change request: A way to conditionally disable MSBuildGitHash Jul 30, 2020
@MarkPflug
Copy link
Owner

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.

@OlegFedko
Copy link
Author

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.

@OlegFedko
Copy link
Author

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?

@MarkPflug
Copy link
Owner

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.

@OlegFedko
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants