Stale info on unrelated changes
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 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 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("$(MyVersion).$([System.Convert]::ToInt32($(GitRevision.Substring(0,4)), 16)).$([System.Convert]::ToInt32($(GitRevision.Substring(4,4)), 16))")]"
Overwrite="true"
WriteOnlyWhenDifferent="false" />
</Target>
@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.
Finally shipping this built-in 💪