我正在编写一个要从 Visual Studio 中的预构建事件执行的批处理文件。
如何让它向 Visual Studio 错误列表输出错误、警告和消息?
很难搜索到这个,因为出现的大多数事情都是如何修复错误,而不是抛出错误!
我正在编写一个要从 Visual Studio 中的预构建事件执行的批处理文件。
如何让它向 Visual Studio 错误列表输出错误、警告和消息?
很难搜索到这个,因为出现的大多数事情都是如何修复错误,而不是抛出错误!
输出需要特殊格式:
<Filename> (<LineNumber>): Warning: <ErrorMessage>
除了警告,您还可以使用Error
空格也很重要!
你可以像这样创建它
echo %~f0 (!lineNo!^): Warning: Invalid target for production
为了提示错误位置,您应该添加或多或少准确的行号。
if /i "!TargetPath:~-3!"=="DLL" (
set "targetValid=1"
) ELSE (
call :GetLineNumber lineNo +1 {3D967145-10B6-44A0-96EF-91B6C6E2DD0E}
echo %~f0 (!lineNo!^): Warning: Invalid target '!TargetPath:~-3!' for production
)
....
:GetLineNumber returnVar add uniqueGUID
:::
:::
setlocal EnableDelayedExpansion
set "GetLineNumber.lineNo=0"
set /a "GetLineNumber.Add=%~2"
set "GetLineNumber.unique=%~3"
for /F "delims=:" %%L in ('findstr /n "!GetLineNumber.unique!" "%~f0"') do (
set /a "GetLineNumber.lineNo=%%L"
)
(
endlocal
set /a "%~1=%GetLineNumber.lineNo%" + %GetLineNumber.Add%
)
exit /b