我希望在构建日志中看到每个项目编译的开始和结束时间。有没有办法让 VS 实现这一点?
另一个选项是提高MSBuild的详细程度。
Tools -> Options -> Projects and Solutions -> Build and Run ->
将MSBuild 项目构建输出详细程度
设置为Normal
。 这将给您提供类似这样的输出:
------ Build started: MyProject, Configuration: Debug x86 ------
Build started 24/03/2014 08:46:18.
...
Build succeeded.
Time Elapsed 00:00:05.18
对于VC++构建,您可以启用构建时间。转到“工具”->“选项”->“项目和解决方案”->“VC++项目设置”,然后选择“构建计时”的选项。
Time
命令:TIME /T
如果不修改实际的项目文件(使用文本编辑器)来添加对MSBuild脚本目标的调用,则无法完成。
使用脚本文件的备选方案... 还包括项目构建所用时间。
在项目共享空间中创建VBS文件"GetTime.vbs" VBS代码...
dim out : Set out = WScript.StdOut
Set objShell = WScript.CreateObject("WScript.Shell")
dim regDir: regDir="HKEY_CURRENT_USER\Software\VB and VBA Program Settings\GetTime.vbs\"
dim msg: msg=""
dim s: s=""
dim e: e=""
dim st:st=""
' param s is start flag keyed to the application being built.
if wscript.arguments.named.exists("s") then
s = wscript.arguments.named("s")
objShell.RegWrite regdir & s,now
end if
if wscript.arguments.named.exists("e") then
e = wscript.arguments.named("e")
st = cdate(objShell.RegRead(regDir & e))
end if
if e<>"" and isdate(st) then
out.writeline e & " ENDED " & now & " ELAPSED " & datediff("s",cdate(st),now) & " seconds"
elseif e<>"" then
out.writeline e & " ENDED " & now
elseif s<>"" then
out.writeline s & " STARTED " & now
else
out.writeline now
end if
修改您的构建事件,将此脚本作为参数包含进去...
(您需要根据输出目录更改目录路径,以便从多个项目中找到文件)预构建事件命令行...
cscript "../../../../Scorecards/gettime.vbs" //B /s:"$(ProjectName)"
构建后事件命令行
cscript "../../../../Scorecards/gettime.vbs" //B /e:"$(ProjectName)"
多个项目的示例输出...
2> OPResources STARTED 7/9/2020 12:59:04 PM
2> ...
2> OPResources ENDED 7/9/2020 12:59:05 PM ELAPSED 1 seconds
1> OPLib_WF STARTED 7/9/2020 12:59:04 PM
1> ...
1> OPLib_WF ENDED 7/9/2020 12:59:05 PM ELAPSED 1 seconds
4>------ Rebuild All started: Project: OPLib, Configuration: Debug Any CPU ------
4> OPLib STARTED 7/9/2020 12:59:06 PM
4> ...
4> OPLib ENDED 7/9/2020 12:59:10 PM ELAPSED 4 seconds
5>------ Rebuild All started: Project: PerfUpdater, Configuration: Debug Any CPU ------
6>------ Rebuild All started: Project: Scorecards2, Configuration: Debug Any CPU ------
7>------ Rebuild All started: Project: SingleSignOn, Configuration: Debug Any CPU ------
7> SingleSignOn STARTED 7/9/2020 12:59:10 PM
7> ...
7> SingleSignOn ENDED 7/9/2020 12:59:12 PM ELAPSED 2 seconds