c# - dotnet run --project <PATH> 不将项目路径作为工作目录

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

当使用 .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 时,如何让我的应用程序将工作目录识别为项目文件夹的根目录?? (要清楚,除非我可以让它自动结束,否则我不想使用 watch )

最佳答案

从项目的文件夹运行 dontet。
因为 appsettings.json 和 ssh 证书是相对于 executiion 文件夹的。
不管 System.Reflection.Assembly.GetExecutingAssembly().Location

关于c# - dotnet run --project <PATH> 不将项目路径作为工作目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59829037/

相关文章:

C# winform 删除然后将更多项目添加到面板控件

c# - MVC5 商店和经理类

c# - 使用 LINQ to SQL 从数据库进行最佳 Count() 操作

.net 架构 : Creating a IRepository<T> generically

.net-core - 修复错误 NU1605 : Detected package downgrade - log4net 的正确方法是什么

.net-core - 关于 F# 项目中服务器 GC 的警告

parallel-processing - .Net Core Hangfire - 增加 worker 数量

c# - 如何检查偏移量处的某些字节并相应地设置复选框

c# - 需要一种数据类型来在 C# 中保存 100 万以上的数字

c# - 如何从客户端证书中读取通用名称?