dotnet format doesn't write to disk after updating to dotnet SDK 9.0.200
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
### Describe the bug
`dotnet format` doesn't write formatting changes back to the file after updating the dotnet SDK to 9.0.200. It works up to 9.0.102.
### To Reproduce
1. Create a file named `csharp_bad_01.cs` in the current working directory with the following contents (ensure to respect spaces and blank lines):
```cs
using System;
namespace HelloWorld {
class Program {
static void Main(string[] args) {
Console.WriteLine("Hello World");
}
}
}
```
1. Run `docker run --rm -it --entrypoint /bin/ash -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:9.0.200-alpine3.21`
1. Run `cd /app`
1. Hash the content of the file: `sha256sum csharp_bad_01.cs`. Output:
```
813c093e202045f5f6c88ab88e988aafd2120feb6479b0e667717714d1e4e39d csharp_bad_01.cs
```
1. Run `dotnet format whitespace --folder --exclude / --include csharp_bad_01.cs -v diag --verify-no-changes`. Output:
```
Formatting code files in workspace '/app/'.
Loading workspace.
Complete in 1271ms.
Determining formattable files.
Complete in 191ms.
Running formatters.
/app/csharp_bad_01.cs(3,21): error WHITESPACE: Fix whitespace formatting. Replace 1 characters with '\n'. [/app//]
/app/csharp_bad_01.cs(4,3): error WHITESPACE: Fix whitespace formatting. Insert '\s\s'. [/app/]
/app/csharp_bad_01.cs(4,16): error WHITESPACE: Fix whitespace formatting. Replace 1 characters with '\n\s\s\s\s'. [/app/]
/app/csharp_bad_01.cs(5,5): error WHITESPACE: Fix whitespace formatting. Insert '\s\s\s\s'. [/app/]
/app/csharp_bad_01.cs(5,36): error WHITESPACE: Fix whitespace formatting. Replace 1 characters with '\n\s\s\s\s\s\s\s\s'. [/app/]
/app/csharp_bad_01.cs(6,7): error WHITESPACE: Fix whitespace formatting. Insert '\s\s\s\s\s\s'. [/app/]
/app/csharp_bad_01.cs(7,5): error WHITESPACE: Fix whitespace formatting. Insert '\s\s\s\s'. [/app/]
/app/csharp_bad_01.cs(8,3): error WHITESPACE: Fix whitespace formatting. Insert '\s\s'. [/app/]
Complete in 436ms.
Formatted code file '/app/csharp_bad_01.cs'.
Formatted 1 of 1 files.
Format complete in 1899ms.
/app/test/linters/csharp # exit
exit status 2
```
1. Run `dotnet format whitespace --folder --exclude / --include csharp_bad_01.cs -v diag`. Output:
```
Formatting code files in workspace '/app/'.
Loading workspace.
Complete in 1257ms.
Determining formattable files.
Complete in 191ms.
Running formatters.
Complete in 467ms.
Formatted code file '/app/csharp_bad_01.cs'.
Formatted 1 of 1 files.
Format complete in 1978ms.
```
1. Hash the content of the file: `sha256sum csharp_bad_01.cs`, observing that it has the same hash as before, and the same content. Output:
```
813c093e202045f5f6c88ab88e988aafd2120feb6479b0e667717714d1e4e39d csharp_bad_01.cs
```
If you repeat the steps described above using the `9.0.102-alpine3.21` container image, you can observe that `dotnet format` correctly writes the formatted file.
### Exceptions (if any)
### Further technical details
- Include the output of `dotnet --info`:
```
/ # dotnet --info
.NET SDK:
Version: 9.0.200
Commit: 90e8b202f2
Workload version: 9.0.200-manifests.b4a8049f
MSBuild version: 17.13.8+cbc39bea8
Runtime Environment:
OS Name: alpine
OS Version: 3.21
OS Platform: Linux
RID: linux-musl-x64
Base Path: /usr/share/dotnet/sdk/9.0.200/
.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.2
Architecture: x64
Commit: 80aa709f5d
.NET SDKs installed:
9.0.200 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 9.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 9.0.2 [/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
```
Also, not sure if #46780 is related to this.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.