Visual Studio Developer Center >
Visual Studio Forums
>
Visual Studio Extensibility
>
Can we fail the build and add build errors OnBuildBegin event
Can we fail the build and add build errors OnBuildBegin event
- I'm planning to write a VS Addin for VS 2008
In that can we fail the build and add build errors(on some conditions) OnBuildBegin event. I'm using folllowing event handler to raise build begin event
_dispBuildEvents_OnBuildBeginEventHandler
Answers
- Hi Vital,
Sorry for misunderstanding.
Based on my understanding, you have two requirements, as following shows:
1. Add some errors into Error list Window;
2. Build on some conditions (if it does not meet the conditions, cancel the Build).
If I understand correctly, you can achieve these objectives with Add-in:
1. The automation model (EnvDTE80) provides the EnvDTE80.ErrorList and the EnvDTE80.ErrorItems collection. You can use EnvDTE80.ErrorList() function, or OutputWindowPane.OutputTaskItemString method to add errors to Error List. For more information, please see:
HOWTO: Add an error with navigation to the Error List from a Visual Studio add-in
2. You can use _DTE::ExecuteCommand Method to cancel Build as this code shows: _DTE::ExecuteCommand(Build.Cancel) in OnBuildBegin Event on conditions.
Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byNancy ShaoMSFT, ModeratorFriday, November 13, 2009 2:39 AM
All Replies
- Hi NagaVital,
OnBuildBegin event just is triggered when Build action is begin, it means when you click Build this project, this event is firstly triggered.
If you want to use OnBuildBegin Event, firstly add the following code in Exec() function:
EnvDTE.Events events = _applicationObject.Events; buildEvents = (EnvDTE.BuildEvents)events.BuildEvents; buildEvents.OnBuildBegin += new _dispBuildEvents_OnBuildBeginEventHandler(this.OnBuildBegin);
And declare OnBuildBegin class out of Exec() function, as following shows:
The most important thing is defining buildEvents in whole namespace but not in Exec() function, or buildEvents will not valid, for example:public void OnBuildBegin(EnvDTE.vsBuildScope Scope, EnvDTE.vsBuildAction Action) { //Add Your Code here System.Windows.Forms.MessageBox.Show("OnBuildBegin"); }
Please let me know if you have any questions.private DTE2 _applicationObject; private AddIn _addInInstance; BuildEvents buildEvents;
Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us. - Hi Nancy,
Thanks for your reply
I have added the code which fires the Buildbegin event that works fine.
But my main problem is, I want to add some errors into Error List window and I want to fail the Build on some conditions, can we do this?
Either it may be on onBuildbegin or any other event
Refards,
Vital. - Hi Vital,
Sorry for misunderstanding.
Based on my understanding, you have two requirements, as following shows:
1. Add some errors into Error list Window;
2. Build on some conditions (if it does not meet the conditions, cancel the Build).
If I understand correctly, you can achieve these objectives with Add-in:
1. The automation model (EnvDTE80) provides the EnvDTE80.ErrorList and the EnvDTE80.ErrorItems collection. You can use EnvDTE80.ErrorList() function, or OutputWindowPane.OutputTaskItemString method to add errors to Error List. For more information, please see:
HOWTO: Add an error with navigation to the Error List from a Visual Studio add-in
2. You can use _DTE::ExecuteCommand Method to cancel Build as this code shows: _DTE::ExecuteCommand(Build.Cancel) in OnBuildBegin Event on conditions.
Best Regards,
Nancy
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byNancy ShaoMSFT, ModeratorFriday, November 13, 2009 2:39 AM


