Output Build Order of Visual Studio solution to a text file
This is a good candidate for a Visual Studio Plugin project.
- Create a new Visual Studio Add-in project.
- In the project creation wizard make sure you choose the following configuration in the Choose Add-in Options step (the other steps are not important, I'm assuming you'll use C#):
In the Connect.cs file, add the following fields:
private BuildEvents _buildEvents; private Events _events; private bool buildEventConnected = false;
And add / modify these methods accordingly:
public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom) { _applicationObject = (DTE2)application; _addInInstance = (AddIn)addInInst; _events = _applicationObject.Events; _buildEvents = _events.BuildEvents; if (connectMode != ext_ConnectMode.ext_cm_UISetup && !buildEventConnected) { _buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); buildEventConnected = true; } } private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action) { const string BUILD_OUTPUT_PANE_GUID = "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}"; TextDocument txtOutput = default(TextDocument); TextSelection txtSelection = default(TextSelection); Window vsWindow = default(Window); vsWindow = _applicationObject.Windows.Item(EnvDTE.Constants.vsWindowKindOutput); OutputWindow vsOutputWindow = default(OutputWindow); OutputWindowPane objBuildOutputWindowPane = default(OutputWindowPane); vsOutputWindow = (OutputWindow)vsWindow.Object; foreach (OutputWindowPane objOutputWindowPane in vsOutputWindow.OutputWindowPanes) { if (objOutputWindowPane.Guid.ToUpper() == BUILD_OUTPUT_PANE_GUID) { objBuildOutputWindowPane = objOutputWindowPane; break; } } txtOutput = objBuildOutputWindowPane.TextDocument; txtSelection = txtOutput.Selection; txtSelection.StartOfDocument(false); txtSelection.EndOfDocument(true); objBuildOutputWindowPane.OutputString(System.DateTime.Now.ToString()); txtSelection = txtOutput.Selection; var solutionDir = System.IO.Path.GetDirectoryName(_applicationObject.Solution.FullName); System.IO.File.WriteAllText(solutionDir + "\\build_output.log", txtSelection.Text); } public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom) { if (buildEventConnected) { _buildEvents.OnBuildDone -= new _dispBuildEvents_OnBuildDoneEventHandler(BuildEvents_OnBuildDone); buildEventConnected = false; } }
That's it, on every build you'll have the output sent to the build_output.log
file in your solution's folder.