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


in extension implement ivsupdatesolutionevents2 , ivssolutionbuildmanager2 used registering caller adviseupdatesolutionevents

for example, called before build actions have begun:

public int updatesolution_begin(ref int pfcancelupdate) {     ... } 

however, need getting status or type of current build action, example: build/rebuild/clean/deploy

available & known variants:

buildevents

with events.buildevents can subscribe onbuildbegin, example:

_buildevents.onbuildbegin += new _dispbuildevents_onbuildbegineventhandler((vsbuildscope scope, vsbuildaction action) => {     buildtype = (buildtype)action; }); 

and use buildtype in places, because vsbuildaction provides necessary information

but updatesolution_begin / updatesolution_startupdate called first as priority advising method, , result buildtype sets late..

also can use onbuildbegin instead of updateprojectcfg_begin / updatesolution_startupdate, our handling needed as possible priority caller

ivsupdatesolutionevents4

the ivsupdatesolutionevents4.updatesolution_beginupdateaction provides dwaction , fired before every update action begins during solution build - before first updateprojectcfg_begin

it's need! because dwaction can check vssolnbuildupdateflags

however :( appeared in vs2012, our extension supports vs2010 , higher... need variant 2010 version

updateprojectcfg_begin

the ivsupdatesolutionevents2.updateprojectcfg_begin provides dwaction (see vssolnbuildupdateflags) , available 2010 version, it's same first buildevents variant - it's late handling (and not quite suitable our task)

question

i can't find documentation this, vssolnbuildupdateflags available vs2010, think should variant getting current state of build action, e.g __vshpropid , getproperty ivshierarchy etc...

is possible ? or can onbuildbegin subscription o_o


upd1:

__vshpropid4

found \visualstudiointegration\common\inc\vsshell100.h:

enum __vshpropid4     {   vshpropid_targetframeworkmoniker    = -2102,     vshpropid_externalitem  = -2103,     vshpropid_supportsaspnetintegration = -2104,     vshpropid_designtimedependencies    = -2105,     vshpropid_builddependencies = -2106,     vshpropid_buildaction   = -2107,     vshpropid_descriptivename   = -2108,     vshpropid_alwaysbuildondebuglaunch  = -2109,     vshpropid_first4    = -2109     } ; typedef /* [public] */ dword vshpropid4; 

so, looked doc. - bstr __vshpropid4.vshpropid_buildaction - retrieves build action item

ok, news, next step... try get, example:

object type; hr.getproperty((uint)vsconstants.vsitemid.root, (int)__vshpropid4.vshpropid_buildaction, out type); 

where hr a, example:

ivssolutionbuildmanager2 sbm = (ivssolutionbuildmanager2)serviceprovider.globalprovider.getservice(typeof(svssolutionbuildmanager));  ivshierarchy hr = null; sbm.get_startupproject(out hr); 

however, type null... may problem notifying(has not occurred), similar result if used phierproj updateprojectcfg_begin / updateprojectcfg_done:

int updateprojectcfg_begin(ivshierarchy phierproj, ivscfg pcfgproj, ivscfg pcfgsln, uint dwaction, ref int pfcancel) int updateprojectcfg_done(ivshierarchy phierproj, ivscfg pcfgproj, ivscfg pcfgsln, uint dwaction, int fsuccess, int fcancel) 

which provides dwaction...

and., how use vshpropid_buildaction -_- problem ivshierarchy ?

finished :)

solution 1

commandevents

with envdte.commandevents, can work before processing ivsupdatesolutionevents2 , listen 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 can work type of action in updatesolution_begin, example:

if(evt.buildtype != buildtype.common && evt.buildtype != buildtype) {     //... } 

...

if(buildtype == buildtype.clean || buildtype == buildtype.linkonly){    //... } 

etc.

full example can see in sources (see comment where). also, think it’s not best variant, it's variant vs2010 , higher versions (also should work on older 2005 & 2008, think)…

for vs2012 , newer recommend ivsupdatesolutionevents4

so, problem solved.

other best variants ?


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -