locked
Event for addition/removal of projects RRS feed

  • Question

  • I am currently working on a Visual Studio 2019 Extension and I am searching for a way to get notified when a project gets added or removed from the Solution Explorer. However I am trying to achieve this with native interfaces e.g. without the DTE.

    I already tried using the IVsHierarchyEvents/IVsHierarchyEvents2, however it will only call the item added method, but not the item removed event. Is there any way you can achieve this? 

    • Moved by CoolDadTx Monday, March 9, 2020 2:31 PM Extensibility related
    Sunday, March 8, 2020 5:36 PM

Answers

All replies

  • Hi 24_minutes,

    Thank you for posting here.

    Since this question is about the development of Visual Studio extension programs, in order to provide you with more professional support, we will move your thread to the Visual Studio Integrate forum.

    The Visual C# forum discusses and asks questions about the C# programming language, IDE, libraries, samples, and tools.

    Best Regards,

    Timon


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 9, 2020 9:34 AM
  • Is there any way you can link me to the new post?

    Monday, March 9, 2020 10:50 AM
  • It's been a long time since I looked into this but I believe you want the IVsSolutionEvents. This gives you access to notifications related to changes in the solution including adding/removing/unloading projects. Which I believe is what you're looking for.

    As documented in the interface, to get access to this first grab the SVsSolution service via `GetService`. This should be available (and static) for the life of your extension. From there you can use `AdviseSolutionEvents`.


    Michael Taylor http://www.michaeltaylorp3.net

    Monday, March 9, 2020 2:38 PM
  • I looked through all the `IVsSolutionEvents` multiple times by now and I can't find ANY way method which would just fire on addition of a new projects. All those methods can occur for all pre existing projects. If I am incorrect feel free to correct me.

     
    Monday, March 9, 2020 7:17 PM
  • Hi 24-minutes,

    Welcome to MSDN forum.

    When one project is added into solution, the project will be default opened in solution. You could check it in VS IDE. So "IVsSolutionEvents.OnAfterOpenProject" which will listen for the project that has been added to the solution, both new and old, should meet your requirements.

    However the load/upload feature which is used for pre existing projects.

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Tuesday, March 10, 2020 5:36 AM
  • It would still fire for reloaded projects, how would I differentiate between an added project and an reloaded project then? I really want to avoid keeping a cache or similar.
    Tuesday, March 10, 2020 8:25 AM
  • Hi 24_minutes,

    Thank you for feedback.

    If the method could run sucessfully, it will return "OK". Maybe you could using return value to judge it:

    if(ReturnofStart)
    {
        If(ReturnofLoad)
            {//loading}
        else
            {//adding}
    }

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Wednesday, March 11, 2020 10:01 AM
  • I am not quite sure, how this should help me? I am searching for a way which would allow me to distinguish between newly added projects and projects which only got reloaded and all this from within the IVsSolutionEvents.OnAfterOpenProject callback.
    Thursday, March 12, 2020 1:47 PM
  • Hi 24_minutes,

    Sorry for delay in reply.

    You could try to set a custom tag in OnAfterOpenProject event , which help you recognize if your project will be reloaded.

    Please refer this sample here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/2d38f312-e566-4f65-bf2a-92041c51d7cc/how-do-i-differentiate-between-a-newly-added-project-and-reloaded-project-in-onafteropenproject?forum=vsx

    Best Regards,

    Dylan


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    • Marked as answer by 24_minutes Saturday, March 21, 2020 2:25 AM
    Friday, March 20, 2020 8:42 AM
  • Thanks for the response, that helped a lot!

    Saturday, March 21, 2020 2:25 AM