Visual Studio 的 Vim 错误格式
我想将 Vim 的快速修复功能与 Visual Studio 的 devenv 构建过程或 msbuild 的输出结合使用。
我创建了一个名为 build.bat 的批处理文件,它执行 devenv 构建,如下
devenv MySln.sln /Build Debug
所示: 在 vim 中,我将 :make 命令指向该批处理文件:
:set makeprg=build.bat
当我现在运行 :make 时,构建成功执行,但是错误不存在不会被解析出来。 因此,如果我运行 :cl 或 :cn 我最终会看到 devenv /Build 的所有输出。 我应该只看到错误。
我尝试了在网络上的各个站点上找到的许多不同的错误格式设置,但它们都没有正确解析出错误。 以下是我尝试过的一些:
set errorformat=%*\\d>%f(%l)\ :\ %t%[A-z]%#\ %m
set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
set errorformat=%f(%l,%c):\ error\ %n:\ %f
当然我也尝试过 Vim 的默认设置。
以下是 build.bat 的一些示例输出:
C:\TFS\KwB Projects\Thingy>devenv Thingy.sln /Build Debug
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
------ Build started: Project: Thingy, Configuration: Debug Any CPU ------
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Linq.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Thingy.exe /resource:obj\Debug\Thingy.g.resources /resource:obj\Debug\Thingy.Properties.Resources.resources /target:winexe App.xaml.cs Controller\FieldFactory.cs Controller\UserInfo.cs Data\ThingGatewaySqlDirect.cs Data\ThingListFetcher.cs Data\UserListFetcher.cs Gui\FieldList.xaml.cs Interfaces\IList.cs Interfaces\IListFetcher.cs Model\ComboBoxField.cs Model\ListValue.cs Model\ThingType.cs Interfaces\IThingGateway.cs Model\Field.cs Model\TextBoxField.cs Model\Thing.cs Gui\MainWindow.xaml.cs Gui\ThingWindow.xaml.cs Interfaces\IField.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs RequiredValidation.cs "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\FieldList.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\MainWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\ThingWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\App.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\GeneratedInternalTypeHelper.g.cs"
C:\TFS\KwB Projects\Thingy\Thingy\Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
Compile complete -- 1 errors, 0 warnings
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
更新: 看起来使用 msbuild 而不是 devenv 可能是正确的方法(根据 Jay 的评论)。
使用 msbuild makeprg 将是:
:set makeprg=msbuild\ /nologo\ /v:q
示例输出应该是:
Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
看起来这里棘手的部分可能在于路径是相对于 .csproj 文件,而不是相对于 .sln 文件,该文件是 Vim 中的当前目录并且位于一个.csproj 文件上方的目录。
答案: 我想通了...
set errorformat=\ %#%f(%l\\\,%c):\ %m
这将捕获 devenv /Build 和 msbuild 的输出。 然而,msbuild 有一个问题。 默认情况下,它的输出不包含完整路径。 要解决此问题,您必须将以下行添加到 csproj 文件的主 PropertyGroup 中:
<GenerateFullPaths>True</GenerateFullPaths>
I want to use Vim's quickfix features with the output from Visual Studio's devenv build process or msbuild.
I've created a batch file called build.bat which executes the devenv build like this:
devenv MySln.sln /Build Debug
In vim I've pointed the :make command to that batch file:
:set makeprg=build.bat
When I now run :make, the build executes successfully, however the errors don't get parsed out. So if I run :cl or :cn I just end up seeing all the output from devenv /Build. I should see only the errors.
I've tried a number of different errorformat settings that I've found on various sites around the net, but none of them have parsed out the errors correctly. Here's a few I've tried:
set errorformat=%*\\d>%f(%l)\ :\ %t%[A-z]%#\ %m
set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
set errorformat=%f(%l,%c):\ error\ %n:\ %f
And of course I've tried Vim's default.
Here's some example output from the build.bat:
C:\TFS\KwB Projects\Thingy>devenv Thingy.sln /Build Debug
Microsoft (R) Visual Studio Version 9.0.30729.1.
Copyright (C) Microsoft Corp. All rights reserved.
------ Build started: Project: Thingy, Configuration: Debug Any CPU ------
c:\WINDOWS\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.Linq.dll" /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll" /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\Thingy.exe /resource:obj\Debug\Thingy.g.resources /resource:obj\Debug\Thingy.Properties.Resources.resources /target:winexe App.xaml.cs Controller\FieldFactory.cs Controller\UserInfo.cs Data\ThingGatewaySqlDirect.cs Data\ThingListFetcher.cs Data\UserListFetcher.cs Gui\FieldList.xaml.cs Interfaces\IList.cs Interfaces\IListFetcher.cs Model\ComboBoxField.cs Model\ListValue.cs Model\ThingType.cs Interfaces\IThingGateway.cs Model\Field.cs Model\TextBoxField.cs Model\Thing.cs Gui\MainWindow.xaml.cs Gui\ThingWindow.xaml.cs Interfaces\IField.cs Properties\AssemblyInfo.cs Properties\Resources.Designer.cs Properties\Settings.Designer.cs RequiredValidation.cs "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\FieldList.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\MainWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\Gui\ThingWindow.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\App.g.cs" "C:\TFS\KwB Projects\Thingy\Thingy\obj\Debug\GeneratedInternalTypeHelper.g.cs"
C:\TFS\KwB Projects\Thingy\Thingy\Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
Compile complete -- 1 errors, 0 warnings
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
UPDATE:
It looks like using msbuild instead of devenv is probably the right way to go (as per Jay's comment).
Using msbuild the makeprg would be:
:set makeprg=msbuild\ /nologo\ /v:q
Sample output whould be:
Controller\FieldFactory.cs(14,19): error CS0246: The type or namespace name 'IFieldNothing' could not be found (are you missing a using directive or an assembly reference?)
It looks like the tricky part here may lie in the fact that the path is relative to the .csproj file, not the .sln file which is the current directory in Vim and lies one directory above the .csproj file.
ANSWER:
I figured it out...
set errorformat=\ %#%f(%l\\\,%c):\ %m
This will capture the output for both devenv /Build and msbuild.
However, msbuild has one catch. By default, it's output doesn't include full paths. To fix this you have to add the following line to your csproj file's main PropertyGroup:
<GenerateFullPaths>True</GenerateFullPaths>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
我找到了一个更好的答案:使用
:compiler
来使用内置的efm
设置。注意:它还设置默认的
makeprg
。 请参阅 $VIMRUNTIME/compiler/I found an even better answer: use
:compiler
to use built-inefm
settings.Note: It also sets the default
makeprg
. See $VIMRUNTIME/compiler/尝试运行 msbuild 而不是 devenv。 这将为构建的运行方式提供大量的动力。
打开 Visual Studio 命令提示符以设置路径。 然后执行
msbuild MySln.sln /Configuration:Debug
。请参阅
msbuild /?
获取帮助。Try running msbuild instead of devenv. This will open up a ton of power in how the build runs.
Open a Visual Studio Command Prompt to get your path set up. Then do
msbuild MySln.sln /Configuration:Debug
.See
msbuild /?
for help.复制问题以从“未回答”列表中删除
这将捕获
devenv /Build
和 msbuild 的输出。 然而,msbuild 有一个问题。 默认情况下,它的输出不包含完整路径。 要解决此问题,您必须将以下行添加到 csproj 文件的主 PropertyGroup 中:Copy from question to remove from 'unanswered' list
This will capture the output for both
devenv /Build
and msbuild. However, msbuild has one catch. By default, it's output doesn't include full paths. To fix this you have to add the following line to your csproj file's main PropertyGroup:我有一篇博文,详细介绍了在 Vim 中构建 C# 项目的所有细节,包括错误格式。 您可以在这里找到它: http://kevin-berridge.blogspot .com/2008/09/vim-c-compiling.html
简而言之,您需要以下内容:
I have a blog post which walks through all the details of getting C# projects building in Vim, including the error format. You can find it here: http://kevin-berridge.blogspot.com/2008/09/vim-c-compiling.html
In short you need the following:
我在 Visual Studio 中寻找编译 c++ 的错误格式时发现了这个问题。 上面的答案对我不起作用(我也不使用 MSBuild)。
我从 这个 Vim 提示 和
:help errorformat
中发现了这一点:这将为您提供如下所示的快速修复:(
突出显示错误)来自
I found this question when looking for errorformat for compiling c++ in Visual Studio. The above answers don't work for me (I'm not using MSBuild either).
I figured out this from this Vim Tip and
:help errorformat
:Which will give you a quickfix looking like this:
(with error highlighted) from
这些错误格式在 Visual studio 2009 v9.0.21022.8 专业版中均不起作用。 使用 cygwin,必须从 bash 调用 devenv,这使得设置 makeprg 有点棘手(拧紧批处理文件)。 当 devenv 分成多个进程并使用“1>”继续错误消息时,还必须调整我的错误格式 或“2>” 等:
我的 .bashrc 使用 cygpath 设置 MAKEPATH 环境变量以转换为 DOS 兼容路径:
如果您有 vim 6.x,则可以使用 :cw 比 clist 好得多(尝试在数百个警告中搜索错误,你就知道我的意思了)。 看着 vim 的调整让我想吐,但我已经在 vim 天堂了! 再见视觉工作室! 感谢您为调整 pydave +1 提供基础。
None of these errorformats worked in Visual studio 2009 v9.0.21022.8 professional edition. Using cygwin, had to call devenv from bash which made setting makeprg a little tricky (screw batch files). Also had to tweak my errorformat when devenv splits into multiple processes and proceeds error message with "1>" or "2>" etc:
My .bashrc sets the MAKEPATH environment variable using cygpath to convert to a DOS compatible path:
If you have vim 6.x you can use :cw which is SO much better than clist (try searching for errors among hundreds of warnings and you know what I mean). Looking at vim tweaks makes me want to vomit but I'm in vim heaven!!! Good bye visual studio! Thanks for the base to tweak pydave +1.
正如 Simon Buchan 提到的,您可以在项目中使用它来生成输出中的完整路径:
但是您可以通过添加
/property:GenerateFullPaths=true
到makeprg 而不是将上述内容添加到您的项目文件中。
As Simon Buchan mentioned you can use this in your project to generate the full paths in the output:
But you can make it more portable by adding
/property:GenerateFullPaths=true
to youmakeprg
instead of adding the above to your project files.