Visual Studio 的 Vim 错误格式 [英] Vim errorformat for Visual Studio

查看:24
本文介绍了Visual Studio 的 Vim 错误格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Visual Studio 的 devenv 构建过程或 msbuild 的输出中使用 Vim 的快速修复功能.

I want to use Vim's quickfix features with the output from Visual Studio's devenv build process or msbuild.

我创建了一个名为 build.bat 的批处理文件,它会像这样执行 devenv 构建:

I've created a batch file called build.bat which executes the devenv build like this:

devenv MySln.sln /Build Debug

在 vim 中,我已将 :make 命令指向该批处理文件:

In vim I've pointed the :make command to that batch file:

:set makeprg=build.bat

当我现在运行 :make 时,构建成功执行,但是错误没有被解析出来.因此,如果我运行 :cl 或 :cn ,我最终会看到 devenv/Build 的所有输出.我应该只看到错误.

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

当然我也试过 Vim 的默认设置.

And of course I've tried Vim's default.

以下是 build.bat 的一些示例输出:

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 ==========

更新:看起来使用 msbuild 而不是 devenv 可能是正确的方法(根据 Jay 的评论).

UPDATE: It looks like using msbuild instead of devenv is probably the right way to go (as per Jay's comment).

使用 msbuild makeprg 将是:

Using msbuild the makeprg would be:

: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 文件上方的一个目录.

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.

答案:我想通了...

set errorformat=\ %#%f(%l\\\,%c):\ %m

这将捕获 devenv/Build 和 msbuild 的输出.但是,msbuild 有一个问题.默认情况下,它的输出不包括完整路径.要解决此问题,您必须将以下行添加到您的 csproj 文件的主 PropertyGroup:

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>

推荐答案

我有一篇博文介绍了在 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:

:set errorformat=\ %#%f(%l\\\,%c):\ %m
:set makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true

这篇关于Visual Studio 的 Vim 错误格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆