【问题标题】:dotnet run --project <PATH> not taking project path as working directorydotnet run --project <PATH> 不将项目路径作为工作目录
【发布时间】:2020-01-20 18:27:58
【问题描述】:

当使用 .NET 命令运行存储在网络驱动器上的控制台应用程序时,它会将工作目录视为调用它的位置,而不是项目路径。..

dotnet run --project "\\network.drive\path\example\project"

我得到如下输出:

WORKING DIRECTORY: C:\Windows\system32
Current Environment: DEV
Current Root URL: <API_URL>
Current Excel File:

Unhandled Exception: System.ArgumentNullException: Value cannot be null.
Parameter name: fileName
   at System.IO.FileInfo..ctor(String originalPath, String fullPath, String fileName, Boolean isNormalized)
   at System.IO.FileInfo..ctor(String fileName)
   at MyProject.Reader.ReadAgentData(Int32 sheetIndex) in \\network.drive\path\example\project\Reader.cs:line 68
   at MyProject.Program.Main(String[] args) in \\network.drive\path\example\project\Program.cs:line 119

错误是 Excel 文件变量为空字符串。由于工作目录不是项目的路径,而是C:\Windows\system32,因此找不到从中提取信息的appsettings.json文件。

奇怪的是,使用命令dotnet watch --project "\\network.drive\path\example\project" run 会导致进程正确运行,它具有正确的工作目录并毫无问题地读取 appsettings.json 文件,但显然必须等待文件更改(目的观看)..

当使用dotnet run --project时,如何让我的应用程序将工作目录识别为项目文件夹的根目录?? (需要明确的是,我不想使用手表,除非我可以让它自动结束)

【问题讨论】:

  • 看看这个 GitHub issue。似乎不支持 UNC 路径
  • 我遇到了与非 UNC 路径相同的问题

标签: c# .net .net-core console-application


【解决方案1】:

从项目文件夹运行 dontet。

因为 appsettings.json 和 ssh 证书是相对于执行文件夹的。

不考虑 System.Reflection.Assembly.GetExecutingAssembly().Location

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-28
    • 2023-01-03
    • 1970-01-01
    • 2017-04-23
    相关资源
    最近更新 更多