dotnet / dotnet/format

MSBuild failures/warnings returns zero exit code

Open
#1,453 2 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
1.9k
Forks
173
Avg merge
10d 13h
Merged PRs (30d)
1

Description

I do not know of any other way to trigger this. Hence, I will demonstrate with [Paket](https://github.com/fsprojects/Paket) and missing references.

**Reproduction**
1. Clone this repo: https://github.com/Arthri/dotnet-format-missingref. This repo cuts the steps required, but to create a similar repo, refer to Reproduction Full.
2. Run `dotnet tool restore`
3. Do NOT run `dotnet paket restore`. Pretend this is a mistake
4. Run `dotnet format MissingRef.sln`. The command fails(output is below) to format anything, but returns a zero exit code indicating it succeeded. Therefore the mistake from earlier was not caught and this will lead to CI checks succeeding despite format errors.

**Reproduction Full**
1. Create a new folder
2. Create a new project(put sln and csproj in same folder)
3. Install Paket and dotnet-format
4. Run `dotnet paket init`
5. Register `Microsoft.Extensions.DependencyInjection` to Paket, this can be done by adding "`Microsoft.Extensions.DependencyInjection`" into paket.references and "`nuget Microsoft.Extensions.DependencyInjection`" paket.dependencies.
6. Run `dotnet paket install`
7. Delete `.paket`. Simulate a mistake
8. Run `dotnet format [PROJECT].sln`

**Output**
```
Formatting code files in workspace 'C:\Users\[USER]\[REPO_PATH]\MissingRef.sln'.
Warnings were encountered while loading the workspace. Set the verbosity option to the 'diagnostic' level to log warnings.
Format complete in 2134ms.
```

**Diagnostic Output**
```
The dotnet format version is '5.1.250801+4a851ea9707f87d381166c2fc2b2d4b58a10a222'.
The dotnet runtime version is '5.0.7'.
The dotnet CLI version is '5.0.301'.
Using MSBuild.exe located in 'C:\Program Files\dotnet\sdk\5.0.301\'.
Formatting code files in workspace 'C:\Users\[USER]\[REPO_PATH]\MissingRef.sln'.
Loading workspace.
Msbuild failed when processing the file 'C:\Users\[USER]\[REPO_PATH]\MissingRef.csproj' with message: The imported project "C:\Users\[USER]\[REPO_PATH]\.paket\Paket.Restore.targets" was not found. Confirm that the expression in the Import declaration ".paket\Paket.Restore.targets" is correct, and that the file exists on disk. C:\Users\[USER]\[REPO_PATH]\MissingRef.csproj
Complete in 1374ms.
Determining formattable files.
Complete in 7ms.
Running formatters.
Complete in 7ms.
Formatted 0 of 0 files.
Format complete in 1392ms.
```

Both outputs, despite failing to load then format the project, returned an unexpected zero exit code. I noticed this on a CI where it would continue "succeed" despite my local copy telling me there's format errors.

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.