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

Stale info on unrelated changes #186

Closed
brunom opened this issue Mar 16, 2022 · 4 comments · Fixed by #226
Closed

Stale info on unrelated changes #186

brunom opened this issue Mar 16, 2022 · 4 comments · Fixed by #226

Comments

@brunom
Copy link

brunom commented Mar 16, 2022

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 brunom added the bug label Mar 16, 2022
@david-wsd
Copy link

@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.

@brunom
Copy link
Author

brunom commented Jun 8, 2022

@david-wsd Yes, #198 is the same issue. Also MarkPflug/MSBuildGitHash#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>

@david-wsd
Copy link

@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.

kzu added a commit that referenced this issue Feb 6, 2023
When the current HEAD (branch/tag/commit) is changed within VS, we currently don't surface any changes and the IDE thinks there's nothing to update. But obviously GitInfo would need to calculate again all the info.

This commit takes the ideas from #186 by @brunom, integrates into GitInfo and surfaces it to VS seamlessly so users don't have to customize anything and it Just Works.

Closes #186
kzu added a commit that referenced this issue Feb 6, 2023
When the current HEAD (branch/tag/commit) is changed within VS, we currently don't surface any changes and the IDE thinks there's nothing to update. But obviously GitInfo would need to calculate again all the info.

This commit takes the ideas from #186 by @brunom, integrates into GitInfo and surfaces it to VS seamlessly so users don't have to customize anything and it Just Works.

Closes #186
@kzu kzu added enhancement and removed bug labels Feb 6, 2023
@kzu
Copy link
Member

kzu commented Feb 6, 2023

Finally shipping this built-in 💪

@kzu kzu closed this as completed in #226 Feb 6, 2023
kzu added a commit that referenced this issue Feb 6, 2023
When the current HEAD (branch/tag/commit) is changed within VS, we currently don't surface any changes and the IDE thinks there's nothing to update. But obviously GitInfo would need to calculate again all the info.

This commit takes the ideas from #186 by @brunom, integrates into GitInfo and surfaces it to VS seamlessly so users don't have to customize anything and it Just Works.

Closes #186
@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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants