Current type of the build action from Visual Studio - Microsoft.VisualStudio.Shell.Interop

左心房为你撑大大i 提交于 2019-12-05 23:10:15

finished :)

Solution 1

CommandEvents

With the EnvDTE.CommandEvents, we can work before processing IVsUpdateSolutionEvents2 and listen all incoming commands, sample:

...

GUID: {5EFC7975-14BC-11CF-9B2B-00AA00573819} (ID: 882) :: Build.BuildSolution
GUID: {5EFC7975-14BC-11CF-9B2B-00AA00573819} (ID: 883) :: Build.RebuildSolution
GUID: {5EFC7975-14BC-11CF-9B2B-00AA00573819} (ID: 884) :: Build.DeploySolution
GUID: {5EFC7975-14BC-11CF-9B2B-00AA00573819} (ID: 885) :: Build.CleanSolution
GUID: {1496A755-94DE-11D0-8C3F-00C04FC2AAE2} (ID: 2005) :: Build.PublishSelection
GUID: {1496A755-94DE-11D0-8C3F-00C04FC2AAE2} (ID: 353) :: Build.Link    
...

for example:

_cmdEvents.BeforeExecute += new _dispCommandEvents_BeforeExecuteEventHandler((string guid, int id, object customIn, object customOut, ref bool cancelDefault) => {

        if(GuidList.VSStd97CmdID == guid || GuidList.VSStd2KCmdID == guid) {
            _c.updateContext((BuildType)id);
        }

});

Now we can work with type of action in UpdateSolution_Begin, for example:

if(evt.BuildType != BuildType.Common && evt.BuildType != buildType) {
    //...
}

...

if(buildType == BuildType.Clean || buildType == BuildType.LinkOnly){
   //...
}

etc.

full example you can see in sources (see comment where). Also, i think it’s not best variant, however it's variant for VS2010 and higher versions (also should work on very older 2005 & 2008, i think)…

For VS2012 and newer i recommend the IVsUpdateSolutionEvents4

So, my problem solved.

Other best variants ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!