dotnet / dotnet/sdk

Rebuild target doesn't process content files when targeting multiple TFs

Open
#54,076 1 comment 0 reactions 0 assignees View on GitHub
Area-NetSDK untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
Targeting multiple frameworks and referencing a nuget package with `contentfiles` having generator templates makes `--no-incremental` build fail because corresponding files aren't generated. `clean` + `build` works fine, as well as rebuilding for a single framework

### To Reproduce

https://github.com/olstakh/MimeTypesRepro

This repository contains one project (multi TF) referencing one nuget package. Nuget package has `.tt` and `.cs.pp` files in `contentFiles` folder, which generate a `.cs` file during build. Code in the project references this generated file.

`dotnet clean` + `dotnet build` - SUCCESS
`dotnet build --no-incremental -f net10.0` - SUCCESS
`dotnet build --no-incremental` - FAIL

### Exceptions (if any)

Build fails because expected files were not generated during build.

### Pre-investigation

From my limited area knowledge - i gathered the following from looking at a binlog and speaking with ai agents.

Take with a grain of salt.

`dotnet build --no-incremental` translates to MSBuild's `Rebuild` target. With TargetFrameworks (plural), the cross-targeting `Rebuild` target in `Microsoft.Common.CrossTargeting.targets` is:

```xml

```

This dispatches `Clean` and `Build` as separate inner-build invocations to the same project instance (with TargetFramework=net10.0), rather than dispatching `Rebuild` as a single target. This breaks the `_CleaningWithoutRebuilding` protocol:

1. Inner build receives `Clean`: `_SdkBeforeClean` (Microsoft.NET.Sdk.targets) sets `_CleaningWithoutRebuilding=true` (because `_SdkBeforeRebuild` never ran — the inner build target is `Clean`, not `Rebuild`)

2. Inner build receives `Build`: MSBuild reuses the cached project instance from step 1. The property `_CleaningWithoutRebuilding` is still true. The `RunProduceContentAssets` target (which processes `.cs.pp` files into `.cs`) has this condition:

```xml
Condition="'@(_ContentFilesToPreprocess)' != '' and '$(_CleaningWithoutRebuilding)' != 'true'"
```

This evaluates to `false` → the `.cs.pp` file from MimeTypes is never processed → no `.cs` file generated

### Further technical details
details of dotnet --info

```

PS C:\code\MimeTypesRepro> dotnet --info
.NET SDK:
Version: 10.0.107
Commit: b16286c228
Workload version: 10.0.100-manifests.ef86bccd
MSBuild version: 18.0.11+b16286c22

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26200
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.107\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.7
Architecture: x64
Commit: b16286c228

.NET SDKs installed:
6.0.428 [C:\Program Files\dotnet\sdk]
8.0.126 [C:\Program Files\dotnet\sdk]
8.0.420 [C:\Program Files\dotnet\sdk]
9.0.116 [C:\Program Files\dotnet\sdk]
9.0.313 [C:\Program Files\dotnet\sdk]
10.0.107 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.26 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download

```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.