dotnet / dotnet/sdk

Running `/t:Clean;Build` suppresses NuGet warnings

Open
#55,505 3 comments 0 reactions 0 assignees View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

_Following was generated with help from copilot, but the issue and the contents in this issue was verified._

When an SDK-style project is built using:

```powershell
msbuild "/t:Clean;Build"
```

NuGet asset warnings stored in `project.assets.json`, such as `NU1701`, are not emitted during the Build phase.

A normal Build reports the warning correctly:

```powershell
msbuild /t:Build
```

The issue occurs because `_SdkBeforeClean` sets `EmitAssetsLogMessages` to `false`:

```xml


<_CleaningWithoutRebuilding>true
false

```

This state remains active during the subsequent Build target, causing `ResolvePackageAssets` to suppress valid NuGet diagnostics.

#### Environment

Originally observed with:

```text
.NET SDK: 10.0.302
MSBuild: 18.5.4
OS: Windows
```

The minimal reproduction also occurs with:

```text
.NET SDK: 11.0.100-preview.5
MSBuild: 18.8.0-preview
OS: Windows
```

### Steps to reproduce

#### Minimal reproduction

Create `Repro.csproj`:

```xml


net8.0



```

Create `Class1.cs`:

```csharp
public class Class1
{
}
```

Restore the project:

```powershell
dotnet restore
```

The restore reports `NU1701`, as expected, because the package only contains .NET Framework assets.

#### Normal Build

```powershell
dotnet msbuild /t:Build
```

`NU1701` is reported:

```text
warning NU1701: Package 'Microsoft.Web.Infrastructure 1.0.0'
was restored using .NET Framework assets instead of the project
target framework 'net8.0'.
```

#### Clean followed by Build

```powershell
dotnet msbuild "/t:Clean;Build"
```

The project builds successfully, but `NU1701` is not reported.

#### Results

| Invocation | NU1701 reported |
|---|---:|
| `/t:Build` | Yes |
| `/t:Clean;Build` | No |
| `/t:Clean;Build /p:_CleaningWithoutRebuilding=false` | Yes |

### Expected behavior

`EmitAssetsLogMessages` should be disabled only while performing a standalone Clean.

When Clean and Build are requested in the same invocation, package asset diagnostics should be enabled during the Build phase.

### Actual behavior

`_SdkBeforeClean` sets:

```text
_CleaningWithoutRebuilding=true
EmitAssetsLogMessages=false
```

These values persist into the Build phase. Consequently, `ResolvePackageAssets` does not emit warnings recorded in `project.assets.json`.

### Is this a regression?

_No response_

### Are there any workarounds?

```powershell
msbuild "/t:Clean;Build" /p:_CleaningWithoutRebuilding=false
```

With this property set, `NU1701` is reported again.

### dotnet --info output

```console

```

### IDE version

_No response_

### Other details

_No response_

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the _SdkBeforeClean target and the EmitAssetsLogMessages and _CleaningWithoutRebuilding properties described in the issue, then trace how ResolvePackageAssets uses them during a "/t:Clean;Build" invocation. Use the Repro.csproj and Class1.cs minimal reproduction, compare normal Build with Clean followed by Build, and confirm that NU1701 is reported during the Build phase.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.