dotnet / dotnet/msbuild

Non-existing path in .slnf results in misleading error message when built through MSBuild task

Open
#13,379 2 comments 1 reaction 2 assignees Claimed by @MichalPavlik View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description

We hit this in https://github.com/dotnet/dotnet/pull/5402/

When building an .slnf file that contains a non-existing path through `` you get this error message instead of one that tells you about the missing path:

```
error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
```

### Steps to Reproduce

1. Download [msbuildbugrepro.zip](https://github.com/user-attachments/files/25967537/msbuildbugrepro.zip) and unpack
2. Run `dotnet build build.proj -t Execute`

### Expected Behavior

When building the .slnf file directly you get a nice error message:
```bash
$ dotnet build filter.slnf
/Users/alexander/dev/test/msbuildbugrepro/solution.slnx : error MSB4025:
The project file could not be loaded. Microsoft.Build.Exceptions.InvalidProjectFileException: Solution filter file at "/Users/alexander/dev/test/msbuildbugrepro/filter.slnf" includes project "RealProject.csproj" that is not in the solution file at "/Users/alexander/dev/te
st/msbuildbugrepro/solution.slnx". /Users/alexander/dev/test/msbuildbugrepro/RealProject.csproj
at Microsoft.Build.Shared.ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile(Boolean condition, String errorSubCategoryResourceName, BuildEventFileInfo projectFile, Exception innerException, String resourceName, Object[] args)
at Microsoft.Build.Construction.SolutionFile.ValidateProjectsInSolutionFilter()
at Microsoft.Build.Construction.SolutionFile.ReadSolutionModel(SolutionModel solutionModel)
at Microsoft.Build.Construction.SolutionFile.ParseUsingNewParser()

Build failed with 1 error(s) in 0.0s
```

### Actual Behavior

Error:
```bash
$ dotnet build build.proj -t Execute
Restore complete (0.0s)
failed with 1 error(s) (0.0s)
/Users/alexander/dev/test/msbuildbugrepro/filter.slnf(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.

Build failed with 1 error(s) in 0.1s
```

### Analysis

_No response_

### Versions & Configurations

```
.NET SDK:
Version: 11.0.100-preview.3.26161.119
Commit: da71424348
Workload version: 11.0.100-manifests.30df970d
MSBuild version: 18.6.0-preview-26161-119+da7142434
```

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.