简体   繁体   English

Visual Studio的Vim错误格式

[英]Vim errorformat for Visual Studio

I want to use Vim's quickfix features with the output from Visual Studio's devenv build process or msbuild. 我想将Vim的quickfix功能与Visual Studio的devenv构建过程或msbuild的输出一起使用。

I've created a batch file called build.bat which executes the devenv build like this: 我创建了一个名为build.bat的批处理文件,它执行devenv构建,如下所示:

devenv MySln.sln /Build Debug

In vim I've pointed the :make command to that batch file: 在vim我已经指出:make命令到该批处理文件:

:set makeprg=build.bat

When I now run :make, the build executes successfully, however the errors don't get parsed out. 当我现在运行:make时,构建执行成功,但是错误不会被解析出来。 So if I run :cl or :cn I just end up seeing all the output from devenv /Build. 所以如果我运行:cl或:cn我最终会看到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. 当然,我已经尝试过Vim的默认设置。

Here's some example output from the build.bat: 以下是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). 更新:看起来使用msbuild而不是devenv可能是正确的方法(根据Jay的评论)。

Using msbuild the makeprg would be: 使用msbuild makeprg将是:

: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. 看起来这里棘手的部分可能在于路径相对于.csproj文件,而不是.sln文件,它是Vim中的当前目录,位于.csproj文件上方的一个目录中。

ANSWER: I figured it out... 答案:我想通了......

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

This will capture the output for both devenv /Build and msbuild. 这将捕获devenv / Build和msbuild的输出。 However, msbuild has one catch. 但是,msbuild有一个问题。 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: 要解决此问题,您必须将以下行添加到csproj文件的主PropertyGroup:

<GenerateFullPaths>True</GenerateFullPaths>

I have a blog post which walks through all the details of getting C# projects building in Vim, including the error format. 我有一篇博文,介绍了在Vim中构建C#项目的所有细节,包括错误格式。 You can find it here: http://kevin-berridge.blogspot.com/2008/09/vim-c-compiling.html 你可以在这里找到它: 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

Copy from question to remove from 'unanswered' list 从“问题”复制到“未答复”列表中删除

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

This will capture the output for both devenv /Build and msbuild. 这将捕获devenv /Build和msbuild的输出。 However, msbuild has one catch. 但是,msbuild有一个问题。 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: 要解决此问题,您必须将以下行添加到csproj文件的主PropertyGroup:

<GenerateFullPaths>True</GenerateFullPaths>

I found an even better answer: use :compiler to use built-in efm settings. 我找到了一个更好的答案:使用:compiler来使用内置的efm设置。

" Microsoft C#
compiler cs
" Microsoft Visual C++
compiler msvc
" mono
compiler mcs
" gcc
compiler gcc

Note: It also sets the default makeprg . 注意:它还设置默认的makeprg See $VIMRUNTIME/compiler/ 请参阅$ VIMRUNTIME / compiler /

Try running msbuild instead of devenv. 尝试运行msbuild而不是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. 打开Visual Studio命令提示符以设置路径。 Then do msbuild MySln.sln /Configuration:Debug . 然后做msbuild MySln.sln /Configuration:Debug

See msbuild /? msbuild /? for help. 求助。

I found this question when looking for errorformat for compiling c++ in Visual Studio. 在查找用于在Visual Studio中编译c ++的errorformat时,我发现了这个问题。 The above answers don't work for me (I'm not using MSBuild either). 以上答案对我不起作用(我也没有使用MSBuild)。

I figured out this from this Vim Tip and :help errorformat : 我从这个Vim提示中找到了这个并且:help errorformat

" filename(line) : error|warning|fatal error C0000: message
set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %[A-Z\ ]%#%n:\ %m

Which will give you a quickfix looking like this: 这将为您提供如下所示的quickfix:

stats.cpp|604 error 2039| 'getMedian' : is not a member of 'Stats'

(with error highlighted) from (突出显示错误)来自

c:\p4\main\stats.cpp(604) : error C2039: 'getMedian' : is not a member of 'Stats'

As Simon Buchan mentioned you can use this in your project to generate the full paths in the output: 正如Simon Buchan所提到的,您可以在项目中使用它来生成输出中的完整路径:

<GenerateFullPaths>True</GenerateFullPaths>

But you can make it more portable by adding /property:GenerateFullPaths=true to you makeprg instead of adding the above to your project files. 但是你可以通过添加/property:GenerateFullPaths=true来使它更具可移植性/property:GenerateFullPaths=truemakeprg而不是将上面的内容添加到项目文件中。

:set makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true\

None of these errorformats worked in Visual studio 2009 v9.0.21022.8 professional edition. 这些错误格式都不适用于Visual Studio 2009 v9.0.21022.8专业版。 Using cygwin, had to call devenv from bash which made setting makeprg a little tricky (screw batch files). 使用cygwin,不得不从bash调用devenv,这使得设置makeprg有点棘手(螺旋批处理文件)。 Also had to tweak my errorformat when devenv splits into multiple processes and proceeds error message with "1>" or "2>" etc: 当devenv拆分成多个进程并继续使用“1>”或“2>”等错误消息时,还必须调整我的errorformat:

set autowrite
"2>c:\cygwin\home\user\proj/blah.cpp(1657) : error C2065: 'blah' : undeclared identifier

set errorformat=%.%#>\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %[A-Z\ ]%#%n:\ %m
let prg="devenv"
let makepath=$MAKEPATH
let &makeprg='cmd /c "'.prg.' '.makepath.'"'

My .bashrc sets the MAKEPATH environment variable using cygpath to convert to a DOS compatible path: 我的.bashrc使用cygpath设置MAKEPATH环境变量以转换为DOS兼容路径:

export MAKEPATH="$(cygpath -d "proj/VC9/some.sln") /build \"Debug\""

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). 如果你有vim 6.x你可以使用:cw比clist好得多(尝试在数百个警告中搜索错误,你知道我的意思)。 Looking at vim tweaks makes me want to vomit but I'm in vim heaven!!! 看着vim调整让我想呕吐但是我在vim天堂! Good bye visual studio! 再见视觉工作室! Thanks for the base to tweak pydave +1. 感谢基地调整pydave +1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM