SAFE-Stack / SAFE-template

dotnet CLI template for SAFE project
MIT License
283 stars 87 forks source link

Error on dotnet run out of the box #537

Closed EspenBrun closed 1 year ago

EspenBrun commented 1 year ago

Hello,

I just installed the latest template 4.1.1, and tried running it (I did dotnet tool restore first) and out of the box I get an error for dotnet run. The command that fails from Build.fs is dotnet watch run --project src/Server/Server.fsproj. When I just run dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0" though, that command works fine.

dotnet watch run --project src/Server/Server.fsproj
dotnet watch 🚀 Started
/Users/espen/code/dotnet-new-safe-4.1.1/.paket/Paket.Restore.targets(219,5): error MSB3073: The command "dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"" exited with code 134. [/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj]

The build failed. Fix the build errors and run again.
dotnet watch ❌ Exited with error code 1
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
^Cdotnet watch 🛑 Shutdown requested. Press Ctrl+C again to force exit.
olivercoad commented 1 year ago

It looks like you're using Windows but what version(s) of dotnet do you have installed? Can you please show the output of dotnet --info and paste the full logs of running dotnet run?

Also in my Build.fs it does dotnet watch run from the working directory src/Server, and doesn't use --project. Is that something you changed yourself? Does it make a difference if you cd into src/Server and then just do dotnet watch run?

EspenBrun commented 1 year ago

Thanks for the reply!

I'm on a mac. The output of dotnet --info

~/code/dotnet-new-safe-4.1.1 master
❯ dotnet --info   
.NET SDK (reflecting any global.json):
 Version:   6.0.401
 Commit:    0906eae6f8

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.0
 OS Platform: Darwin
 RID:         osx-x64
 Base Path:   /usr/local/share/dotnet/sdk/6.0.401/

global.json file:
  /Users/espen/code/dotnet-new-safe-4.1.1/global.json

Host:
  Version:      6.0.9
  Architecture: x64
  Commit:       163a63591c

.NET SDKs installed:
  2.2.401 [/usr/local/share/dotnet/sdk]
  3.0.103 [/usr/local/share/dotnet/sdk]
  3.1.200 [/usr/local/share/dotnet/sdk]
  3.1.405 [/usr/local/share/dotnet/sdk]
  3.1.406 [/usr/local/share/dotnet/sdk]
  5.0.102 [/usr/local/share/dotnet/sdk]
  5.0.103 [/usr/local/share/dotnet/sdk]
  5.0.404 [/usr/local/share/dotnet/sdk]
  6.0.400 [/usr/local/share/dotnet/sdk]
  6.0.401 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.2.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.8 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Download .NET:
  https://aka.ms/dotnet-download

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

Full log of dotnet run:

~/code/dotnet-new-safe-4.1.1 master
❯ dotnet run   
run Run
Building project with version: LocalBuild
Shortened DependencyGraph for Target Run:
<== Run
   <== InstallClient
      <== Clean

The running order is:
Group - 1
  - Clean
Group - 2
  - InstallClient
Group - 3
  - Run
Starting target 'Clean'
> "/usr/local/bin/mono" --version (In: false, Out: true, Err: true)
/Users/espen/code/dotnet-new-safe-4.1.1/src/Client> "dotnet" fable clean --yes (In: false, Out: false, Err: false)
Fable: F# to JS compiler 3.7.5
Stop Russian aggression against Ukraine!

This will recursively delete all *.fs.js[.map] files in /Users/espen/code/dotnet-new-safe-4.1.1/src/Client
Deleted output/fable_modules
Clean completed! Files deleted: 0
Finished (Success) 'Clean' in 00:00:01.0942973
Starting target 'InstallClient'
.> "/usr/local/bin/npm" install (In: false, Out: false, Err: false)

up to date, audited 431 packages in 3s

56 packages are looking for funding
  run `npm fund` for details

3 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.
Finished (Success) 'InstallClient' in 00:00:03.7260124
Starting target 'Run'
/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared> "dotnet" build (In: false, Out: false, Err: false)
MSBuild version 17.3.1+2badb37d1 for .NET
  Determining projects to restore...
  Paket version 7.0.2+a704d681f4688c094e60d2b0795913896f145865
  Restoring /Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj
  Starting restore process.
  Total time taken: 0 milliseconds
  All projects are up-to-date for restore.
  Paket version 7.0.2+a704d681f4688c094e60d2b0795913896f145865
  Restoring /Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj
  Starting restore process.
  Total time taken: 0 milliseconds
  Shared -> /Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/bin/Debug/net6.0/Shared.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:04.98
server: /Users/espen/code/dotnet-new-safe-4.1.1/src/Server> dotnet watch run
client: /Users/espen/code/dotnet-new-safe-4.1.1/src/Client> dotnet fable watch -o output -s --run npm run start
/Users/espen/code/dotnet-new-safe-4.1.1/src/Server> "dotnet" watch run (In: false, Out: true, Err: true)
/Users/espen/code/dotnet-new-safe-4.1.1/src/Client> "dotnet" fable watch -o output -s --run npm run start (In: false, Out: true, Err: true)
client: Fable: F# to JS compiler 3.7.5
client: Stop Russian aggression against Ukraine!
client: Parsing Client.fsproj...
client: .> dotnet restore Client.fsproj
client:   Determining projects to restore...
client:   Paket version 7.0.2+a704d681f4688c094e60d2b0795913896f145865
client:   Restoring /Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj
client:   Starting restore process.
client:   Total time taken: 0 milliseconds
server: dotnet watch 🚀 Started
client:   All projects are up-to-date for restore.
server: /Users/espen/code/dotnet-new-safe-4.1.1/.paket/Paket.Restore.targets(219,5): error MSB3073: The command "dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"" exited with code 134. [/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj]
server: 
server: The build failed. Fix the build errors and run again.
server: dotnet watch ❌ Exited with error code 1
server: dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
client: Some Nuget packages contain information about NPM dependencies that can be managed by Femto: https://github.com/Zaid-Ajaj/Femto
client: Project and references (120 source files) parsed in 6626ms
client: Loaded Feliz.HookAttribute from ../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
client: Loaded Feliz.ReactComponentAttribute from ../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
client: Loaded Feliz.ReactMemoComponentAttribute from ../../../../.nuget/packages/feliz.compilerplugins/1.8.0/lib/netstandard2.0/Feliz.CompilerPlugins.dll
client: Started Fable compilation...
client: Fable compilation finished in 9910ms
client: .> npm run start
client: Watching ..
client: > start
client: > webpack-dev-server --mode development
client: Bundling for run - development ...
client: <i> [webpack-dev-server] [HPM] Proxy created: /api/**  -> http://localhost:5000
client: <i> [webpack-dev-server] [HPM] Proxy created: /socket/**  -> http://localhost:5000
client: <i> [webpack-dev-server] Project is running at:
client: <i> [webpack-dev-server] Loopback: http://localhost:8080/
client: <i> [webpack-dev-server] On Your Network (IPv4): http://10.0.0.3:8080/
client: <i> [webpack-dev-server] On Your Network (IPv6): http://[fe80::1]:8080/
client: <i> [webpack-dev-server] Content not from webpack is served from '/Users/espen/code/dotnet-new-safe-4.1.1/src/Client/public' directory
client: <i> [webpack-dev-server] 404s will fallback to '/index.html'
client: asset vendors-node_modules_react-dom_index_js-node_modules_remotedev_lib_index_js-node_modules_webp-2931a1.js 3.29 MiB [emitted] (id hint: vendors)
client: asset app.js 3.01 MiB [emitted] (name: app)
client: asset runtime.js 43.3 KiB [emitted] (name: runtime)
client: asset index.html 704 bytes [emitted]
client: Entrypoint app 6.34 MiB = runtime.js 43.3 KiB vendors-node_modules_react-dom_index_js-node_modules_remotedev_lib_index_js-node_modules_webp-2931a1.js 3.29 MiB app.js 3.01 MiB
client: runtime modules 28.2 KiB 14 modules
client: modules by path ./src/Client/output/ 1.01 MiB
client:   modules by path ./src/Client/output/fable_modules/fable-library.3.7.5/ 596 KiB 45 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.SimpleJson.3.23.0/*.js 164 KiB 8 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Remoting.Client.7.19.0/*.js 30.5 KiB 5 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Elmish.3.1.0/*.js 15.3 KiB 4 modules
client:   modules by path ./src/Client/output/fable_modules/Thoth.Json.6.0.0/*.js 97.8 KiB 4 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Elmish.HMR.5.2.0/*.js 6.32 KiB 3 modules
client:   modules by path ./src/Client/output/*.js 18.8 KiB 2 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Elmish.React.3.0.1/*.js 5.29 KiB 2 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Elmish.Debugger.3.3.0/*.js 6.37 KiB 2 modules
client:   modules by path ./src/Client/output/fable_modules/Fable.Parsimmon.4.1.0/*.js 35.2 KiB 2 modules
client: modules by path ./node_modules/ 1.22 MiB 55 modules
client: webpack 5.65.0 compiled successfully in 1807 ms

Yes I added --project when I ran it from the command line. I have not changed Build.fs.

When going into src/Server and running dotnet watch run:

~/code/dotnet-new-safe-4.1.1/src/Server master
❯ dotnet watch run                                   
dotnet watch 🚀 Started
/Users/espen/code/dotnet-new-safe-4.1.1/.paket/Paket.Restore.targets(219,5): error MSB3073: The command "dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"" exited with code 134. [/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj]

The build failed. Fix the build errors and run again.
dotnet watch ❌ Exited with error code 1
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...

I hope this helps!

olivercoad commented 1 year ago

I'm not really sure, sorry. The output looks very fine up to that point and there aren't really any hints as to what it might be. I do remember running into some issues with ~6.0.400 so thought maybe there was a small chance it was to do with the sdk version but I've tried with the same version as you now (6.0.401) and it works fine.

Have you been able to reproduce the issue in any other projects using paket or any other ways? Does it work with older versions of the template like 3.1.1 and .net 5?

olivercoad commented 1 year ago

You could try upgrading/downgrading paket in config/dotnet-tools.json to see if that changes anything. That latest version is 7.1.5

EspenBrun commented 1 year ago

I tried upgrading/downgrading to 7.1.5, 6.2.1 (latest on 6.) and to 6.0.7 (from safe 3.1.1). Same error.

Safe template 3.1.1 runs no problem.

I have not had this problem anywhere else and have create new projects with .net 6.

Any other things I could try is much appreciated.

olivercoad commented 1 year ago

Okay, I've thought of a few more things to try. For all of the commands in this comment run them from src/Server as the working directory.

When you run dotnet watch run it gives the error. Does it also give the error if it's just dotnet run without watch? What if you did dotnet paket restore then dotnet restore and then dotnet run --no-restore (or dotnet watch run --no-restore)?

You could also try increasing the msbuild verbosity to see if it gives anything useful with something like --verbosity normal or --verbosity diag.

EspenBrun commented 1 year ago

It worked to just do dotnet run from the Server directory! So the failure is related somehow to watch.

~/code/dotnet-new-safe-4.1.1/src/Server master
❯ dotnet run
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[62]
      User profile is available. Using '/Users/espen/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
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

I tried dotnet paket restore, then dotnet restore and then dotnet watch run --no-restore, but I get the same error.

EspenBrun commented 1 year ago

Normal verbosity:

~/code/dotnet-new-safe-4.1.1/src/Server master 26s
❯ dotnet watch run --verbosity normal
dotnet watch 🚀 Started
Using launch settings from /Users/espen/code/dotnet-new-safe-4.1.1/src/Server/Properties/launchSettings.json...
Build started 11/6/2022 12:27:48 PM.
     1>Project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Server/Server.fsproj" on node 1 (Restore target(s)).
     1>_GetAllRestoreProjectPathItems:
         Determining projects to restore...
     1>Project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Server/Server.fsproj" (1) is building "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" (2:3) on node 1 (_GenerateRestoreGraphProjectEntry target(s)).
     2>PaketRestore:
         dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"

         Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

            at System.Reflection.RuntimeAssembly.GetType(RuntimeAssembly assembly, String name, Boolean throwOnError, Boolean ignoreCase, ObjectHandleOnStack type, ObjectHandleOnStack keepAlive)
            at System.Reflection.RuntimeAssembly.GetType(String name, Boolean throwOnError, Boolean ignoreCase)
            at System.StartupHookProvider.CallStartupHook(String assemblyPath)
            at System.StartupHookProvider.ProcessStartupHooks()
     2>/Users/espen/code/dotnet-new-safe-4.1.1/.paket/Paket.Restore.targets(219,5): error MSB3073: The command "dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"" exited with code 134. [/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj]
     2>Done Building Project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" (_GenerateRestoreGraphProjectEntry target(s)) -- FAILED.
     1>Done Building Project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Server/Server.fsproj" (Restore target(s)) -- FAILED.

Build FAILED.

       "/Users/espen/code/dotnet-new-safe-4.1.1/src/Server/Server.fsproj" (Restore target) (1) ->
       "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" (_GenerateRestoreGraphProjectEntry target) (2:3) ->
       (PaketRestore target) -> 
         /Users/espen/code/dotnet-new-safe-4.1.1/.paket/Paket.Restore.targets(219,5): error MSB3073: The command "dotnet paket restore --project "/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj" --output-path "obj" --target-framework "net6.0"" exited with code 134. [/Users/espen/code/dotnet-new-safe-4.1.1/src/Shared/Shared.fsproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:01.71

The build failed. Fix the build errors and run again.
dotnet watch ❌ Exited with error code 1
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
EspenBrun commented 1 year ago

So seems I am missing a runtime, I'll try to install that. System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

EspenBrun commented 1 year ago

Or it seems I can't get that one on mac, correct?

olivercoad commented 1 year ago

Aha, so it's related to dotnet watch. That's interesting. I'm gonna be pretty low on time for the next while but it would be interesting to look into the changes made to dotnet watch for .net 6.

If you can reproduce it on a simpler project you could potentially open an issue in Paket or dotnet sdk. It might also be worth asking someone else with a mac to try it in case the runtime is just messed up on your machine somehow.

On Sun., 6 Nov. 2022, 22:39 Espen Kirkesæther Brun, < @.***> wrote:

Or it seems I can't get that one on mac, correct?

— Reply to this email directly, view it on GitHub https://github.com/SAFE-Stack/SAFE-template/issues/537#issuecomment-1304780483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF5P62RTCXJVFUYGMNF5VN3WG6KIXANCNFSM6AAAAAARUBP2OE . You are receiving this because you commented.Message ID: @.***>

olivercoad commented 1 year ago

Does anyone know if the version of dotnet watch used is based on the host dotnet or if it's impacted by the global.json?

On Sun., 6 Nov. 2022, 23:09 Oliver Coad, @.***> wrote:

Aha, so it's related to dotnet watch. That's interesting. I'm gonna be pretty low on time for the next while but it would be interesting to look into the changes made to dotnet watch for .net 6.

If you can reproduce it on a simpler project you could potentially open an issue in Paket or dotnet sdk. It might also be worth asking someone else with a mac to try it in case the runtime is just messed up on your machine somehow.

On Sun., 6 Nov. 2022, 22:39 Espen Kirkesæther Brun, < @.***> wrote:

Or it seems I can't get that one on mac, correct?

— Reply to this email directly, view it on GitHub https://github.com/SAFE-Stack/SAFE-template/issues/537#issuecomment-1304780483, or unsubscribe https://github.com/notifications/unsubscribe-auth/AF5P62RTCXJVFUYGMNF5VN3WG6KIXANCNFSM6AAAAAARUBP2OE . You are receiving this because you commented.Message ID: @.***>

EspenBrun commented 1 year ago

I have not been able to reproduce it on a simpler project. I have tried dotnet new with new console, webapi, feliz and saturn, all running on net6.0. No error here.

I'll get someone else with a mac to try with a new safe template.

olivercoad commented 1 year ago

Because the error happens when doing paket restore on a <ProjectReference> with dotnet watch run, I would expect any repro to need to be using paket and multiple projects.

EspenBrun commented 1 year ago

I have tried creating a new console app and a class lib, and use paket as package manager. Installed a package in the class lib, created a module that used that package in lib, and called in from the console app. Works fine with dotnet watch

afry23 commented 1 year ago

Hi, I had the same problem on mac os. "dotnet watch run" in src/Server didn't work. When I deleted all .NET SDKs < 3.0.100 it worked for me.

EspenBrun commented 1 year ago

That worked for me, thanks a lot!