简体   繁体   中英

Output Build Order of Visual Studio solution to a text file

Is there a way to output the Build order to a text file via command line?

To explain: We use multiple branches of source and have large solutions of 100+ projects on each branch. I need to write build scripts to build these solutions from command line. We can then tailor the solutions on the branches to only have project references for the projects that team are working on. This should greatly increase solution load time and ease the frustration of the Developers and me, I hope :)

I'm going to keep looking and maybe look at using C# and the APIs provided with VS. We are using 2012 update 1.

This is a good candidate for a Visual Studio Plugin project.

  1. Create a new Visual Studio Add-in project.
  2. 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#):

在此处输入图片说明

  1. In the Connect.cs file, add the following fields:

     private BuildEvents _buildEvents; private Events _events; private bool buildEventConnected = false; 
  2. 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.

快速的方法是执行“清理解决方案”,以便您可以在构建日志中看到倒序的顺序。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM