使用.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?

查看:458
本文介绍了使用.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天全站免登陆