我想将 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>
最佳答案
我有一篇博客文章,详细介绍了在 Vim 中构建 C# 项目的所有细节,包括错误格式。您可以在这里找到它:http://kevin-berridge.blogspot.com/2008/09/vim-c-compiling.html
简而言之,您需要以下内容:
:set errorformat=\ %#%f(%l\\\,%c):\ %m
:set makeprg=msbuild\ /nologo\ /v:q\ /property:GenerateFullPaths=true
关于visual-studio - Visual Studio 的 Vim 错误格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/101270/