Visual Studio的Vim错误格式

Kev*_*dge 31 vim errorformat visual-studio

我想将Vim的quickfix功能与Visual Studio的devenv构建过程或msbuild的输出一起使用.

我创建了一个名为build.bat的批处理文件,它执行devenv构建,如下所示:

devenv MySln.sln /Build Debug
Run Code Online (Sandbox Code Playgroud)

在vim我已经指出:make命令到该批处理文件:

:set makeprg=build.bat
Run Code Online (Sandbox Code Playgroud)

当我现在运行: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
Run Code Online (Sandbox Code Playgroud)

当然,我已经尝试过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 ==========
Run Code Online (Sandbox Code Playgroud)

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

使用msbuild makeprg将是:

:set makeprg=msbuild\ /nologo\ /v:q
Run Code Online (Sandbox Code Playgroud)

样本输出应该是:

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?)
Run Code Online (Sandbox Code Playgroud)

看起来这里棘手的部分可能在于路径相对于.csproj文件,而不是.sln文件,它是Vim中的当前目录,位于.csproj文件上方的一个目录中.

答案: 我想通了......

set errorformat=\ %#%f(%l\\\,%c):\ %m
Run Code Online (Sandbox Code Playgroud)

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

<GenerateFullPaths>True</GenerateFullPaths>
Run Code Online (Sandbox Code Playgroud)

Kev*_*dge 20

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
Run Code Online (Sandbox Code Playgroud)


Sim*_*han 8

从"问题"复制到"未答复"列表中删除

set errorformat=\ %#%f(%l\\\,%c):\ %m
Run Code Online (Sandbox Code Playgroud)

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

<GenerateFullPaths>True</GenerateFullPaths>
Run Code Online (Sandbox Code Playgroud)


idb*_*rii 5

我找到了一个更好的答案:用于:compiler使用内置efm设置。

" Microsoft C#
compiler cs
" Microsoft Visual C++
compiler msvc
" mono
compiler mcs
" gcc
compiler gcc
Run Code Online (Sandbox Code Playgroud)

注意:它还设置了默认的makeprg. 见 $VIMRUNTIME/compiler/