c# - 使用 .netcore 3.0 和使用/p :PublishSingleFile=true flag? 时如何获取可执行文件的实际路径

标签 c# .net-core ubuntu-16.04 systemd netcoreapp3.0

我最近将一个应用程序升级到 dotnet core 3,并在构建过程中开始使用 PublishSingleFile 标志。通过这两个更改,找到可执行路径的方式发生了变化。现在,我没有获得可执行文件所在的路径,而是重定向到 /var/tmp/.net/ 中的随机目录。我以前在哪里得到 /opt/appdir/ .

Directory.SetCurrentDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));

编辑:所以看起来它吐出的随机目录实际上指向我的应用程序的解压缩版本,该版本不包含其他目录中的重要资源。

最佳答案

以下似乎将您所追求的路径提供给原始可执行文件:

System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName

关于c# - 使用 .netcore 3.0 和使用/p :PublishSingleFile=true flag? 时如何获取可执行文件的实际路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58083706/

相关文章:

.net-core - 如何从应用程序内确定 CoreCLR 运行时的版本

pip - 'pip install kaggle' 工作正常 - 但 'kg command not found'

c# - DataGrid ASP.net C# 中的中型 Blob

c# - 方法重载 : funnel call to derived class argument overload

c# - Azure Function - 将消息从事件中心触发器发送到 Azure SignalR 服务

c# - 如何使用automapper解析绝对url

docker - 从docker内部通过Oracle VM和cntlm代理进行Internet访问

regex - Perl/Sed 命令多次替换相同的模式

c# - 在没有启动的情况下在旧的 ASP.NET MVC 应用程序中创建 HttpClient

c# - C# 中的基本数据结构