mik*_*bvs 8 .net c# console-application .net-core
当使用 .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
Run Code Online (Sandbox Code Playgroud)
错误是 Excel 文件变量是空字符串。由于工作目录不是项目的路径,而是C:\Windows\system32找不到从中提取信息的 appsettings.json 文件。
奇怪的是,使用该命令dotnet watch --project "\\network.drive\path\example\project" run会导致进程正确运行,它具有正确的工作目录并毫无问题地读取 appsettings.json 文件,但显然必须等待文件更改(监视的目的)。
使用时如何让我的应用程序将工作目录识别为项目文件夹的根目录dotnet run --project?(要明确的是,我不想使用手表,除非我可以让它自动结束)
pro*_*ica -2
从项目文件夹运行 dontet。
因为appsettings.json和ssh证书是相对于执行文件夹的。
无论 System.Reflection.Assembly.GetExecutingAssembly().Location 为何
| 归档时间: |
|
| 查看次数: |
7187 次 |
| 最近记录: |