I have been investigating this for several hours. I have found numerous links, including several here on SO which claim to show how to find the startup path, or the application directory. All of the solutions suggested return a location:
我一直在调查这几个小时。我找到了很多链接,包括SO上的几个链接声明如何查找启动路径或应用程序目录。建议的所有解决方案都返回一个位置:
C:\Users\<my user name>\AppData\Local\Apps\2.0\XO8PWL8B.5HH\1GZX7M0H.N1J\<temp location>\
C:\ Users \ <我的用户名> \ AppData \ Local \ Apps \ 2.0 \ XO8PWL8B.5HH \ 1GZX7M0H.N1J \
When my WPF xbap is run from a remote location. I need to determine the actual folder of the remote location.
从远程位置运行我的WPF xbap时。我需要确定远程位置的实际文件夹。
I am deploying this to an internal server ABCDEF, so in order to run this application I am entering:
我正在将其部署到内部服务器ABCDEF,所以为了运行这个应用程序,我输入:
\\ABCDEF\myApp.xbap
I want to programmatically determine the server and folder. My reason for this is that each time you publish a WPF with "automatically increment revision with each publish
" turned on. The folder where additional DLL's are located changes, additional programs that this program depends on.
我想以编程方式确定服务器和文件夹。我之所以这样做是因为每次发布WPF时都会打开“自动增加每次发布的修订版本”。附加DLL所在的文件夹发生更改,此程序依赖其他程序。
I want to be able to dynamically determine the correct folder to look at.
我希望能够动态确定要查看的正确文件夹。
I have tried:
我试过了:
'Dim path As String = Reflection.Assembly.GetEntryAssembly().Location
'Dim Path As String = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
'System.IO.Path.GetDirectoryName(System.Reflection. Assembly.GetExecutingAssembly.Location)
'application.StartupPath
All of which did not work.
所有这些都不起作用。
These links suggested many of the methods I have tried:
这些链接提出了我尝试过的许多方法:
2 个解决方案
#1
4
I think this will steer you in the right direction. Since it sounds like you're deploying via ClickOnce you should get the information you need here:
我认为这会引导你朝着正确的方向前进。由于听起来您正在通过ClickOnce进行部署,因此您应该获得所需的信息:
System.Deployment.Application.ApplicationDeployment.CurrentDeployment
this class can be found in the System.Deployment.dll
可以在System.Deployment.dll中找到此类
Unfortunately the CurrentDeployment
object doesn't actually tell you where the application lives so you have to do some more work :(
不幸的是,CurrentDeployment对象实际上并没有告诉你应用程序的位置,所以你必须做更多的工作:(
if you call this:
如果你这样称呼:
var datadir = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory
you'll get something like this(for the datadirectory)
你会得到这样的东西(对于datadirectory)
C:\Users\Administrator\AppData\Local\Apps\2.0\Data\BVPTZA5G.3AC\WC2WBZ92.D96\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341\Data\1.0.0.0
from there you need to get the folder name of the bold folder above because the application lives here(not the data directory):
从那里你需要获取上面的粗体文件夹的文件夹名称,因为应用程序住在这里(不是数据目录):
C:\Users\Administrator\AppData\Local\Apps\2.0\RCVHD71Y.7CQ\BC42YMHT.ZQ0\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341
So I would create a function that
所以我会创建一个函数
- Takes in the first filepath
- Determines the randomly generated foldername
- finds the folder of the application based on that folder name(which contains your executables)
接受第一个文件路径
确定随机生成的foldername
根据该文件夹名称(包含您的可执行文件)查找应用程序的文件夹
I think creating an extension method on type ApplicationDeployment would be fitting.
我认为在ApplicationDeployment类型上创建扩展方法是合适的。
Hope that helps
希望有所帮助
#2
0
This worked for me:
这对我有用:
string exePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName; string dir = Path.GetDirectoryName(exePath);
string exePath = System.Reflection.Assembly.GetExecutingAssembly()。GetModules()[0] .FullyQualifiedName; string dir = Path.GetDirectoryName(exePath);
#1
4
I think this will steer you in the right direction. Since it sounds like you're deploying via ClickOnce you should get the information you need here:
我认为这会引导你朝着正确的方向前进。由于听起来您正在通过ClickOnce进行部署,因此您应该获得所需的信息:
System.Deployment.Application.ApplicationDeployment.CurrentDeployment
this class can be found in the System.Deployment.dll
可以在System.Deployment.dll中找到此类
Unfortunately the CurrentDeployment
object doesn't actually tell you where the application lives so you have to do some more work :(
不幸的是,CurrentDeployment对象实际上并没有告诉你应用程序的位置,所以你必须做更多的工作:(
if you call this:
如果你这样称呼:
var datadir = System.Deployment.Application.ApplicationDeployment.CurrentDeployment.DataDirectory
you'll get something like this(for the datadirectory)
你会得到这样的东西(对于datadirectory)
C:\Users\Administrator\AppData\Local\Apps\2.0\Data\BVPTZA5G.3AC\WC2WBZ92.D96\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341\Data\1.0.0.0
from there you need to get the folder name of the bold folder above because the application lives here(not the data directory):
从那里你需要获取上面的粗体文件夹的文件夹名称,因为应用程序住在这里(不是数据目录):
C:\Users\Administrator\AppData\Local\Apps\2.0\RCVHD71Y.7CQ\BC42YMHT.ZQ0\ expe..tion_ba14dd6bedbd6876_0000.0009_7919ca38a4e51341
So I would create a function that
所以我会创建一个函数
- Takes in the first filepath
- Determines the randomly generated foldername
- finds the folder of the application based on that folder name(which contains your executables)
接受第一个文件路径
确定随机生成的foldername
根据该文件夹名称(包含您的可执行文件)查找应用程序的文件夹
I think creating an extension method on type ApplicationDeployment would be fitting.
我认为在ApplicationDeployment类型上创建扩展方法是合适的。
Hope that helps
希望有所帮助
#2
0
This worked for me:
这对我有用:
string exePath = System.Reflection.Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName; string dir = Path.GetDirectoryName(exePath);
string exePath = System.Reflection.Assembly.GetExecutingAssembly()。GetModules()[0] .FullyQualifiedName; string dir = Path.GetDirectoryName(exePath);