dotnet / dotnet/project-system

CopyToOutputDirectory item in shared project can cause overbuild

Open
#8,157 0 comments 1 reaction 0 assignees View on GitHub
Feature-Up-to-date Performance-Scenario-Build Triage-Approved
Dominant language
C#
Stars
1k
Forks
415
PR merge metrics
No merged PRs in 30d

Description

## Visual Studio Version

Version 17.3.0 Preview 2.0 [32509.2.main]

## Summary

Adding a `CopyToOutputDirectory="PreserveNewest"` item in a shared project can make the referencing project overbuild.

Observed in Roslyn's `Compilers.sln`, leading to overbuild of `csc-arm64.csproj`.

## Steps to Reproduce

1. Create a console app
2. Create a shared project
3. Add a text file as a `None` item to the shared project (manually editing the `.projitems` file)
4. Build the console app a few times

Or just open and build this solution: [SharedProjectCopyToOutputDirectoryOverbuildBug.zip](https://github.com/dotnet/project-system/files/8666608/OverbuildSharedProjectCopyToOutoutDirectoryBug.zip)

## Expected Behavior

Incremental build identifies the project as up-to-date.

## Actual Behavior

Incremental build fails, building the project is each time (overbuild).

```
Checking None item with CopyToOutputDirectory="PreserveNewest" 'c:\Repo\SharedProject1\TextFile1.txt':
Source 11/05/2022 13:37:32: 'c:\Repo\SharedProject1\TextFile1.txt'
Destination 'c:\Repo\ConsoleApp1\bin\Debug\net6.0\..\SharedProject1\TextFile1.txt' does not exist, not up-to-date.
```

## User Impact

Reduces productivity while waiting for avoidable builds.

This is not likely to be a very common scenario, though it does impact our partner team Roslyn.

## Analysis

Likely due to this:

https://github.com/dotnet/project-system/blob/d1b8455fbe4868b6a837e0167ab4d8be8f9169a5/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UpToDate/BuildUpToDateCheck.cs#L682

## Workaround

Move the `CopyToOutputDirectory` item to the referencing `.csproj` project(s).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.