[RESOLVED]Reference a project in your solution programmatically

Hi

I have projects that can be added to my framework MVC solution after the fact. What I want to do is after they were added, to be able to in the front end programmatically add there reference to my main project’s references.

There is the following link:

http://www.codeproject.com/Articles/11658/Programmatically-add-references-to-Visual-Studio-N

E.g. Solution MyModel, Project – Main Project, SubProject1, SubProject 2.

How do I add SubProject2 as reference to Main Project.

Like, when you right click in Main Project References, Add References and in Projects you get the project tab to choose your project.

Thanks

Hi,

Add reference almost the same with solution. There is a choice at the same time with "solution", choose "browse" and at the click "Browse" at bottom wizard, and point to "objdebug<SubProject2_name>.dll" or "objrelease<SubProject2_name>.dll".

Have fun

Hi

Sorry, not following? I need to do this in code behind without the user being aware. The user will create a new object called a project. Then this will create my project in the background, adding it to the solution and then it needs to add the reference
to the new project in my main project.

Hope this makes sense.

Thanks

Hi,

sunettew1

Like, when you right click in Main Project References, Add References and in Projects you get the project tab to choose your project.

Add References, and in Browse Tab below of project tab, there is also
Browse at the bottom of the wizard and click it to browse to the folder where SubProject2.dll located.

I thing that is what you need. Doe’s not it?

Have fun

Hi

To add it in code behind. The user shouldn’t browse  to where the dll is. I want to add it automatically when the user greate a new "object" of type project from the gui.

Thanks

Hi sunettew1,

For this requirement, you could use References.AddProject method.

More information, please refer to:

# References.AddProject Method

http://msdn.microsoft.com/en-us/library/vslangproj.references.addproject.aspx

On the other hand, there are some link about load assembly that may benefit you:

# Reference Interface

http://msdn.microsoft.com/en-us/library/vslangproj.reference(v=vs.120).aspx

# EnvDTE – Adding a reference to a project

http://blogs.msdn.com/b/murat/archive/2008/07/30/envdte-adding-a-refernce-to-a-project.aspx

# Using reflection to load unreferenced assemblies at runtime

http://www.dreamincode.net/forums/topic/78974-using-reflection-to-load-unreferenced-assemblies-at-runtime/

Best Regards

Starain

Leave a Reply