Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net core 如何在.NET核心项目的launchSettings.json中使用相对路径?_.net Core - Fatal编程技术网

.net core 如何在.NET核心项目的launchSettings.json中使用相对路径?

.net core 如何在.NET核心项目的launchSettings.json中使用相对路径?,.net-core,.net Core,My launchSettings.json文件: { “概况”:{ “WinRedismProxy”:{ “命令名”:“可执行文件”, “executablePath”:“C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe”, “commandLineArgs:“dotnet C:\\Users\\KudeBJ\\Desktop\\redis smc proxy prototype\\WinRedismProxy\\Wi

My launchSettings.json文件:

{
“概况”:{
“WinRedismProxy”:{
“命令名”:“可执行文件”,
“executablePath”:“C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe”,
“commandLineArgs:“dotnet C:\\Users\\KudeBJ\\Desktop\\redis smc proxy prototype\\WinRedismProxy\\WinRedismProxy\\bin\\Debug\\netcoreapp3.0\\WinRedismProxy.dll”
}
}
}
上面的代码中有一个问题。将项目放置在其他位置而不是桌面时,项目将不会运行。这是因为我在配置中使用了绝对路径。有没有办法将其更改为相对的?

您可以使用:

var path=Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);

它将获得
C:\\Users\\KudeBJ\\AppData\\Roaming
文件夹。此外,您还可以获得其他文件夹。查看
Environment.SpecialFolder
enum.

您想要实现什么?是否要求应用程序在PowerShell中打开?@StephenKennedy我想使用PowerShell来执行我的应用程序,而不是cmd。谢谢~我得到了路径,但有点困惑,如何将路径写入json文件?