dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

[Bug]: Deleted embedded resources dont cause rebuild #10644

Open innominateAtWork opened 1 month ago

innominateAtWork commented 1 month ago

Issue Description

dotnet build does not detect deleted EmbeddedResources.

Steps to Reproduce

  1. Download example project from https://github.com/innominateAtWork/NoRebuildWhenDeleteEmbeddedResource
  2. dotnet run it outputs all files included as EmbeddedResources in MyApp.csproj and their content
  3. Change the text in File1.txt
  4. dotnet run the project rebuilds and includes the updated text
  5. Delete File1.txt
  6. dotnet run the project does NOT rebuild the run looks identical to the prior run

Expected Behavior

MyApp rebuilds because an EmbeddedResources has been deleted.

Actual Behavior

MyApp does NOT rebuild.

Analysis

No response

Versions & Configurations

MSBuild version 17.11.3+0c8610977 for .NET 17.11.3.35201

innominateAtWork commented 1 month ago

Similarly adding a File3.txt also does not cause rebuild

AR-May commented 1 month ago

Team triage: @JaynieBai! Could you please try to repro and collect binlogs for this issue?

JaynieBai commented 1 month ago

@AR-May I repro this issue locally. Here is the log when delete the File1.txt. there is no File1.txt shown in the binlog. CentralNode_dotnet_PID=24032_x64_BuildManager_Default.binlog.txt

But when delete the File1.txt and save the other files in the project folder. The date modified is updated. It will rebuild the project and output different result.

JaynieBai commented 1 month ago

Similarly adding a File3.txt also does not cause rebuild

Can't repro this one

AR-May commented 1 month ago

Thank you @JaynieBai! @rainersigwald the incremental build scenario is broken when one tries to delete from EmbeddedResources, but no other change is present. It seems like the CoreCompile target is skipped due to all outputs being newer than all inputs, which is true, but not correct. The only change since the previous build is deleted File1.txt and it is absent from inputs as well, so this change does not trigger the re-compilation of assembly.

innominateAtWork commented 1 month ago

It looks like copying a file does not trigger a rebuild, but creating a new file does.

> dotnet run
MyApp.File1.txt = A
MyApp.File2.txt = B
> cp File2.txt File3.txt
> dotnet run
MyApp.File1.txt = A
MyApp.File2.txt = B
> echo C > File4.txt
> dotnet run
MyApp.File1.txt = A
MyApp.File2.txt = B
MyApp.File3.txt = B
MyApp.File4.txt = C
rainersigwald commented 1 month ago

Ah that makes sense and we should fix it by bringing back https://github.com/dotnet/msbuild/pull/6780.