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

标签 .net-core

我的 launchSettings.json 文件:

{
  "profiles": {
    "WinRedisSmcProxy": {
      "commandName": "Executable",
      "executablePath": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
      "commandLineArgs": "dotnet C:\\Users\\KudeBJ\\Desktop\\redis-smc-proxy-prototype\\WinRedisSmcProxy\\WinRedisSmcProxy\\bin\\Debug\\netcoreapp3.0\\WinRedisSmcProxy.dll"
    }
  }
}
上面的代码有问题。当项目被放置在另一个位置而不是桌面时,项目将不会运行。这是因为我在配置中使用了绝对路径。有什么办法可以将其更改为相对的吗?

最佳答案

您可以使用:

var path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
它将获得 C:\\Users\\KudeBJ\\AppData\\Roaming文件夹。此外,您可以获得另一个文件夹。看 Environment.SpecialFolder枚举。

关于.net-core - 如何在.NET Core 项目的launchSettings.json 中使用相对路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57104918/

相关文章:

c# - .NET Core 平台中Log4Net Layout.XmlLayout 不创建日志

c# - 如何更改 Visual Studio Code 中的默认构建输出目录

.net-core - .NET Core 2.1 ConfigurationBuilder.Build() - StackOverflowException

google-app-engine - Google App Engine .Net Core 2.0 应用无法访问 Google Cloud SQL 数据库

docker - Console.ForegroundColor/BackgroundColor 未反射(reflect)在 Docker 日志中

c# - 使用多个身份用户时没有类型 Identity.UserManager 的服务

c# - 如何确定 .NET CORE DLL 是否在 Web 服务器/主机或控制台应用程序中运行

Azure KeyVault nuget 包问题

c# - 为什么我的 BackgroundService 立即停止?

c# - 如何在 C# 中向线程添加函数?