获取应用程序的启动地址 [英] get startup adr of application

查看:91
本文介绍了获取应用程序的启动地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

在vs2008(C#)中:

我有:
1.一个主要项目(Windows应用程序)
2. WCF库
3. WCF主机
4. WCF客户端(Windows应用程序)

为了使用创建的客户测试我的服务,我在主项目中调用我的客户表单,并在通过此表单获得服务的输入要求后,通过调用我的服务合同方法开始对服务做出响应.

在此服务中,我需要创建一个带有用于请求的接收参数的正确连接字符串,并且我需要我的应用程序启动路径(D:\ myProj.dll)才能访问exe文件,但是使用diffrent后,不幸的是各种返回此路径的代码,正是在调用服务时,我得到了我不需要的其他路径(myproj,bin.debug或c:\ programfiles \ visual studio9 \ common7 \ IDE),您可以帮我吗?

有关其他信息,我不得不说我是通过命令添加此路径的,以便对我的服务库和客户端的构建事件进行.


请帮助我访问此路径(我的项目的启动路径-> D:\ myProj.dll)

提前谢谢

hi ...

in vs2008 (C#):

I have :
1. a main project (windows app)
2. WCF Library
3. WCF Host
4. WCF Client (Windows app)

for testing my service with created client, I call my client form in my main proj and after getting the input requirement of service by this form , I start making response of service by calling my service contract method .

in this service I need to create a proper connection string with recieved parameter for request and I need my application startup path (D:\myProj.dll) to get access to an exe file , Unfortunately after using diffrent kinds of codes that return this path, exactly at point of calling my service, I get another paths I don''t need (myproj,bin.debug or c:\programfiles\visual studio9\common7\IDE) can U help me ?

for additional info I have to say that I added this path by a command to post-build event of my service library and client.


plz help me to get access to this path (startup path of my project -> D:\myProj.dll)

thank you in advance

推荐答案

因此,启动路径,而不是"adr",对吗?

如果某个程序集中有一些代码,则此调用可以为您提供执行中的程序集:
So, start-up path, not "adr", right?

If you have some code in some assembly, this call can give you the executing assembly:
string assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location;

自然地,您可以获取任何位置基本上,通过这种方式,您可以找到某个程序集的主要可执行模块(即文件)的位置. (即使VS仅支持创建单模块程序集,程序集本身也不必是单个文件;该文件也是模块,而不是程序集.)

现在,您可以提取目录路径:

Naturally, you can get the location of any other assembly, for example, the entry assembly, using System.Reflection.Assembly.GetEntryAssembly(); etc. Basically, this way you find a location of a main executable module of some assembly, which is a file. (An assembly itself does not have to be a single file, even though VS only support creation of single-module assemblies; the file is also a module, not an assembly.)

Now, you can extract the directory path:

string exePath = System.IO.Path.GetDirectoryName(assemblyLocation);



请参阅:
http://msdn.microsoft.com/en-us/library/system.reflection. assembly.aspx [^ ],
http://msdn.microsoft.com/en-us/library/system.io. path.aspx [^ ].

我不明白您怎么能获得对exe文件的访问权限",这与WCF有什么关系,但是看来这是您的问题. :-)

—SA



Please see:
http://msdn.microsoft.com/en-us/library/system.reflection.assembly.aspx[^],
http://msdn.microsoft.com/en-us/library/system.io.path.aspx[^].

I don''t understand how can you "get access to an exe file", and how is this related to WCF, but it looks like this is your problem. :-)

—SA


这篇关于获取应用程序的启动地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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