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

make the gitinfo caches location configurable to be able to reuse the same information over several projects that are built #190

Closed
tisis2 opened this issue Mar 31, 2022 · 0 comments · Fixed by #191
Labels

Comments

@tisis2
Copy link
Contributor

tisis2 commented Mar 31, 2022

i would like to use GitInfo to version all DLLs in my solution to the same version. i use SDK style projects and would like to use the generated assembly. therefore I placed a central Build.Directory.targets for the solution that would add the following:

    <ItemGroup>
        <PackageReference Include="GitInfo" Version="2.2.0">
            <PrivateAssets>all</PrivateAssets>
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
    </ItemGroup>

    <Target Name="SetVersionFromGitInfo" DependsOnTargets="GitVersion" BeforeTargets="GetAssemblyVersion">
        <PropertyGroup>
            <BaseVersion>$(GitBaseVersionMajor).$(GitBaseVersionMinor).$(GitBaseVersionPatch).$(GitCommits)</BaseVersion>

            <!-- for TFS build GitBranch is not set so we need to get the branch from the TFS variable -->
            <FeatureBranch>$(BUILD_SOURCEBRANCH)</FeatureBranch>
            <FeatureBranch Condition="$(FeatureBranch.StartsWith('refs/heads/'))">$(FeatureBranch.Substring(11))</FeatureBranch>
            <!-- if variable is not set its a local build -->
            <FeatureBranch Condition="$(FeatureBranch) == ''">$(GitBranch)</FeatureBranch>

            <ExtendedVersion>$(BaseVersion) / $(GitCommit) ($(GitIsDirty)) $(FeatureBranch)</ExtendedVersion>

            <Version>$(BaseVersion)</Version>
            <InformationalVersion>$(ExtendedVersion)</InformationalVersion>
        </PropertyGroup>
    </Target>

i recognized that the build time for the round 30 projects increased about 2 minutes after that change.
so i tried to see how to optimize that a bit. we found that the GitInfo for a single project would be cached so we thought it might be a nice approach to move the cache to the solution directory and reuse it so that not every project is recreating its own cache with the same content.

to test that i added the following to the central .targets file:

    <Target Name="OverrideGitInfoCache" BeforeTargets="$(GitInfoDependsOn)">
        <PropertyGroup>
            <_GitInfoFile>../GitInfo.cache</_GitInfoFile>
            <_GitIsDirtyFile>../GitIsDirty.cache</_GitIsDirtyFile>
        </PropertyGroup>
    </Target>

it almost worked. i just recognised that now the cache is still updated on each project, since the is dirty cache was updated all the time and therefore the gitinfo cache was recreated. i think that could be fixed with the change i commented in #165.

it would be nice to be able to change the cache location by just setting a variable. maybe this could be something that should be configurable.

@tisis2 tisis2 added the bug label Mar 31, 2022
@kzu kzu closed this as completed in #191 Nov 18, 2022
@devlooped devlooped locked and limited conversation to collaborators Sep 11, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant