有没有办法通过命令行将Build命令输出到文本文件?
解释:我们使用多个源代码分支,并在每个分支上拥有100多个项目的大型解决方案。我需要编写构建脚本来从命令行构建这些解决方案。然后,我们可以在分支机构上定制解决方案,以便仅为团队正在进行的项目提供项目引用。这应该会大大增加解决方案加载时间并减轻开发人员和我的挫败感,我希望:)
我将继续寻找并考虑使用C#和VS提供的API。我们正在使用2012年更新1.
答案 0 :(得分:5)
这是Visual Studio插件项目的理想选择。
在 Connect.cs 文件中,添加以下字段:
private BuildEvents _buildEvents;
private Events _events;
private bool buildEventConnected = false;
并相应地添加/修改这些方法:
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;
}
}
就是这样,在每次构建时,您都会将输出发送到解决方案文件夹中的build_output.log
文件。
答案 1 :(得分:0)
快速方法是执行“清理解决方案”,以便您可以在构建日志中看到相反的顺序。