VB.net:Application.StartupPath 的问题

问题描述 投票:0回答:3

我想访问运行我的已发布应用程序的文件夹的路径。

我能找到的所有内容都说使用 Application.StartupPath(),但这不起作用。

我编写了一个简单的程序来显示这些内容,发布到单个独立文件,然后从目录运行它

C:\Users\jerem\Downloads\split

这就是我得到的:

Application.StartupPath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\"
Application.ExecutablePath = "C:\Users\jerem\AppData\Local\Temp\.net\getlaunchdir\jvi1ji54.zau\getlaunchdir.dll"

运行 .exe 文件似乎会创建一个临时文件夹,其中包含随后运行的文件负载。 很好,但它返回 StartupPath 的“错误”结果 - 即不是我想要的。

我该如何解决这个问题?

谢谢

** 根据 Caius Jard 的要求添加的发布设置图像。 发布设置图片

我不确定你如何获得将 application.startuppath 显示为 C: emp\ 的图像 - 这看起来像调试模式镜头,我的问题仅在运行已发布的程序时发生。

vb.net
3个回答
0
投票

我怀疑您是用 ClickOnce 发布的?如果您使用文件夹发布它,它应该按照您的预期运行

enter image description here

enter image description here

运行时:

enter image description here


0
投票

可能就是您正在寻找的:

Private uriBuilder As New UriBuilder(Reflection.Assembly.GetExecutingAssembly().CodeBase)

    Public FullAssemblyPath As String = Uri.UnescapeDataString(uriBuilder.Path)
    Public ExeDirectory As String = IO.Path.GetDirectoryName(FullAssemblyPath)

0
投票

检查您的导入之一是否覆盖应用程序

Imports System.Net.Mime.MediaTypeNames

这重新定义了 Application,因此无法识别 Application.StartupPath 或 Application.ExecutablePath。

© www.soinside.com 2019 - 2024. All rights reserved.