Howto programatically add references to active project?

Hi All,

I'm relatively a newbie in dot.net development. But I've working experiences with VC/VB programming as well as Java. So, not finding too hard to adopt myself with the flexibility offered by dot.net framework.

Recently I've been creating a web application development framework which will include a custom control library to be used in the web projects associated with the framework.

To maximize the usability of the framework I've planned to create an Custom Web Project Item Template Wizard that will create a web form based on the framework when selected from the Add Item.

As additional features in the wizard, I want the wizard to check active project references for my framework dll and add references to the framework dll as well as any dependencies if not found.

Also i want the same behavior for the ToolBox window : The wizard will look for a named Tab there (That will be created by the wizard in previous execution), create Tab if not found and add custom web control components from the framework dll for user convenience.

Let me know whether these can be done or not, so that I can include/exclude this feature from my project plan. I'm primarily interested in VS.Net 2003 extensibility.

And if these tasks can be done programmatically from the wizard plz help me with resource links that covers such issues or provide a working code snippets to make me understand the facts.

Thanx in advance




Answer this question

Howto programatically add references to active project?

  • Mystagogue

    To add a reference to a web project, you need to first create a Wizard Extension. Then, in the ProjectFinishedGenerating method, add code such as this:

    VsWebSite.AssemblyReferences refsObject = ((VsWebSite.VSWebSite)proj.Object).References;

    refsObject.AddFromFile("C:\path\File.dll");

    Where proj is the project that you have generated from your template. To add a control to the toolbox, you can simply drop the assembly in the folder "Documents\Visual Studio 2005\Controls" (you can create a sub folder here, which will be the tab name) and then run the command Tools.InstallCommunityControls (using the automation model's DTE.ExecuteCommand method) which will automatically add the controls to the toolbox

    Craig



  • Allan Nielsen

    Hi,

    Yes, you can automate the IDE (the DTE object) from an external app. See:

    HOWTO: Automating Visual Studio .NET from outside the IDE.

    http://www.mztools.com/resources_vsnet_addins.htm



  • Shuaib

    Dear Craig;

    I just want to ask about if I can create project or/and solution programatically from windows application instead of Addin application, if yes please tell me which reference(s) should I use

    Thank you in advance :-)

    Ramy Mahrous
    Faculty of Computers and Information
    Helwan University, Egypt
    Personal blog:
    http://ramymahrous. blogspot. com

    Technical blog: http://www.hasebat. com


  • Howto programatically add references to active project?