使用 .netcore 3.0 并使用/p:PublishSingleFile=true 标志时如何获取可执行文件的实际路径? [英] How to get actual path to executable when using .netcore 3.0 and using the /p:PublishSingleFile=true flag?

查看:9
本文介绍了使用 .netcore 3.0 并使用/p:PublishSingleFile=true 标志时如何获取可执行文件的实际路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I recently upgraded an application to dotnet core 3 and started using the PublishSingleFile flag during the build process. With these two changes the way the executable path is found has changed. Now instead of getting the path where the executable file is, I get redirected to a random directory in /var/tmp/.net/ where as I used to get /opt/appdir/.

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

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

So it seems like the random dir it is spitting out actually points to an unpacked version of my application which does not contain vital resources that are in the other directory.

推荐答案

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

The following seems to give the path you're after, to the original executable:

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

这篇关于使用 .netcore 3.0 并使用/p:PublishSingleFile=true 标志时如何获取可执行文件的实际路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆