我使用 MSBuild 构建项目文件。 默认情况下,MSBuild 仅会输出编译结果,但是我需要检查执行了哪些命令。
我能查看实际执行的构建命令吗?我想要检查在 csc
命令中使用的编译器选项和引用。
我使用 MSBuild 构建项目文件。 默认情况下,MSBuild 仅会输出编译结果,但是我需要检查执行了哪些命令。
我能查看实际执行的构建命令吗?我想要检查在 csc
命令中使用的编译器选项和引用。
您可以设置Visual Studio构建的输出为详细模式。 进入菜单栏Tools -> Options -> Projects and Solutions -> Build and Run。 更改MSBuild项目构建输出详细程度选项,通常从默认的Minimal改为Normal、Detailed或Diagnostic。
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\CL.exe /c /IC:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\src /IC:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\..\pdelib\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\core\include /IC:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\..\pdelib\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\step\include /IC:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\..\pdelib\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\iges\include /ZI /JMC /nologo /W3 /WX- /diagnostics:column /sdl /Od /D _DEBUG /D _CONSOLE /D _UNICODE /D UNICODE /Gm- /EHsc /RTC1 /MD /GS /fp:precise /permissive- /Zc:wchar_t /Zc:forScope /Zc:inline /Fo"x64\Debug\\" /Fd"x64\Debug\vc142.pdb" /external:W3 /Gd /TP /FC /errorReport:queue /wd4996 /wd4703 ..\..\src\test_pdelib.cpp ..\..\src\test_step.cpp
test_pdelib.cpp
test_step.cpp
Generating Code...
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.29.30133\bin\HostX86\x64\link.exe /ERRORREPORT:QUEUE /OUT:"C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\x64\Debug\test_pdelib.exe" /INCREMENTAL /ILK:"x64\Debug\test_pdelib.ilk" /NOLOGO /LIBPATH:C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\core\lib /LIBPATH:C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\step\lib /LIBPATH:C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\..\..\..\pdelib_v7.8.3\v7.8.3\msdos_mcn\vc140_64_md\iges\lib libgdx.lib libpdx.lib libstep.lib libiges.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'" /manifest:embed /DEBUG /PDB:"C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\x64\Debug\test_pdelib.pdb" /SUBSYSTEM:CONSOLE /TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\x64\Debug\test_pdelib.lib" /MACHINE:X64 x64\Debug\test_pdelib.obj
x64\Debug\test_step.obj
test_pdelib.vcxproj -> C:\Users\Administrator\Desktop\pdelib\test_pdelib\v7.8.3\VSE2019.16.11.4\x64\Debug\test_pdelib.exe
-fl
会同时写入日志。默认名称为 msbuild.log :-) 名称/位置可以使用 -flp
进行更改。您还可以为日志文件设置不同于控制台的详细程度,例如 -flp:LogFile=msbuild-detailed.log;Verbosity=diagnostic
。 - Fizz-consoleLoggerParameters:ShowCommandLine
aka -clp:ShowCommandLine
。根据VS2019的说明文档:
默认控制台记录器的详细程度为正常,并包含摘要。
(Summary
也是一种输出类型,可以打印或不打印,与ShowCommandLine
处于同一类别)
结果证明(在VS 2019下进行的实验见下文),最小的-v:m
详细程度会抑制工具的stdout输出,除了msbuild标语之外,并抑制cmd回显。
-clp:ShowCommandLine
将回显添加回-v:m
中。这实际上打印出的噪音比正常的msbuild详细级别要少得多,特别是来自msbuild本身的噪音。不幸的是,你不能将-clp:ShowCommandLine
与-v:q
组合使用,以抑制工具的横幅而获得cmd回显;-v:q
仍将打印横幅,但取消-clp:ShowCommandLine
的效果。
我使用了微软提供的最小的 msbuild C# 示例 链接,从 x64 dev cmd 提示符中运行测试:
M:\tests\cs-build>msbuild helloworld.csproj -t:Build
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 1/16/2022 9:42:20 AM.
Project "M:\tests\cs-build\helloworld.csproj" on node 1 (Build target(s)).
Build:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current
\Bin\Roslyn\csc.exe /out:Helloworld.exe Helloworld.cs
CompilerServer: tool - using command line tool by design 'C:\Program Files (x
86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Roslyn\csc.exe
' - 753a030a-3ca4-43b9-9e98-18d923493186
Done Building Project "M:\tests\cs-build\helloworld.csproj" (Build target(s)).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.80
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<Compile Include="helloworld.cs" />
</ItemGroup>
<Target Name="Build">
<Csc Sources="@(Compile)"/>
</Target>
</Project>
M:\tests\cs-build>msbuild helloworld.csproj -t:Build -v:m
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
M:\tests\cs-build>
-v:m -clp:ShowCommandLine
来获得cmd echo,但除了错误和msbuild横幅之外,没有其他的msbuild chatter。M:\tests\cs-build>msbuild helloworld.csproj -t:Build -v:m -clp:ShowCommandLine
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current
\Bin\Roslyn\csc.exe /out:Helloworld.exe Helloworld.cs
-clp:ShowCommandLine
与-v:q
结合使用,以抑制横幅但获取命令行回显; -v:q
仍会打印横幅,但取消-clp:ShowCommandLine
的效果。M:\tests\cs-build>msbuild helloworld.csproj -t:Build -v:q -clp:ShowCommandLine
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
M:\tests\cs-build>
-nologo
单独抑制msbuild横幅,因此-v:m -clp:ShowCommandLine -nologo
是有效的组合。M:\tests\cs-build>msbuild helloworld.csproj -t:Build -v:m -nologo -clp:ShowCommandLine
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current
\Bin\Roslyn\csc.exe /out:Helloworld.exe Helloworld.cs
M:\tests\cs-build>
M:\tests\cpp-build>msbuild myproject.vcxproj /p:configuration=debug
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
Build started 1/16/2022 10:05:01 AM.
Project "M:\tests\cpp-build\myproject.vcxproj" on node 1 (default targets).
InitializeBuildStatus:
Touching "debug\myproject.tlog\unsuccessfulbuild".
ClCompile:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\1
4.29.30133\bin\HostX86\x86\CL.exe /c /Zi /nologo /W1 /WX- /diagnostics:column
/O2 /Oy- /Gm- /EHsc /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Zc:inline
/Fo"debug\\" /Fd"debug\vc142.pdb" /external:W1 /Gd /TP /analyze- /FC /errorRe
port:queue main.cpp
main.cpp
Link:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\1
4.29.30133\bin\HostX86\x86\link.exe /ERRORREPORT:QUEUE /OUT:"M:\tests\cpp-bui
ld\debug\myproject.exe" /NOLOGO kernel32.lib user32.lib gdi32.lib winspool.li
b comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc3
2.lib odbccp32.lib /MANIFEST /MANIFESTUAC:"level='asInvoker' uiAccess='false'
" /manifest:embed /DEBUG:FULL /PDB:"M:\tests\cpp-build\debug\myproject.pdb" /
TLBID:1 /DYNAMICBASE /NXCOMPAT /IMPLIB:"M:\tests\cpp-build\debug\myproject.li
b" /MACHINE:X86 /SAFESEH debug\main.obj
myproject.vcxproj -> M:\tests\cpp-build\debug\myproject.exe
FinalizeBuildStatus:
Deleting file "debug\myproject.tlog\unsuccessfulbuild".
Touching "debug\myproject.tlog\myproject.lastbuildstate".
Done Building Project "M:\tests\cpp-build\myproject.vcxproj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:02.32
我不会在这里粘贴那个.vcxproj
文件,因为它相当长。
这个相当冗长的输出(包括cmd命令行)肯定不是我从典型的cmake项目生成的这样的文件所经历的体验,尽管经过一些测试后,后者的cmake默认使用...msbuild默认的详细程度,因此包括cmd echo。我不会在这里粘贴通过cmake生成的vcxproj构建的(更长的)输出,但您可以在https://pastebin.com/WQtbYeDE上看到它。那是为前面的MS C++示例制作的最小CMakeLists.txt。
cmake_minimum_required(VERSION 3.10)
# set the project name
project(Tutorial)
# add the executable
add_executable(Tutorial main.cpp)
.sln
还是直接将由CMake生成的.vcxproj
进行msbuild构建,在冗长度上没有区别。
msbuild
默认会打印所有的csc
命令。 - user202729