Skip to content

dotnet watch on macOS throws error looking for exe #41776

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

Closed
1 task done
mrlife opened this issue May 20, 2022 · 8 comments
Closed
1 task done

dotnet watch on macOS throws error looking for exe #41776

mrlife opened this issue May 20, 2022 · 8 comments
Assignees
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Milestone

Comments

@mrlife
Copy link
Contributor

mrlife commented May 20, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

I ran dotnet watch --verbose on SDK version 6.0.203, then updated to 6.0.300 and ran the command again. I got the same error each time. I am on macOS and the error seems to indicate it is trying to use a Windows executable.

ref: #39073 (comment)

Expected Behavior

Hot reload should run without error after executing command dotnet watch

Steps To Reproduce

  1. Create a new Blazor Server app on macOS
  2. Run dotnet watch in the project directory and notice it works
  3. Add this line to the .csproj since the publish server is Windows: <DefaultAppHostRuntimeIdentifier>win-x64</DefaultAppHostRuntimeIdentifier>
  4. Run dotnet watch --verbose in the project directory and notice it throws the error

Exceptions (if any)

watch : Caught top-level exception from hot reload: System.ComponentModel.Win32Exception (8): An error occurred trying to start process '/Users/UserName/Projects/MyProject/bin/Debug/net6.0/MyProject.exe' with working directory '/Users/UserName/MyProject'. Exec format error
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at Microsoft.DotNet.Watcher.Internal.ProcessRunner.RunAsync(ProcessSpec processSpec, CancellationToken cancellationToken)
at Microsoft.DotNet.Watcher.HotReloadDotNetWatcher.WatchAsync(DotNetWatchContext context, CancellationToken cancellationToken)

.NET Version

6.0.300

Anything else?

.NET SDK (reflecting any global.json):
Version: 6.0.300
Commit: 8473146e7d

Runtime Environment:
OS Name: Mac OS X
OS Version: 12.4
OS Platform: Darwin
RID: osx.12-arm64
Base Path: /usr/local/share/dotnet/sdk/6.0.300/

Host (useful for support):
Version: 6.0.5
Commit: 70ae3df4a6

.NET SDKs installed:
6.0.101 [/usr/local/share/dotnet/sdk]
6.0.200 [/usr/local/share/dotnet/sdk]
6.0.201 [/usr/local/share/dotnet/sdk]
6.0.202 [/usr/local/share/dotnet/sdk]
6.0.203 [/usr/local/share/dotnet/sdk]
6.0.300 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.4 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

@TanayParikh TanayParikh added the area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI label May 20, 2022
@mkArtakMSFT mkArtakMSFT added the feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external) label May 23, 2022
@mkArtakMSFT mkArtakMSFT added this to the Discussions milestone May 23, 2022
@DamianEdwards
Copy link
Member

Does dotnet run work or does it fail the same way dotnet watch does?

@mrlife
Copy link
Contributor Author

mrlife commented May 23, 2022

Does dotnet run work or does it fail the same way dotnet watch does?

Same

@DamianEdwards
Copy link
Member

Right, I think this behavior is expected then. The property you're setting in the project impacts the project's output when built. If you wish for a setting to only apply when publishing for a specific RID, you can either add a Condition attribute to the property in the project file so that it only applies when building for the desired RID, or just pass the property value when performing the publish, e.g. dotnet publish -c Release /p:DefaultAppHostRuntimeIdentifier=win-x64

@mrlife
Copy link
Contributor Author

mrlife commented May 23, 2022

@DamianEdwards That's interesting, thanks for pointing that out. Note that the issue isn't present when building with Visual Studio for Mac (ARM). I added the condition attribute, though since it is on the property that's setting the RID, dotnet watch works but the exe is no longer created when publishing to the server. I'm guessing I misunderstood.

<DefaultAppHostRuntimeIdentifier Condition="'$(RuntimeIdentifier)'=='win-x64'">win-x64</DefaultAppHostRuntimeIdentifier>

@DamianEdwards
Copy link
Member

You'll need to ensure you specify the RID when publishing, e.g. dotnet publish -c Release -r win-x64

@mrlife
Copy link
Contributor Author

mrlife commented May 24, 2022

@DamianEdwards Thank you. I added the -r win-x64 to my publish command. It works well, so I'll close this.

At the same time, I think adding -r support to dotnet watch would be a simpler solution for the user. Created a new issue here: dotnet/sdk#25612

@mrlife mrlife closed this as completed May 24, 2022
@DamianEdwards
Copy link
Member

I'm still slightly confused. Why can't you simply supply -r win-x64 to your publish command and not have anything specified in your project file at all? I understood your scenario to be one of developing/building on Mac, but publish for Windows.

@mrlife
Copy link
Contributor Author

mrlife commented May 25, 2022

You'll need to ensure you specify the RID when publishing, e.g. dotnet publish -c Release -r win-x64

@DamianEdwards This sounded additive to my comment about DefaultAppHostRuntimeIdentifier. I can see now that I was also slightly confused and the latter is unnecessary. Thanks for jumping back in even though the issue was closed.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-commandlinetools Includes: Command line tools, dotnet-dev-certs, dotnet-user-jwts, and OpenAPI feature-dotnetwatch This issue is related to the dotnet-watch command-line tool (now external)
Projects
None yet
Development

No branches or pull requests

5 participants