Hi. I'm just new with 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 Layer referenced 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 folder the respective references were not reflected. I don't know if I 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 solutionvsSolution.AddFromTemplate(csTemplatePath, solutionPath +
@"\" + projectBLName, projectBLName, false);}
if (excludedFromCreationType != SWPProjectCreationType.AdminUI){
//Add Admin UI template to the solutionvsSolution.AddFromTemplate(uiTemplatePath, adminUIPath, projectAdminUIName,
false);}
//Add UI template to the solutionvsSolution.AddFromTemplate(uiTemplatePath, uiPath, projectUIName,
false); //Set project referencesSetProjectReference(vsSolution.Projects, projectConfigName, projectDalName, projectBLName, projectUIName,
projectAdminUIName, excludedFromCreationType);
//Save the solutionvsSolution.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){
VSProject)project.Object; if (project.Name.Equals(configProjectName))setProjectReference = (
{
projectConfig = project;
}
else if (project.Name.Equals(dalProjectName)){
if (projectConfig != null)projectDAL = project;
{
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...
}
}
}

Added project reference not reflected
MSI Setup too complicated
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.
David Schleifer - MSFT
Web projects must be casted to VsWebsite instead.
gemma
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.