locked
Event handler for PostBuild Event of a project in side extension RRS feed

  • Question

  • hi,

    I am building an addin for visual studio & I want to execute some complex c# code once the project is build.

    How can i achieve this inside the Visual studio Extension via c#?


    • Edited by Piyush Parate Saturday, May 16, 2015 3:38 PM
    • Moved by Mike Danes Monday, May 18, 2015 5:04 AM VS extension related
    Saturday, May 16, 2015 3:35 PM

Answers

  • Hi,

    The most easiest way is to use the BuildEvents of DTE object,

    _dispBuildEvents_Event.OnBuildDone Event

    See the sample here:

    private void MenuItemCallback(object sender, EventArgs e)
            {
                DTE dte = GetService(typeof(SDTE)) as DTE;
                dte.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
            }
    
            void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
            {
                throw new NotImplementedException();
            }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 9:19 AM
  • Hi Caillen,

    That example, as written, is subject to garbage collection and the event handler would be disconnected. See:

    PRB: Visual Studio .NET events being disconnected from add-in.

    http://www.mztools.com/articles/2005/MZ2005012.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.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 2:00 PM
  • See:

    HOWTO: Performing some action before or after a build from a Visual Studio macro or add-in

    http://www.mztools.com/articles/2007/MZ2007029.aspx

    (note: you can use also DTE in a package as explained in the other answer by Caillen Zhong)


    * 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.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 2:03 PM

All replies

  • Hi,

    The most easiest way is to use the BuildEvents of DTE object,

    _dispBuildEvents_Event.OnBuildDone Event

    See the sample here:

    private void MenuItemCallback(object sender, EventArgs e)
            {
                DTE dte = GetService(typeof(SDTE)) as DTE;
                dte.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
            }
    
            void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
            {
                throw new NotImplementedException();
            }


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 9:19 AM
  • Hi Caillen,

    That example, as written, is subject to garbage collection and the event handler would be disconnected. See:

    PRB: Visual Studio .NET events being disconnected from add-in.

    http://www.mztools.com/articles/2005/MZ2005012.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.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 2:00 PM
  • See:

    HOWTO: Performing some action before or after a build from a Visual Studio macro or add-in

    http://www.mztools.com/articles/2007/MZ2007029.aspx

    (note: you can use also DTE in a package as explained in the other answer by Caillen Zhong)


    * 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.

    • Marked as answer by Caillen Monday, May 25, 2015 11:34 AM
    Monday, May 18, 2015 2:03 PM
  • Hi Caillen,

    That example, as written, is subject to garbage collection and the event handler would be disconnected. See:

    PRB: Visual Studio .NET events being disconnected from add-in.

    http://www.mztools.com/articles/2005/MZ2005012.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.


    Correct, thanks Carlos.

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, May 19, 2015 9:13 AM