locked
How to create new Csharp Solution, Project programmatically ( EnvDTE ) ?? related RRS feed

  • Question

  •  

      I have used this below code given by Ole Preisler. Now i want to add some reference programatically with other references in new solution like -using NLog;

       what should i do ??

    code-----

    Add a reference to EnvDTE and EnvDTE80 and copy and paste this code code snippet into your consoleApp project. That will do the correct instantiation of VS and create a solution from template.

     

     

         EnvDTE.Solution soln = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution")) as EnvDTE.Solution;

    soln.DTE.MainWindow.Visible = true;

    EnvDTE80.Solution2 soln2 = soln as EnvDTE80.Solution2;

    string csTemplatePath = soln2.GetProjectTemplate("ConsoleApplication.zip", "CSharp");

    soln.AddFromTemplate(csTemplatePath, @"C:\temp\FooBar", "Foo", false);

    int x = soln.AddIns.Count;

    • Edited by ShailiShah Wednesday, February 8, 2012 5:43 AM
    Wednesday, February 8, 2012 5:39 AM

All replies

  • Hi ShailiShah,

    this example shows how to add dll as a referance to project

    EnvDTE.Project projectBL = .. (get project in solution)
    VSLangProj.VSProject vsprojectBL = projectBL.Object; // project that will be added referance
    vsprojectBL.References.Add(Constants.DllPath);

    Regards,

    Mehmet.

    Wednesday, February 8, 2012 12:25 PM
  • thanks for your help.

    can u give me perfect solution ?

    i am using visual studio 2010 for programatically creating visual studio solution.i am using above mention code.using code i can create solution but i want to add reference like using NLog; in new solution.

    thta means that when new solution is created dynamically then the reference- using NLog; should also be added .

    plz solve my issue. 


    • Edited by ShailiShah Wednesday, February 8, 2012 1:14 PM
    Wednesday, February 8, 2012 1:00 PM
  • You should consider creating your project template with the required using statements and references already added. Then you just have to create the project. And if you want to do that programatically, you can use the EnvDTE.Solution.AddFromTemplate.

    Sincerely,


    Ed Dore

    Thursday, February 9, 2012 4:30 AM
  • Hi,

         Thanks for your reply .

        

         i have already use this code to create solution from template.-----

         EnvDTE.Solution soln = System.Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.Solution")) as EnvDTE.Solution;

    soln.DTE.MainWindow.Visible = true;

    EnvDTE80.Solution2 soln2 = soln as EnvDTE80.Solution2;

    string csTemplatePath = soln2.GetProjectTemplate("ConsoleApplication.zip", "CSharp");

    soln.AddFromTemplate(csTemplatePath, @"C:\temp\FooBar", "Foo", false);

    int x = soln.AddIns.Count;     this is adding some default references in the solution but  besides this default references i want to add Nlog.dll reference to use Nlog facility in my programatically created solution and i also want to write using Nlog in the form after adding reference in solution.    plz help me out.


    plz reply.
    • Edited by ShailiShah Saturday, February 11, 2012 10:19 AM
    Thursday, February 9, 2012 5:08 AM