Skip to content

Potential incrementality issue in GenerateTargetFrameworkMonikerAttribute #9840

Open
@KirillOsenkov

Description

<Target Name="GenerateTargetFrameworkMonikerAttribute"
BeforeTargets="BeforeCompile"
DependsOnTargets="PrepareForBuild;GetReferenceAssemblyPaths"
Inputs="$(MSBuildToolsPath)\Microsoft.Common.targets"
Outputs="$(TargetFrameworkMonikerAssemblyAttributesPath)"
Condition="'@(Compile)' != '' and '$(GenerateTargetFrameworkAttribute)' == 'true'">
<!-- This is a file shared between projects so we have to take care to handle simultaneous writes (by ContinueOnError)
and a race between clean from one project and build from another (by not adding to FilesWritten so it doesn't clean) -->
<WriteLinesToFile
File="$(TargetFrameworkMonikerAssemblyAttributesPath)"
Lines="$(TargetFrameworkMonikerAssemblyAttributeText)"
Overwrite="true"
ContinueOnError="true"
Condition="'@(Compile)' != '' and '$(TargetFrameworkMonikerAssemblyAttributeText)' != ''"
/>
<ItemGroup Condition="'@(Compile)' != '' and '$(TargetFrameworkMonikerAssemblyAttributeText)' != ''">
<Compile Include="$(TargetFrameworkMonikerAssemblyAttributesPath)"/>
<!-- Do not put in FileWrites: this is a file shared between projects in %temp%, and cleaning it would create a race between projects during rebuild -->
</ItemGroup>
</Target>

I think the problem is that the condition on the target doesn't match the condition on the WriteLinesToFile task. I think we should add and '$(TargetFrameworkMonikerAssemblyAttributeText)' != '' to the Condition on the Target.

Otherwise we get this:
image

The target runs (because the output file doesn't exist), but then the tasks are skipped because the text is empty, and so it doesn't write the file again.

It's benign, but would be nice to get it out of the way for build incrementality investigations (the less targets run in an incremental build the easier it is to see targets which are breaking incrementality and shouldn't be running)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions