dotnet / dotnet/sdk

Irrelevant nuget.config on parent directory makes build failure on project directory

Open
#44,897 3 comments 0 reactions 0 assignees View on GitHub
Area-CLI untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

### Describe the bug
Irrelevant `nuget.config` on parent directory makes build failure on project directory.

### To Reproduce
Create a solution directory
```
$ mkdir $HOME/Projects/some-project
```
Initialize a solution with a console project inside the solution directory
```
$ cd $HOME/Projects/some-project
$ dotnet new sln --name SomeProject \
&& dotnet new console --name SomeProject \
&& dotnet sln add SomeProject
```
Test build success
```
$ dotnet build
Determining projects to restore...
All projects are up-to-date for restore.
SomeProject -> /home/huypn12/Projects/some-project/SomeProject/bin/Debug/net8.0/SomeProject.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:03.35
```
Now create an invalid nuget config on the parent directory:
```
$ touch $HOME/Projects/nuget.config
$ tee $HOME/Projects/nuget.config <

EOF
```
Test build: failed
```
$ cd $HOME/Projects/some-project
$ dotnet build
Determining projects to restore...
/usr/share/dotnet/sdk/8.0.404/NuGet.targets(745,5): error : NuGet.Config does not contain the expected root element: 'configuration'. Path: '/home/huypn12/Projects/nuget.config'. [/home/huypn12/Projects/some-project/SomeProject/SomeProject.csproj]

Build FAILED.

/usr/share/dotnet/sdk/8.0.404/NuGet.targets(745,5): error : NuGet.Config does not contain the expected root element: 'configuration'. Path: '/home/huypn12/Projects/nuget.config'. [/home/huypn12/Projects/some-project/SomeProject/SomeProject.csproj]
0 Warning(s)
1 Error(s)
```

### Discussion
Why is such behaviour? Is it because of some recursive `nuget.config` checking?
Perhaps it makes more sense to have `dotnet build` command to check the `nuget.config` file of the current project directory?
Which part of the dotnet sdk is responsible for the behaviour?

### Further technical details
```
.NET SDK:
Version: 8.0.404
Commit: 7b190310f2
Workload version: 8.0.400-manifests.4d7d414a
MSBuild version: 17.11.9+a69bbaaf5

Runtime Environment:
OS Name: debian
OS Version: 12
OS Platform: Linux
RID: linux-x64
Base Path: /usr/share/dotnet/sdk/8.0.404/

.NET workloads installed:
Configured to use loose manifests when installing new manifests.
There are no installed workloads to display.

Host:
Version: 8.0.11
Architecture: x64
Commit: 9cb3b725e3

.NET SDKs installed:
8.0.404 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.11 [/usr/share/dotnet/shared/Microsoft.NETCore.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.