dotnet / dotnet/sdk

Sdk.props improperly imports Microsoft.Common.props unconditionally

Open
#50,573 0 comments 0 reactions 1 assignee Claimed by @dsplaisted View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug

The [Microsoft.Common.props](https://github.com/dotnet/msbuild/blob/main/src/Tasks/Microsoft.Common.props#L98) provides a property `$(MicrosoftCommonPropsHasBeenImported)` to signal that it has already been imported.

But the [Sdk.props](https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/sdk/Sdk.props#L49) imports the props unconditionally, which can cause unwanted warnings if a custom SDK already imports it to properly initialize default paths in that targets file.

### To Reproduce

In a custom SDK's Sdk.props, import the common props:

```xml


```

Then a regular project would use the custom SDK and also import the .NET SDK as usual:

```xml


Exe
net10.0

```

Full repro in the following repo: https://github.com/kzu/SdkBug/

### Exceptions (if any)

```
pwsh> dotnet restore
C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props(49,3): warning MSB4011: "C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Users\danie\.nuget\packages\customsdk\42.42.42\Sdk\Sdk.props (2,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\Delete\SdkBug\Repro\Repro.csproj]
C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props(49,3): warning MSB4011: "C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\Current\Microsoft.Common.props" cannot be imported again. It was already imported at "C:\Users\danie\.nuget\packages\customsdk\42.42.42\Sdk\Sdk.props (2,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\Delete\SdkBug\Repro\Repro.csproj]
Restore complete (0.6s)
```

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

```
.NET SDK:
Version: 10.0.100-preview.7.25380.108
Commit: 30000d883e
Workload version: 10.0.100-manifests.8bb6be96
MSBuild version: 17.15.0-preview-25380-108+30000d883

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.7.25380.108\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host:
Version: 10.0.0-preview.7.25380.108
Architecture: x64
Commit: 30000d883e

.NET SDKs installed:
8.0.413 [C:\Program Files\dotnet\sdk]
9.0.304 [C:\Program Files\dotnet\sdk]
10.0.100-preview.7.25380.108 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-preview.7.25380.108 [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.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-preview.7.25380.108 [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.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-preview.7.25380.108 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

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.