C# Getting Parent Assembly Name of Calling Assembly

前端 未结 9 1352
轮回少年
轮回少年 2021-01-01 09:02

I\'ve got a C# unit test application that I\'m working on. There are three assemblies involved - the assembly of the C# app itself, a second assembly that the app uses, and

9条回答
  •  梦毁少年i
    2021-01-01 09:54

    Assembly.GetEntryAssembly() is null if you run tests from nunit-console too.

    If you just want the name of the executing app then use:

     System.Diagnostics.Process.GetCurrentProcess().ProcessName 
    

    or

     Environment.GetCommandLineArgs()[0];
    

    For nunit-console you would get "nunit-console" and "C:\Program Files\NUnit 2.5.10\bin\net-2.0\nunit-console.exe" respectively.

提交回复
热议问题