locked
Template that creates a project in the selected folder RRS feed

  • Question

  • I need my project and solution to be created exactly in the folder selected in the New Project dialog. Currently, a folder is created matching the project name, and the solution file and project are created in that folder. As a result, the user is forced to close, move, and reopen the solution before it's usable.

    How can I make the project template create the file on disk exactly where requested?

     

    Saturday, June 26, 2010 9:01 PM

Answers

  • You could try the following

    Create a project wizard that creates the project using the template you refered to (EnvDTE80.Soltion2.AddFromTemplate method, you can obtain the location of the template with EnvDTE80.Solution2.GetProject[Item]Template).
    After creating the project you'll have the wizard to perform the following actions

    Remove the project from the current solution (EnvDTE80.Solution2.Remove method).
    Move the contents of the (default) projectfolder to the folder of your choice (using System.IO classes/methods)
    Add the project again to the solution (EnvDTE80.Solution2.AddFromFile method) refering to the project file at the new location.

    I haven't tried this yet myself but I think it'll work.

    • Marked as answer by Nancy Shao Tuesday, July 6, 2010 3:49 AM
    Monday, June 28, 2010 5:56 PM

All replies

  • Hi A280Z28,

    Thanks for your post!

    I'm not sure I understand you clearly, do you mean you want to add your custom project by Add New Project, and it forces Visual Studio reopen the solution. If so, I think it's by design, Add New Project will force Visual Studio close current solution, and create a new solution. If you only want to add a new project to current solution, you can click File > Add > New Project or right click solution node and choose Add > New Project.

    But if your question is about custom project template, I would suggest you watch this video about creat custom project templates in VS 2008 with link:

    http://msdn.microsoft.com/en-us/vstudio/cc703626.aspx

    If I misunderstood you, or you have any comments, please feel free to let me know.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, June 28, 2010 6:03 AM
  • That is a bit  tricky because Visual Studio allways creates a folder for a project.
    The simplest way to solve this is to create the project as usual the remove it from your solution. In Windows explorer move the project to the location of your choice and add it again to your solution with "Add Existing Project".
    This will take very little time so an automated solution is not cost effective (but may be fun).

    If you want an automated solution I can only suggest that you look into creating custom templates and the use of a Template Wizard and/or a project wizard.
    A TemplateWizard allows you to define and initialize your own template parameters that will be referred to in the files incorporated in the template.
    A project wizard allows you to add all kinds of functionality prior to and after creating the project.

    References

    http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.templatewizard.aspx
    http://msdn.microsoft.com/en-US/library/ms185301(v=VS.80).aspx
    http://msdn.microsoft.com/en-us/library/7k3w6w59(VS.80).aspx
    http://msdn.microsoft.com/en-us/library/eehb4faa(VS.80).aspx

    From any of these links you will find references that lead you to related usefull information.

    P.S.

    I use a template wizard to derive template parameters to qualify the names of projects and default namespaces from the physical location of the solution within a TFS Workspace. This location conforms to corporate standards regarding (logical) Business Domains, Application Domains, and Application Types.

    Monday, June 28, 2010 7:45 AM
  • That is a bit  tricky because Visual Studio allways creates a folder for a project.
    The simplest way to solve this is to create the project as usual the remove it from your solution. In Windows explorer move the project to the location of your choice and add it again to your solution with "Add Existing Project".
    This will take very little time so an automated solution is not cost effective (but may be fun).

    This is how we're handling things right now. Unfortunately, this is the primary template for a custom project type/language, so the instructions included with our release state that every user has to manually move the project after creating it every time.
    Monday, June 28, 2010 1:41 PM
  • You could try the following

    Create a project wizard that creates the project using the template you refered to (EnvDTE80.Soltion2.AddFromTemplate method, you can obtain the location of the template with EnvDTE80.Solution2.GetProject[Item]Template).
    After creating the project you'll have the wizard to perform the following actions

    Remove the project from the current solution (EnvDTE80.Solution2.Remove method).
    Move the contents of the (default) projectfolder to the folder of your choice (using System.IO classes/methods)
    Add the project again to the solution (EnvDTE80.Solution2.AddFromFile method) refering to the project file at the new location.

    I haven't tried this yet myself but I think it'll work.

    • Marked as answer by Nancy Shao Tuesday, July 6, 2010 3:49 AM
    Monday, June 28, 2010 5:56 PM
  • Hello,

    I am writing to follow up this issue. Please let me know what I can help. Thanks.

     

    Regards,

    Nancy Shao [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, July 5, 2010 7:18 AM