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 run -- args' requires 'args' to exist #18437

Closed
rolfbjarne opened this issue Jun 22, 2021 · 8 comments
Closed

'dotnet run -- args' requires 'args' to exist #18437

rolfbjarne opened this issue Jun 22, 2021 · 8 comments
Milestone

Comments

@rolfbjarne
Copy link
Member

Description

Repro:

  • Install .NET 6 Preview 6 on a Mac.
  • Install the Mac Catalyst workload: sudo dotnet workload install microsoft-maccatalyst-sdk-full
  • Clone https:/dotnet/maui-samples (hash: bb264d046139f6635ed066157c44b99010b8d1dd)
  • Build & run HelloMacCatalyst:
$ cd HelloMacCatalyst
$ dotnet build
$ dotnet run --no-build -- helloworld
The file /Users/rolf/work/net6-mobile-samples/HelloMacCatalyst/helloworld does not exist.

Note that the error does not come from the Mac Catalyst test app, which is never executed. In fact you can delete everything, and try again without building, and you get the same error (now it'll also complain that the Mac Catalyst app doesn't exist, which makes sense):

git clean -xfd
$ dotnet run --no-build -- helloworld
The files /Users/rolf/work/net6-mobile-samples/HelloMacCatalyst/bin\Debug/net6.0-maccatalyst/maccatalyst-x64/HelloMacCatalyst.app and /Users/rolf/work/net6-mobile-samples/HelloMacCatalyst/helloworld do not exist.
@KathleenDollard KathleenDollard transferred this issue from dotnet/runtime Jun 22, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Jun 22, 2021
@KathleenDollard
Copy link

What is the name of the application that is built?
If you just type dotnet run or dotnet run -- helloworld does it work?
Is helloworld an argument to the application you're trying to run?

@rolfbjarne
Copy link
Member Author

What is the name of the application that is built?

HelloMacCatalyst

This is the source code: https:/dotnet/maui-samples/tree/main/HelloMacCatalyst

If you just type dotnet run or dotnet run -- helloworld does it work?

dotnet run works

dotnet run -- helloworld does not (same error)

Is helloworld an argument to the application you're trying to run?

Yes.

Note that we set RunCommand and RunArguments: https:/xamarin/xamarin-macios/blob/2b7dc07d20fc06344d7f164af8934f5e755572c2/dotnet/Microsoft.MacCatalyst.Sdk/targets/Microsoft.MacCatalyst.Sdk.targets#L5-L8

although I don't see how that would make the actual user arguments verified as valid paths (which they obviously don't have to be)

@sfoslund
Copy link
Member

I'm looking into this issue. So far, I've confirmed that this does not repro with a simple console app so this appears to be something specific to the maui sample app

dotnet run --no-build -- helloworld
Hello World! helloworld

Source:

using System;
namespace tmp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World! " + args[0]);
}
}
}

@sfoslund
Copy link
Member

@rolfbjarne I've reproed and investigated more and I believe that this is a result of setting the RunCommand and RunArguments in the file you linked. I've experimented with the simple console app I used above by adding:
<PropertyGroup> <RunArguments>$(OutputPath)/$(AssemblyName).app</RunArguments> </PropertyGroup>
to the project file and it ends up mangling the arguments in a similar way:

dotnet run --no-build hello
Hello World! /tmp.app

I'm not sure exactly how the RunCommand and RunArguments properties are supposed to interact with command line arguments to the run command, but maybe @rainersigwald can comment.

@sfoslund sfoslund removed the untriaged Request triage from a team member label Jun 23, 2021
@sfoslund sfoslund added this to the Discussion milestone Jun 23, 2021
@rainersigwald
Copy link
Member

RunCommand and RunArguments are SDK/CLI concepts, not part of core MSBuild. It looks like they're here, which appends more or less as I expected:

string runProgram = project.GetPropertyValue("RunCommand");
if (string.IsNullOrEmpty(runProgram))
{
ThrowUnableToRunError(project);
}
string runArguments = project.GetPropertyValue("RunArguments");
string runWorkingDirectory = project.GetPropertyValue("RunWorkingDirectory");
if (Args.Any())
{
runArguments += " " + ArgumentEscaper.EscapeAndConcatenateArgArrayForProcessStart(Args);
}

@rainersigwald
Copy link
Member

I'm pretty sure the error is coming from macOS's open:

open a b c
The files /Users/raines/temp/a, /Users/raines/temp/b, and /Users/raines/temp/c do not exist.

@rolfbjarne
Copy link
Member Author

🤦

Sorry I didn't figure this out myself.

rolfbjarne added a commit to rolfbjarne/xamarin-macios that referenced this issue Jun 25, 2021
When we're using 'open' to launch apps, we need to use '--args ...' to pass any additional argument to the app, because otherwise 'open' will try to open those arguments as if they were files:

```
$ open "/Applications/Sublime Text.app" helloworld
The file /Users/rolf/test/helloworld does not exist.
```

(and doesn't launch Sublime Text).

while this works:

```
$ open "/Applications/Sublime Text.app" --args helloworld
```

in that it opens Sublime Text.

It's also possible to not append any other arguments, so this:

```
$ open "/Applications/Sublime Text.app" --args
```

while it looks weird, it works just fine.

Ref: dotnet/sdk#18437
rolfbjarne added a commit to xamarin/xamarin-macios that referenced this issue Jun 25, 2021
…12019)

When we're using 'open' to launch apps, we need to use '--args ...' to pass any additional argument to the app, because otherwise 'open' will try to open those arguments as if they were files:

```
$ open "/Applications/Sublime Text.app" helloworld
The file /Users/rolf/test/helloworld does not exist.
```

(and doesn't launch Sublime Text).

while this works:

```
$ open "/Applications/Sublime Text.app" --args helloworld
```

in that it opens Sublime Text.

It's also possible to not append any other arguments, so this:

```
$ open "/Applications/Sublime Text.app" --args
```

while it looks weird, it works just fine.

Ref: dotnet/sdk#18437
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants