locked
Get the solution folder of a project RRS feed

  • Question

  • Hi there,

    I got the Project reference of a project in my solution (within my VSX package).

    Now I delete this project, make changes in the structure and files and re-add this project again. This works quite well. My problem is that the project gets added in the project root and not in any solution folders it was before.

    My question is: how can I determine if the project I removed was below a solution folder? For my source code it would be awesome to get the solution folder of a project so I can just remember that folder in a variable before I delete the project.

    The other way round is to remember all solution folders and check if one of them contains my project.

    But I'm not sure how to achieve that. I've tried things like ParentProjectItem of a project but that wont return the solution folder.

    Can someone provide a hint how to easily achieve this?

    Thanks in advance and bye
    Fabian


    The Visual Studio Settings-Switcher! Visit http://visualstudiogallery.msdn.microsoft.com/a79072f7-3109-44a0-95c0-9c50e729d6a3

    Friday, September 19, 2014 4:28 PM

Answers

  • - Using the automation model (EnvDTE), either from an add-in or package:

    ParentProjectItem.Collection.Parent

    that returns Object type, that you must try to cast to either Project or ProjectItem.

    See:

    HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in.
    http://www.visualstudioextensibility.com/articles/add-ins/

    - Using the native hierarchies, either from an add-in or package:

    VSHPROPID_Parent property

    HOWTO: Navigate the files of a solution using the IVsHierarchy interface from an add-in.
    (same link)

    LearnVSXNow! Part #36 - Working with Hierarchies Part 3 - Properties and Hierarchy Traversal

    http://dotneteers.net/blogs/divedeeper/archive/2008/10/16/LearnVSXNowPart36.aspx


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.


    Friday, September 19, 2014 7:29 PM
  • Hello,

    some time ago I had a quite similar problem, I had to get the project paths. So this worked for me ..

    private void GetProjectPaths() {

    string slnFullName = this.GetActiveIDE().Solution.FullName; Projects projects = GetActiveIDE().Solution.Projects; foreach (Project project in projects) { string prjFullName = project.FullName } } private DTE2 GetActiveIDE() { return Package.GetGlobalService(typeof(DTE)) as DTE2; }

    Greetings


    • Edited by Merando Tuesday, September 23, 2014 10:59 AM formatting
    • Marked as answer by Caillen Monday, September 29, 2014 7:57 AM
    Tuesday, September 23, 2014 10:58 AM

All replies

  • - Using the automation model (EnvDTE), either from an add-in or package:

    ParentProjectItem.Collection.Parent

    that returns Object type, that you must try to cast to either Project or ProjectItem.

    See:

    HOWTO: Navigate the files of a solution from a Visual Studio .NET macro or add-in.
    http://www.visualstudioextensibility.com/articles/add-ins/

    - Using the native hierarchies, either from an add-in or package:

    VSHPROPID_Parent property

    HOWTO: Navigate the files of a solution using the IVsHierarchy interface from an add-in.
    (same link)

    LearnVSXNow! Part #36 - Working with Hierarchies Part 3 - Properties and Hierarchy Traversal

    http://dotneteers.net/blogs/divedeeper/archive/2008/10/16/LearnVSXNowPart36.aspx


    * My new blog about VSX: http://www.visualstudioextensibility.com * Twitter: https://twitter.com/VSExtensibility * MZ-Tools productivity extension for Visual Studio: http://www.mztools.com.


    Friday, September 19, 2014 7:29 PM
  • Hello,

    some time ago I had a quite similar problem, I had to get the project paths. So this worked for me ..

    private void GetProjectPaths() {

    string slnFullName = this.GetActiveIDE().Solution.FullName; Projects projects = GetActiveIDE().Solution.Projects; foreach (Project project in projects) { string prjFullName = project.FullName } } private DTE2 GetActiveIDE() { return Package.GetGlobalService(typeof(DTE)) as DTE2; }

    Greetings


    • Edited by Merando Tuesday, September 23, 2014 10:59 AM formatting
    • Marked as answer by Caillen Monday, September 29, 2014 7:57 AM
    Tuesday, September 23, 2014 10:58 AM