相关疑难解决方法(0)

如何在C#中获取当前可执行文件的名称?

我想获取当前正在运行的程序的名称,即程序的可执行文件名称.在C/C++中,你可以从中获得它args[0].

c# command-line

338
推荐指数
13
解决办法
26万
查看次数

Web应用程序的GetEntryAssembly

Assembly.GetEntryAssembly()不适用于Web应用程序.

但是......我真的需要这样的东西.我使用了一些在Web和非Web应用程序中使用的深层嵌套代码.

我目前的解决方案是浏览StackTrace以找到第一个被调用的程序集.

/// <summary>
/// Version of 'GetEntryAssembly' that works with web applications
/// </summary>
/// <returns>The entry assembly, or the first called assembly in a web application</returns>
public static Assembly GetEntyAssembly()
{
    // get the entry assembly
    var result = Assembly.GetEntryAssembly();

    // if none (ex: web application)
    if (result == null)
    {
        // current method
        MethodBase methodCurrent = null;
        // number of frames to skip
        int framestoSkip = 1;


        // loop until we cannot got further in …
Run Code Online (Sandbox Code Playgroud)

c# reflection code-generation assemblies stack-frame

45
推荐指数
2
解决办法
2万
查看次数

使用Assembly vs AppDomain查找我的主要可执行文件的路径

我是.NET用户,我的目标就像找到主执行程序集(EXE文件)目录的绝对路径一样简单.

我有几个候选人:

  • Assembly.GetExecutingAssembly().CodeBase
  • Assembly.GetExecutingAssembly().Location
  • AppDomain.CurrentDomain.BaseDirectory

如果要通过.NET文档判断 - 我倾向于CodeBase.任何人都可以用比.NET文档更具体的术语来解释这三个问题吗?一个例子来证明这种差异?

.net directory exe path

24
推荐指数
4
解决办法
3万
查看次数

调用程序集获取应用程序名称VB.NET

我有一个MyProgram.EXE引用Utilities程序集的控制台应用程序().

在我的Utilities程序集中,我有以下代码:

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)
Run Code Online (Sandbox Code Playgroud)

当我打电话给它时MyProgram.EXE,我会收到" AppName is: Utilities.dll"

我想要的是" AppName is: MyProgram.EXE"

我究竟做错了什么?

.net vb.net

6
推荐指数
2
解决办法
3万
查看次数

提取当前的可执行文件名称

首先,我想说我并不是指完整路径,
GetModuleFileName或argv [0]产生的.有没有一个更聪明的解决方案,而不是在最后一次反斜杠之前解雇所有内容?

c++ windows

4
推荐指数
1
解决办法
5044
查看次数