呼唤大会获得应用程序名称VB.NET [英] Calling Assembly to get Application Name VB.NET

查看:130
本文介绍了呼唤大会获得应用程序名称VB.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序(<$ C C $> MyProgram.EXE )引用一个实用程序组件。

I have a console application (MyProgram.EXE) that references a Utilities assembly.

在我的实用工具组件,我有code,做:

In my Utilities assembly, I have code that does:

Dim asm As Assembly = Assembly.GetExecutingAssembly()
Dim location As String = asm.Location
Dim appName As String = System.IO.Path.GetDirectoryName(location)
Conole.WriteLine("AppName is: {0}", appName)

当我从 MyProgram.EXE 调用它,我收到 appname是:Utilities.dll

我要的是 appname是:MyProgram.EXE

我是什么做错了吗?

推荐答案

使用 GetEntryAssembly()而不是得到一个包含入口点的集会。

Use GetEntryAssembly() instead to get the assembly containing the entry point.

更好的方法是使用 System.Environment.CommandLine 属性,而不是去做。

The better way to do it is using System.Environment.CommandLine property instead.

具体做法是:

Dim location As String = System.Environment.GetCommandLineArgs()(0)
Dim appName As String = System.IO.Path.GetFileName(location)
Conole.WriteLine("AppName is: {0}", appName)

顺便说一句,你想用 GetFileName ,而不是 GetDirectoryName

这篇关于呼唤大会获得应用程序名称VB.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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