Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Added project reference not reflected
 

Added project reference not reflected

Hi. I'm just newwith the automation features of .Net. I'm making a class library project that would generate a Solution with 3 class library project and a UI project (windows or web). I used the DTE2 and Solution2 objects to accomplish this. I am now in the process of adding the project references to each respective projects (Config Layerreferenced to DAL, Config and Dal referenced in BL, Config and BL referenced to UI). The problem now is when I open the solution and browse each project reference folderthe respective referenceswere not reflected. I don't know ifI just missed something.Below is the code I used to do it. Hope you could help me with this one. Thanks.

//Initialization is done on top of these codes.

//Add the class library templates to the solution

vsSolution.AddFromTemplate(csTemplatePath, solutionPath + @"\" + projectConfigName, projectConfigName, false);

vsSolution.AddFromTemplate(csTemplatePath, solutionPath + @"\" + projectDalName, projectDalName, false);

//Check for excluded projects

if (excludedFromCreationType != SWPProjectCreationType.BusinessLayer)

{

//Add BL class library to the solution

vsSolution.AddFromTemplate(csTemplatePath, solutionPath + @"\" + projectBLName, projectBLName, false);

}

if (excludedFromCreationType != SWPProjectCreationType.AdminUI)

{

//Add Admin UI template to the solution

vsSolution.AddFromTemplate(uiTemplatePath, adminUIPath, projectAdminUIName, false);

}

//Add UI template to the solution

vsSolution.AddFromTemplate(uiTemplatePath, uiPath, projectUIName, false);

//Set project references

SetProjectReference(vsSolution.Projects, projectConfigName, projectDalName, projectBLName, projectUIName,

projectAdminUIName, excludedFromCreationType);

//Save the solution

vsSolution.SaveAs(solutionPath + @"\" + solutionName + ".sln");

ide.Quit();

}

private static void SetProjectReference(

Projects solutionProjects, string configProjectName, string dalProjectName,

string blProjectName, string uiProjectName, string adminUIProjectName,

SWPProjectCreationType excludedFromCreationType)

{

//Projects to be referenced

Project projectConfig = null;

Project projectBL = null;

Project projectDAL = null;

Project projectUI = null;

Project projectAdminUI = null;

//Project where reference will be set

VSProject setProjectReference = null;

foreach (Project project in solutionProjects)

{

if (project != null)

{

setProjectReference = (VSProject)project.Object;

if (project.Name.Equals(configProjectName))

{

projectConfig = project;

}

else if (project.Name.Equals(dalProjectName))

{

projectDAL = project;

if (projectConfig != null)

{

setProjectReference.References.AddProject(projectConfig);

}

}

else if (project.Name.Equals(blProjectName) && excludedFromCreationType != SWPProjectCreationType.BusinessLayer)

{

projectBL = project;

if (projectConfig != null && projectDAL != null)

{

setProjectReference.References.Add(projectConfig);

setProjectReference.References.Add(projectDAL);

}

}

//Same code above will go for the UI reference...

}

}

}

jonsanity  Thursday, March 30, 2006 9:20 AM
If you're using GAX, it may be useful to take advantage of the DteHelper class for locating projects and stuff like that.

Web projects must be casted to VsWebsite instead.
kzu  Thursday, March 30, 2006 5:40 PM

I think I got. I just called the Solution.Build method after setting the project references.

But I have another problem. How do I set a project reference for Web Projects? I'm getting an Invalid Cast Exception at this line "setProjectReference = (VSProject)project.Object;" when the project is a Web Application.

Thanks again.

jonsanity  Thursday, March 30, 2006 9:58 AM
If you're using GAX, it may be useful to take advantage of the DteHelper class for locating projects and stuff like that.

Web projects must be casted to VsWebsite instead.
kzu  Thursday, March 30, 2006 5:40 PM

Thanks kzu. I was able to create the project reference in web projects.

I have a couple of questions again.

First, Do you happen to know how to add Solution Items (ex. ReadMe.Txt, Db.vsd) programmatically?

Second, Do you know what this error is "Call was rejected
by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED))"? I do get this error sometimes when I run the code generator I'm doing. But sometimes it doesn't appear. Ussually this happens when I'm calling ths vsSolution.AddFromTemplate... or other methods from Solution2 object.

Thanks in advance.

jonsanity  Friday, March 31, 2006 11:50 AM

You can use google to search for other answers

Custom Search

More Threads

• Can the debugger be used to step through a guidance package?
• How does the .vstemplate run?
• Recipe Framework Error while Registering Guidance Package
• SharePoint recipe problems
• Access to $fileinputname$
• Urgent - Create a new Item (Form)
• Value cannot be null. Parameter name: serviceProvider
• Is GAT/GAX compatible with non-English versions of Visual Studio 2005 ?
• Could I add repeating code with this technology in my solution in C#.net?
• Slow Wizard Input using MonitorArgument