locked
Change project directory in Multi-Project template RRS feed

  • Question

  • I've created a multi-project template in VisualStudio 2008.

    My problem is that when the new project is generated, off of the individual projects are in the same root directory. This is not allowed in my organisation and the BLL must reside elsewhere.

    I've been able to generate the files within the BLL project in another folder using parameters, but the .csproj file stays put.

    Is there any way to accomplish this?

    Here's what I've tried, and it's not working:

    In the RunStarted, I've captured the automationObject cast into a _DTE.

    In ProjectFinishedGenerating, I try the following code, and it doesn't want to delete or save the project as I want it to.

    Project p = dte.Solution.Item(1);  
    project.Delete();  
    p.SaveAs(BOLocation + @"\" + project.Name);  
     
    //BOLocation is the user input path where the BLL should reside 

    If anyone could help me out with this, I'd appreciate it. GAT/GAX is not an option for us.
    Tuesday, October 21, 2008 6:01 PM

Answers

  •  For fun, I tied to just add a new console project. It worked fine. It turns out that my compressed folder was somehow corrupted. I was able to recompress the template directory, and it worked fine.

    Thank you for your help.

    For those of you following along, I am now adding the 3 projects in the solution directory, and then adding the BLL programmatically, then adding the reference to my ServiceImpl project programmatically.

    Here's the code:

            public void RunFinished()  
            {  
                if (currentlyWorkingOn == ProjectPart.None)  
                {  
                    AddBusinessOperations(dte);  
     
                    //add project references  
                    VSProject2 vsProj = (VSProject2)SIProject.Object;                                 
                    vsProj.References.AddProject(BOProject);  
                }  
     
            }  
     
            private void AddBusinessOperations(_DTE dte)  
            {  
                try  
                {  
                    Solution3 soln = (Solution3)dte.Solution;  
                    string projectName = SolutionName + "." + "BusinessOperations";  
                    string templatePath = soln.GetProjectTemplate("BOProject.zip", "CSharp");  
                    soln.AddFromTemplate(templatePath, BOLocation, projectName, false);  
                }  
                catch (Exception e)  
                {  
                    MessageBox.Show("Error Adding BO: " + e.ToString());  
                    throw new WizardBackoutException();  
                }  
            } 
    • Edited by Bob Egan Monday, October 27, 2008 7:09 PM
    • Marked as answer by Bob Egan Monday, October 27, 2008 7:09 PM
    Monday, October 27, 2008 7:04 PM

All replies


  • Hi Bob,

    What did you mean by "it's not working"? Did you get any error message? If you want to move some projects out of the solution directory, one approach would be overriding the RunFinished method and move the projects in this method. Then you can use the WizardExtension Element to run the method after the project is created.

    More information
    http://msdn.microsoft.com/en-us/library/ms171411.aspx
    http://msdn.microsoft.com/en-us/library/ms185301.aspx

    Thanks,
    Rong-Chun Zhang

    Please mark the replies as answers if they help and unmark if they don't.
    Thursday, October 23, 2008 8:17 AM
  • Thank you for responding. I'm getting an error saying that the project folder already exists.

    I can't add it last, because it is referenced by another project in the solution if I move it in runFinished, won't that break my dependencies?

    Here's a little more background:

    We want to template our solution. Each consists of 4 projects. Our Business Operations (BLL) cannot be in any subordinate of the solution folder and must be seperate and apart.

    I have multi-project template that loads the three other projects into a solution. That is working fine.

    In ProjectFinishedGenerating I have this code:

    string folder = BOLocation + @"\BusinessOperations";  
                            Solution2 soln = (Solution2)dte.Solution;  
                            string projectName = SafeTeamProjectName + "." + SolutionName + "." + "BusinessOperations";  
                            Project proj = soln.AddSolutionFolder(projectName);  
                            SolutionFolder sf = (SolutionFolder)proj.Object;  
                            string templatePath = soln.GetProjectTemplate("BOProject.zip", "CSharp");  
                            sf.AddFromTemplate(templatePath, folder, projectName);  
                            BusinessOperationsProject = soln.Item(i);  
                            MessageBox.Show(ServiceContractsProject.Name); 

     

    Here's my template:

    <TemplateContent> 
        <Project TargetFileName="$BOLocation$\$safeprojectname$.BusinessOperations.csproj" File="WCFWebServiceSample.BusinessOperations.csproj" ReplaceParameters="true">  
          <Folder Name="BusinessLogic" TargetFolderName="$BOLocation$\BusinessLogic">  
            <ProjectItem ReplaceParameters="true" TargetFileName="$safeprojectname$BusinessManager.cs">ServiceBusinessManagerTemplate.cs</ProjectItem> 
          </Folder> 
          <ProjectItem ReplaceParameters="false" TargetFileName="$BOLocation$\privatekey.snk">privatekey.snk</ProjectItem> 
          <Folder Name="Properties" TargetFolderName="$BOLocation$\Properties">  
            <ProjectItem ReplaceParameters="true" TargetFileName="AssemblyInfo.cs">AssemblyInfo.cs</ProjectItem> 
          </Folder> 
        </Project> 
      </TemplateContent> 
      <WizardExtension> 
        <Assembly>AAWizard, Version=1.0.0.0, Culture=NeutralPublicKeyToken=875fa32958881c7c</Assembly>  
        <FullClassName>AAWizard.IWizImpl</FullClassName> 
      </WizardExtension> 
      <WizardData Name="ProjectPart">BusinessOperations</WizardData> 
    </VSTemplate> 

    Please note the folders that my properties and business logic are in.

    It looks to me like the wizard adds the project items first before saving the project, and then when it gets there, it blows up because there are subfolders.

    If I try to install to another directory, I get a file not found error from the template looking for the csproj file.

    Is there any way to accomplish this? If so, can you post a code example?

    Thank you,

    Bob
    Thursday, October 23, 2008 4:17 PM
  • Bob Egan said:

    We want to template our solution. Each consists of 4 projects. Our Business Operations (BLL) cannot be in any subordinate of the solution folder and must be seperate and apart.


    Hi,

    You may try to use the SolutionFolder element to group your projects in multi-project templates except the BLL project. For more information about SolutionFolder element, please check the following page:

    http://msdn.microsoft.com/en-us/library/ms171399(VS.80).aspx

    Thanks,
    Rong-Chun Zhang

    Please mark the replies as answers if they help and unmark if they don't.
    Friday, October 24, 2008 8:29 AM
  • I think you're missing the point here.

    I want the BOProject in a totally seperate folder from the rest of the solution ie.

    Solution folder = C:\MySolution

    it has

    C:\MySolution\Service
    C:\MySolution\Contracts
    etc...

    My BO Project should be here:

    C:\MyLibraries\MySolution\BOProject

    But I still want the BOProject generated by the template, and included in C:\MySolution\MySolution.sln

    Let's try this another way:

    In RunFinished, I should be able to do this:

    BOProject.SaveAs(BOLocation + @"\" + BOProject.Name);  
    Project p = dte.Solution.Item(2); //THIS IS THE BO PROJECT  
    dte.Solution.Remove(p);  
    dte.Solution.AddFromFile(BOProject.FileName, false); 


    Now I get an error saying that the directory cannot be changed: The project file can only be saved into the project location....
    • Edited by Bob Egan Friday, October 24, 2008 3:46 PM
    Friday, October 24, 2008 1:18 PM
  •  For fun, I tied to just add a new console project. It worked fine. It turns out that my compressed folder was somehow corrupted. I was able to recompress the template directory, and it worked fine.

    Thank you for your help.

    For those of you following along, I am now adding the 3 projects in the solution directory, and then adding the BLL programmatically, then adding the reference to my ServiceImpl project programmatically.

    Here's the code:

            public void RunFinished()  
            {  
                if (currentlyWorkingOn == ProjectPart.None)  
                {  
                    AddBusinessOperations(dte);  
     
                    //add project references  
                    VSProject2 vsProj = (VSProject2)SIProject.Object;                                 
                    vsProj.References.AddProject(BOProject);  
                }  
     
            }  
     
            private void AddBusinessOperations(_DTE dte)  
            {  
                try  
                {  
                    Solution3 soln = (Solution3)dte.Solution;  
                    string projectName = SolutionName + "." + "BusinessOperations";  
                    string templatePath = soln.GetProjectTemplate("BOProject.zip", "CSharp");  
                    soln.AddFromTemplate(templatePath, BOLocation, projectName, false);  
                }  
                catch (Exception e)  
                {  
                    MessageBox.Show("Error Adding BO: " + e.ToString());  
                    throw new WizardBackoutException();  
                }  
            } 
    • Edited by Bob Egan Monday, October 27, 2008 7:09 PM
    • Marked as answer by Bob Egan Monday, October 27, 2008 7:09 PM
    Monday, October 27, 2008 7:04 PM