Skip to content

Commit 69cc38c

Browse files
committed
Re-run WriteVerifyAttributes when the values change
The up-to-date check compared only $(MSBuildAllProjects) timestamps against the generated file, but the content comes from $(SolutionDir), $(SolutionName) and $(TargetFrameworks). So rebuilding with a different /p:SolutionDir or /p:SolutionName, which is exactly what the DiscoverSolutionInfo warnings tell users to pass, or building the same project from another solution, skipped the target and CoreCompile and left stale metadata in the assembly for AttributeReader and DerivePaths to read at test time. Only a full Rebuild or touching the csproj cleared it. The values are now written to a cache file with WriteOnlyWhenDifferent, and that file is an input, so its timestamp moves only on a real change. Same pattern as the SDK's GenerateAssemblyInfo. Verified by building, then rebuilding with /p:SolutionName=OtherSolution: before this the emitted Verify.SolutionName stayed at the old value, now it updates.
1 parent d731cfb commit 69cc38c

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

src/Verify/buildTransitive/Verify.props

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,21 @@
9090
</PropertyGroup>
9191
</Target>
9292

93-
<Target Name="WriteVerifyAttributes"
93+
<!-- The generated values come from properties, not from the files the up-to-date check can
94+
see, so they are written to a cache file with WriteOnlyWhenDifferent: its timestamp
95+
moves only when a value actually changes, which is what makes WriteVerifyAttributes
96+
below re-run. This mirrors the SDK's GenerateAssemblyInfo.
97+
Without it, only $(MSBuildAllProjects) timestamps were compared, so rebuilding with a
98+
different /p:SolutionDir or /p:SolutionName (exactly what the DiscoverSolutionInfo
99+
warnings above tell users to pass), or building the same project from another
100+
solution, skipped the target and left stale Verify.SolutionDirectory and
101+
Verify.SolutionName metadata in the assembly until a full Rebuild. -->
102+
<Target Name="WriteVerifyAttributesCache"
94103
Condition="$(Language) == 'VB' or $(Language) == 'C#' or $(Language) == 'F#' or $(Language) == 'X#'"
95-
DependsOnTargets="DiscoverSolutionInfo"
96-
BeforeTargets="BeforeCompile;CoreCompile"
97-
Inputs="$(MSBuildAllProjects)"
98-
Outputs="$(IntermediateOutputPath)$(VerifyAttributesFile)">
104+
DependsOnTargets="DiscoverSolutionInfo">
99105
<PropertyGroup>
100106
<VerifyAttributesFilePath>$(IntermediateOutputPath)$(VerifyAttributesFile)</VerifyAttributesFilePath>
107+
<VerifyAttributesCacheFile>$(IntermediateOutputPath)Verify.Attributes.cache</VerifyAttributesCacheFile>
101108
<!-- IntermediateOutputPath is relative to the project for the default layout, but absolute for
102109
others (eg artifacts output), so combine rather than concatenate. -->
103110
<VerifyIntermediateDirectory>$([System.IO.Path]::Combine('$(MSBuildProjectDirectory)', '$(IntermediateOutputPath)'))</VerifyIntermediateDirectory>
@@ -132,6 +139,21 @@
132139
<!-- Ensure not part of Compile, as a workaround for https://github.com/dotnet/sdk/issues/114 -->
133140
<Compile Remove="$(VerifyAttributesFilePath)" />
134141
</ItemGroup>
142+
<MakeDir Directories="$(IntermediateOutputPath)" />
143+
<WriteLinesToFile File="$(VerifyAttributesCacheFile)"
144+
Lines="@(VerifyAttributes->'%(_Parameter1)=%(_Parameter2)')"
145+
Overwrite="true"
146+
WriteOnlyWhenDifferent="true" />
147+
<ItemGroup>
148+
<FileWrites Include="$(VerifyAttributesCacheFile)" />
149+
</ItemGroup>
150+
</Target>
151+
<Target Name="WriteVerifyAttributes"
152+
Condition="$(Language) == 'VB' or $(Language) == 'C#' or $(Language) == 'F#' or $(Language) == 'X#'"
153+
DependsOnTargets="WriteVerifyAttributesCache"
154+
BeforeTargets="BeforeCompile;CoreCompile"
155+
Inputs="$(MSBuildAllProjects);$(IntermediateOutputPath)Verify.Attributes.cache"
156+
Outputs="$(IntermediateOutputPath)$(VerifyAttributesFile)">
135157
<WriteCodeFragment AssemblyAttributes="@(VerifyAttributes)"
136158
Language="$(Language)"
137159
OutputFile="$(VerifyAttributesFilePath)">

0 commit comments

Comments
 (0)