command-line-api: Does not allow arguments that start with the '@' character

static void Main(string param1, string param2)
{
    Console.WriteLine($"Parameters Param1={param1}, Param2={param2}");
}

Fails when invoking the app from command line with a parameter that starts with the “@” character

C:\MyApp.exe --param1 Hello --param2 @World

Response file not found 'World'
Required argument missing for option: --param2

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

If anyone using Beta 4 arrives here, you’ll find that ParseResponseFileAs(ResponseFileHandling.Disabled) mentioned in @elgonzo’s answer is gone. The Beta 4-compatible way to treat @-prefixed arguments as something other than response files is documented in issue #1750’s first comment under “Custom token replacement”.

You’ll need to create a CommandLineBuilder and then call the UseTokenReplacer extension method to get the raw @-prefixed token. Then you can return false to tell the parser to treat the token as a raw string:

.UseTokenReplacer((string tokenToReplace, out IReadOnlyList<string>? replacementTokens, out string? errorMessage) =>
{
	replacementTokens = null;
	errorMessage = null;
	return false;
})