dotnet watch run or build suddenly started failing with Sdk.Web, > 8.0.206 and Paket.
- Dominant language
- C#
- Stars
- 3.2k
- Forks
- 1.3k
- PR merge metrics
- PR metrics pending
Description
This is related to [this issue](https://github.com/SAFE-Stack/SAFE-template/issues/621), around a breaking change somewhere after .NET 8.0.206 that is impacted (as far as I can tell) from the following convergence:
1. You are using the `Microsoft.NET.Sdk.Web` SDK.
1. You are using an SDK later than 8.0.206 (I've used up to 401 and can reliably reproduce this).
1. You are using Paket as your .NET package management client.
> This issue is not confined to F#. It also impacts C# projects.
If all of these things are true and you `dotnet watch build` or `run` from the folder of the project, things go wrong. I suspect it's something that's changed since 8.0.206 (or the Sdk.Web) that has somehow broken Paket.
We have seen this with multiple customers of SAFE Stack, which uses Paket and ASP .NET Core - when people upgraded to 8.0.3xx, things started going wrong with no code changes at all.
[This repository](https://github.com/CompositionalIT/webwatchissue) contains a working reproduction of the issue using F#, whilst [this repository](https://github.com/CompositionalIT/webwatchissue-cs) contains an even simpler repro of the issue using C#.
Here are some steps to reproduce:
1. Install a version of .NET 8.0 after 8.0.206 (I'm using 8.0.401).
1. Make a clean folder and `cd` to it.
1. `dotnet new globaljson`
1. Set it to e.g.
```json
{
"sdk": {
"version": "8.0.401"
}
}
```
1. `dotnet new console -lang F#`
1. `dotnet tool install paket --create-manifest-if-needed`
1. `dotnet paket add FSharp.Core`
1. Change the SDK in the project file.
Now, observe the following behaviours:
### dotnet watch build ❌
```cmd
dotnet watch � Started
Determining projects to restore...
Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.
File name: 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
at System.Reflection.RuntimeAssembly.GetType(QCallAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive, ObjectHandleOnStack assemblyLoadContext)
at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
at System.Reflection.Assembly.GetType(String name, Boolean throwOnError)
at System.StartupHookProvider.CallStartupHook(StartupHookNameOrPath startupHook)
at System.StartupHookProvider.ProcessStartupHooks()
D:\code\runthru\.paket\Paket.Restore.targets(171,3): error MSB3073: The command "dotnet paket restore" exited with code -532462766. [D:\code\runthru\runthru.fsproj]
Build FAILED.
```
### `dotnet watch run` ❌
```cmd
error MSB3073: The command "dotnet paket restore" exited with code -532462766
```
## Workarounds
* Don't use `watch`; `dotnet build` and `dotnet run` on their own work. ✅
* Change `global.json` to pin to 8.0.206. ✅
* Change the `fsproj` SDK to `Microsoft.NET.Sdk` ✅
* Add `--no-restore` to either `watch run` or `watch build`. ✅
## Observations
* Something has changed in the behaviour of `dotnet watch` after 8.0.206 of the SDK. That's the last working version of .NET 8 that I could find.
* There's evidently a difference in behaviour from watch and non-watch versions of `dotnet build` and `dotnet run`. This shouldn't be the case.
* It's somehow linked to the Web SDK. The regular SDK works fine.
cc: @baronfel - he has been unable to reproduce this on his machine at all :-(
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.