Catch reference BEFORE load

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

How can I track reference load. e.g
I have a form with some references. I want to be able to track the event
when one of references loaded, thus I have to catch BEFORE_REFERENCE_LOAD
event. How it possible to do?

TNX
 
Hi,
How can I track reference load. e.g
I have a form with some references. I want to be able to track the event
when one of references loaded, thus I have to catch BEFORE_REFERENCE_LOAD
event. How it possible to do?

TNX

Could You be more specify with: reference load?
Do You think of *Load* event?

Marcin
 
Hi Tamir,

Based on my understanding, you want to hook into the process of adding
reference.

What is the exactly meaning of your "adding reference"? Do you refer to
adding reference in the IDE at design-time?
Adding reference in the IDE will only load the meta data of that assembly,
IDE will not load that entire assembly. I think you must use the IDE macro
to get this done.

If you mean load assembly and use the types in that assembly at runtime, I
think because you load that assembly, you should know when that assembly is
loading.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
I mean such thing:
I have form with some references. I want to be able to do some event on
reference BEFORE it been loaded by the main form
 
Hi Tamir,

If you want to be notified when the developer are invoking "Add Reference"
dialog, you should write an add-in for your IDE.

In the OnConnection method, you may get the "Add Reference" command, then
you can add event handler for this command, do like this:

applicationObject = (DTE)application;
addInInstance = (AddIn)addInInst;
Command addref_cmd=null;

foreach(Command cmd in applicationObject.Commands)
{
if(cmd.Name!=null)
{
if(cmd.Name.Equals("Project.AddReference"))
{
addref_cmd=cmd;
}
}
}

if(addref_cmd!=null)
{
CommandEvents
objAddReferenceCommandEvents=applicationObject.Events.get_CommandEvents(addr
ef_cmd.Guid, addref_cmd.ID);
objAddReferenceCommandEvents.BeforeExecute+=new
_dispCommandEvents_BeforeExecuteEventHandler(objAddReferenceCommandEvents_Be
foreExecute);
}
else
{
System.Windows.Forms.MessageBox.Show("You did not refered the command!!");
}

private void objAddReferenceCommandEvents_BeforeExecute(string Guid, int
ID, object CustomIn, object CustomOut, ref bool CancelDefault)
{
System.Windows.Forms.MessageBox.Show("You invoked add
reference!");
}

If you want to determine when the actual reference is adding to the
project, you should use another approach:

First, add VSLangProj reference in your add-in project.
Then, You should convert your DTE.Solution.Projects(0).Object to
VSLangProj.VSProject,
At last, use ReferenceAdded event of
VSLangProj.VSProject.Events.ReferencesEvents object.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Have you tried my suggestion? Is your problem resolved?

Please feel free to feedback, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Thanks very much for your feedback.

I am glad it works for you. If you have any further concern, please feel
free to feedback, I will help you. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Back
Top