【问题标题】:Unable to pass -p argument to .NET app when using dotnet run使用 dotnet run 时无法将 -p 参数传递给 .NET 应用程序
【发布时间】:2021-01-05 16:59:47
【问题描述】:

我正在尝试使用 dotnet run:dotnet run -p /Users/user/Pictures 将命令行参数 -p 传递给我的 .NET Core 应用程序。但是,当我这样做时,我会收到如下所示的错误消息。看起来dotnet run 正在尝试打开一个项目文件夹,而不是将此参数传递给我的应用程序。我可以将其他内容(例如 -q)传递给我的应用程序。

使用dotnet run时如何将-p传递给我的应用程序?

错误是这样的:

$ dotnet run -p /Users/user/Pictures

MSBUILD : error MSB1001: Unknown switch.
Switch: /Users/user/Pictures
For switch syntax, type "MSBuild -help"
The build failed. Fix the build errors and run again.

我正在尝试使用这样的开关编写一个 .NET 应用程序:

Usage: du [-s] [-p] [-b] "path"

Summarize disk usage of the set of FILES, recursively for directories.
You MUST specify one of the parameters, -s, -p, or -b
-s      Run in single threaded mode
-p      Run in parallel mode (uses all available processors)
-b      Run in both parallel and single threaded mode.Runs parallel followed by sequential mode

【问题讨论】:

  • 听起来像是错字。你到底想运行什么命令?
  • 更新了命令和它的作用。这不是错字。我正在尝试在 Jetbrains Rider Terminal 中运行它。
  • 不清楚你想在这里做什么。 -pdotnet run参数,也是du参数?要将/Users/user/Pictures 传递给dotnet run 还是传递给正在运行的应用程序?

标签: c# .net-core msbuild


【解决方案1】:

您需要使用-- 告诉dotnet run 您已完成传递它的参数,其余的应该传递给正在运行的应用程序。 -pdotnet run --project 的短开关,用于指定要构建和运行的项目文件(例如 .csproj 文件)。您的 -p 特定于您的应用。

dotnet run -- -p /Users/user/Pictures

【讨论】:

猜你喜欢
  • 2018-12-29
  • 2012-12-24
  • 1970-01-01
  • 2021-01-10
  • 1970-01-01
  • 1970-01-01
  • 2011-01-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多