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...
}
}
}