Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet watch run completely broken for F# #44908

Open
isaacabraham opened this issue Nov 16, 2024 · 16 comments
Open

dotnet watch run completely broken for F# #44908

isaacabraham opened this issue Nov 16, 2024 · 16 comments
Labels
Area-Watch untriaged Request triage from a team member

Comments

@isaacabraham
Copy link

Describe the bug

Using dotnet watch run does not work for F# applications. It won't start the application at all.

This is the output I get:

PS D:\code\TodoService\src\app> dotnet watch run
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
  💡 Press "Ctrl + R" to restart.
Using launch settings from D:\code\TodoService\src\app\Properties\launchSettings.json...
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...

At this point, the application should be running, but isn't. Notice how it is trying to use hot reload which doesn't support F#.

When I make a change to the application code (which should trigger a standard watch run restart), sure enough I get this:

dotnet watch ❌ System.InvalidOperationException: Cannot open project 'D:\code\TodoService\src\app\app.fsproj' because the file extension '.fsproj' is not associated with a language.
   at Microsoft.CodeAnalysis.MSBuild.DiagnosticReporter.Report(DiagnosticReportingMode mode, String message, Func`2 createException)
   at Microsoft.CodeAnalysis.MSBuild.ProjectFileExtensionRegistry.TryGetLanguageNameFromProjectPath(String projectFilePath, DiagnosticReportingMode mode, String& languageName)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectFileInfosAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadProjectInfosFromPathAsync(String projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.Worker.LoadAsync(CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadProjectInfoAsync(String projectFilePath, ProjectMap projectMap, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
   at Microsoft.CodeAnalysis.MSBuild.MSBuildProjectLoader.LoadProjectInfoAsync(String projectFilePath, ProjectMap projectMap, IProgress`1 progress, ILogger msbuildLogger, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.Tools.IncrementalMSBuildWorkspace.UpdateProjectConeAsync(String rootProjectPath, CancellationToken cancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(CancellationToken shutdownCancellationToken)
   at Microsoft.DotNet.Watcher.Program.RunAsync()
dotnet watch ❌ An unexpected error occurred

Fsproj is indeed associated with a language - F#. It's just that hot reload doesn't know about it. It's completely broken.

Using dotnet run works, thankfully:

PS D:\code\TodoService\src\app> dotnet run
Using launch settings from D:\code\TodoService\src\app\Properties\launchSettings.json...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
      Content root path: D:\code\TodoService\src\app

To Reproduce

I have an F#9 project which uses the Web SDK. It doesn't use anything else really - standard nuget etc.

Further technical details

  • Include the output of dotnet --info
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version
.NET SDK:
 Version:           9.0.100
 Commit:            59db016f11
 Workload version:  9.0.100-manifests.c6f19616
 MSBuild version:   17.12.7+5b8665660

Running on Win 11.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Watch untriaged Request triage from a team member labels Nov 16, 2024
@baronfel
Copy link
Member

cc @tmat

@forki
Copy link

forki commented Nov 16, 2024

Noticed that as well and I assumed I messed up my setup

@isaacabraham
Copy link
Author

This would be extremely undesirable to leave in for any period of time - F# web applications rely heavily on this (the entire SAFE Stack is built upon a watch mode for both client and server for example).

@forki
Copy link

forki commented Nov 16, 2024

Also dotnet aspire is broken for F# users.
/cc @davidfowl

@baronfel
Copy link
Member

Using the Roslyn MSBuild APIs directly likely won't work for any project type that is non-Roslyn. I'd expect watch for esproj for example to be broken similarly based on this stack.

@forki
Copy link

forki commented Nov 17, 2024

@vzarytovskii

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 17, 2024

@vzarytovskii

Nothing actionable for us here, unfortunately, Roslyn/watch team needs to fix it.

@vzarytovskii
Copy link
Member

Also, I assume --no-hot-reload still works? It should be automatically enabled for F# projects

@tmat
Copy link
Member

tmat commented Nov 18, 2024

Yes, a workaround is to pass --no-hot-reload.

@forki
Copy link

forki commented Nov 18, 2024

How is that a workaround?

@tmat
Copy link
Member

tmat commented Nov 18, 2024

@forki Passing --no-hot-reload makes dotnet-watch work as expected until a fix is available.

@vzarytovskii
Copy link
Member

vzarytovskii commented Nov 18, 2024

How is that a workaround?

Proper hot reload was never supported in F#. @tmat do you know what changed to default behaviour, so it's failing in F# now, did no-hot-reload become default in net8, and now is off-by-default in net9?

@forki
Copy link

forki commented Nov 18, 2024

Well it worked in fable. But yes for dotnet watch run, changes in fsproj or fs files did a recompile and restart. Which would be OK if this works properly again

@isaacabraham
Copy link
Author

How is that a workaround?

Proper hot reload was never supported in F#. @tmat do you know what changed to default behaviour, so it's failing in F# now, did no-hot-reload become default in net8, and now is off-by-default in net9?

Even if that were the case, it should only be on-by-default for C# projects - the rest of everything will break, and there's no need to enforce an extra cmdline parameter on everyone because of this.

@tmat
Copy link
Member

tmat commented Nov 19, 2024

@isaacabraham What about F# projects that have C# dependencies and vice versa? Would you expect Hot Reload work for C# code and trigger rebuild for changes in F# code?

@JordanMarr
Copy link

For anyone else affected by this issue, my workaround is to add the following file:

global.json

{
  "sdk": {
    "version": "8.0.100",
    "rollForward": "latestMinor",
    "allowPrerelease": false
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Watch untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

6 participants