Custom Wizard: Is it possible to add a dll reference to a project on creation from a custom wizard?
-
Hello, I was wondering if anyone could tell me if what I'm trying to accomplish is possible. I am using C# in VS 2008. I have two project templates and another template which links the two projects and calls their templates. The first project is a user control and the second is a test app that needs to reference the user control. I also have a custom wizard that is called from the template. After the projects are created the wizard compiles the user control and gets the path to its dll. I then need to add a reference to the user control from the dll path to my test app. It is not possible for me to add the reference before this as I don't know what the name of the dll will be until the user creates the new user control project giving it whatever name they want. Does anyone know how this could be done?
-
Hello, I was wondering if anyone could tell me if what I'm trying to accomplish is possible. I am using C# in VS 2008. I have two project templates and another template which links the two projects and calls their templates. The first project is a user control and the second is a test app that needs to reference the user control. I also have a custom wizard that is called from the template. After the projects are created the wizard compiles the user control and gets the path to its dll. I then need to add a reference to the user control from the dll path to my test app. It is not possible for me to add the reference before this as I don't know what the name of the dll will be until the user creates the new user control project giving it whatever name they want. Does anyone know how this could be done?
Maybe Reflection is what you want, google it.
-
Maybe Reflection is what you want, google it.
Thank you for the reply. I've been googling for about a week and tried many different things including reflection. I tried Assembly.LoadFrom(dllPath) in the wizard but that just adds the reference to the project that the code is in. I checked out reflection where you can get the type and instantiate an object of that type and call methods from it, but that object is already created. I don't want a new one. When I set an assembly variable in the wizard equal to the assembly of the object needing the reference, the LoadFrom function doesn't exist.
-
Thank you for the reply. I've been googling for about a week and tried many different things including reflection. I tried Assembly.LoadFrom(dllPath) in the wizard but that just adds the reference to the project that the code is in. I checked out reflection where you can get the type and instantiate an object of that type and call methods from it, but that object is already created. I don't want a new one. When I set an assembly variable in the wizard equal to the assembly of the object needing the reference, the LoadFrom function doesn't exist.
I found the answer on another forum. // Provide the information about project1 to project2
VSProject projectWithReferences = project2.Object as VSProject;
if (projectWithReferences != null)
{
// add a project reference... this takes care of dependencies and will enable the msbuild targets to know how to retrieve the outputs
Reference reference = projectWithReferences.References.AddProject(project1);
}