GitInfo icon indicating copy to clipboard operation
GitInfo copied to clipboard

Stale info on unrelated changes

Open brunom opened this issue 3 years ago • 3 comments

Describe the Bug

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.

Steps to Reproduce

Commit a simple framework console hello world {version}. Build. Move to another commit that just ads an unreferenced .txt Build. It's erroneously up to date.

Expected Behavior

Should rebuild.

Version Info

GitInfo.2.2.0

brunom avatar Mar 16 '22 01:03 brunom

@brunom I think I'm referencing this same issue in #198. My GitInfo becomes stale when the project doesn't build, although there may be changes in other projects. Have you found a solution?

Currently I'm trying to create a separate project whos sole purpose is to reference GitInfo, and make that project depend on all other projects. Not sure if that's working yet.

david-wsd avatar Jun 07 '22 22:06 david-wsd

@david-wsd Yes, #198 is the same issue. Also https://github.com/MarkPflug/MSBuildGitHash/issues/31

I ended up rolling my own solution. This is my \Directory.Build.targets:

<PropertyGroup>
	<PrepareResourcesDependsOn>
		$(PrepareResourcesDependsOn);
		MySetVersion
	</PrepareResourcesDependsOn>
	<CoreCompileDependsOn>
		$(CoreCompileDependsOn);
		MySetVersion
	</CoreCompileDependsOn>
</PropertyGroup>

<ItemGroup>
	<!-- Force Visual Studio to call MSBuild whenever the version changes, even if a project has no other changes. -->
	<UpToDateCheckInput Include="$(SolutionDir).git\HEAD" />
</ItemGroup>

<Target Name="MySetVersion">
	<Exec Command="git rev-parse HEAD" ConsoleToMSBuild="true" EnvironmentVariables="PATH=$(MSBuildProgramFiles32)\Git\bin%3B$(ProgramW6432)\Git\bin">
		<Output TaskParameter="ConsoleOutput" PropertyName="GitRevision" />
	</Exec>

	<ItemGroup>
		<Compile Include="$(IntermediateOutputPath)GeneratedAssemblyVersion.cs" />
	</ItemGroup>

	<!-- Overwrite and force a recompile even if the version didn't change (jumping between branches of the same commit), -->
	<!-- or Visual Studio still thinks the project needs building because .git\HEAD is newer. -->
	<!-- The new .NET Project System's UpToDateCheckBuilt fixes this small inefficiency. -->
	<WriteLinesToFile
		File="$(IntermediateOutputPath)GeneratedAssemblyVersion.cs"
		Lines="[assembly: System.Reflection.AssemblyVersion(&quot;$(MyVersion).$([System.Convert]::ToInt32($(GitRevision.Substring(0,4)), 16)).$([System.Convert]::ToInt32($(GitRevision.Substring(4,4)), 16))&quot;)]"
		Overwrite="true"
		WriteOnlyWhenDifferent="false" />
</Target>

brunom avatar Jun 08 '22 23:06 brunom

@brunom Very slick, thank you! I'm currently facing a bigger issue #199, but hopefully I can get that resolved and then try this out.

david-wsd avatar Jun 08 '22 23:06 david-wsd

Finally shipping this built-in 💪

kzu avatar Feb 06 '23 23:02 kzu