如何获得解决方案中的所有装配

编程入门 行业动态 更新时间:2024-10-23 16:25:23
本文介绍了如何获得解决方案中的所有装配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

亲爱的, 我试图让所有课程都在一个有两个项目的解决方案中,但他们之间没有参考,但我只是在当前的初创公司上课项目。 这是我的情况: *我在一个解决方案中有2个项目(ConsoleApplication2) - ConsoleApplication11)。 * ConsoleApplication2是启动项目。 *我尝试使用

AppDomain.CurrentDomain.GetAssemblies()

但我只获得了ConsoleApplication2 [启动项目] 类。 那么,如何在不添加引用的情况下获取ConsoleApplication11类它在ConsoleApplication2中。 等待你的快速行动, 问候, Amr 我尝试了什么: 我试过用 AppDomain.CurrentDomain.GetAssemblies()

但我只得到ConsoleApplication2 [启动项目] c lasses。

解决方案

你必须加载你试图使用反射的程序集:

string path = @ .. \..\ ConsoleApplication11\bin\Debug\ConsoleApplication11.exe; // 将正确的路径放到您要在此处加载的程序集 程序集consoleApp11 = Assembly.LoadFile(path);

汇编类 [ ^ ] Assembly.LoadFile方法(字符串) [ ^ ]

Dears, I am trying to get all classes in a solution that has two projects with no reference between them but i am only getting classes to the current startup project. Here is my case: * I have a 2 projects in one solution (ConsoleApplication2 - ConsoleApplication11). * ConsoleApplication2 is the startup project. * I tried using

AppDomain.CurrentDomain.GetAssemblies()

but i am only getting ConsoleApplication2 [startup project] classes. So, How can i get ConsoleApplication11 classes without adding reference to it in ConsoleApplication2. Waiting your fast actions, Regards, Amr What I have tried: I tried using

AppDomain.CurrentDomain.GetAssemblies()

but i am only getting ConsoleApplication2 [startup project] classes.

解决方案

You have to load the assembly you are trying to use reflection on:

string path = @"..\..\ConsoleApplication11\bin\Debug\ConsoleApplication11.exe"; // Put the right path to the assembly you are trying to load here Assembly consoleApp11 = Assembly.LoadFile(path);

Assembly Class[^] Assembly.LoadFile Method (String)[^]

更多推荐

如何获得解决方案中的所有装配

本文发布于:2023-11-29 21:56:09,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647735.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何获得   解决方案

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!