c#获取包含当前执行的代码的程序集
项目结构如下

Program代码
using System; using TestAssembly.Test; namespace TestAssembly { class Program { static void Main(string[] args) { new Test1().test(); Console.ReadKey(); } } }
Test1部分代码
using System; using System.Reflection; namespace TestAssembly.Test { public class Test1 { public void test() { // Get the assembly from a known type in that assembly. Type t = typeof(Program); Assembly assemFromType = t.Assembly; Console.WriteLine("包含Program程序的程序集:"); Console.WriteLine(" {0}\n", assemFromType.FullName); // Get the currently executing assembly. Assembly currentAssem = Assembly.GetExecutingAssembly(); Console.WriteLine("当前执行程序集:"); Console.WriteLine(" {0}\n", currentAssem.FullName); Console.WriteLine("两个程序集是否相等: {0}", assemFromType.Equals(currentAssem)); var types = assemFromType.GetTypes(); foreach (var item in types) { Console.WriteLine($"程序集包含: name={item.Name},fullname={item.FullName}"); } } } }
执行结果


浙公网安备 33010602011771号