Tôi muốn sử dụng tính năng Quickfix của Vim với đầu ra từ quá trình xây dựng devenv của Visual Studio hoặc msbuild.Vim errorformat cho Visual Studio
tôi đã tạo ra một tập tin batch gọi build.bat mà thực thi devenv xây dựng như thế này:
devenv MySln.sln /Build Debug
Trong vim Tôi đã chĩa: thực hiện lệnh để tập tin batch:
:set makeprg=build.bat
Khi tôi chạy bây giờ: thực hiện, quá trình xây dựng thực thi thành công, tuy nhiên các lỗi không được phân tích cú pháp. Vì vậy, nếu tôi chạy: cl hoặc: cn Tôi chỉ cần nhìn thấy tất cả các đầu ra từ devenv/Build. Tôi sẽ chỉ thấy các lỗi.
Tôi đã thử một số cài đặt errorformat khác nhau mà tôi đã tìm thấy trên các trang web khác nhau trên mạng, nhưng không có cài đặt nào trong số đó đã phân tích cú pháp chính xác. Dưới đây là một số tôi đã thử:
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
Và dĩ nhiên tôi đã thử mặc định của Vim.
Dưới đây là một số ví dụ đầu ra từ 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: Dường như sử dụng msbuild thay vì devenv có lẽ là cách đúng đắn để đi (theo bình luận của Jay).
Sử dụng msbuild các makeprg sẽ là:
:set makeprg=msbuild\ /nologo\ /v:q
Mẫu đầu ra whould được:
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?)
Dường như phần khó hiểu ở đây có thể nằm trong thực tế là con đường là tương đối so với. Tệp csproj, không phải tệp .sln là thư mục hiện tại trong Vim và nằm một thư mục phía trên tệp .csproj.
ĐÁP: I figured it out ...
set errorformat=\ %#%f(%l\\\,%c):\ %m
này sẽ bắt đầu ra cho cả devenv/Xây dựng và msbuild. Tuy nhiên, msbuild có một cú đánh. Theo mặc định, đầu ra của nó không bao gồm đường dẫn đầy đủ. Để khắc phục điều này, bạn phải thêm dòng sau vào nhóm thuộc tính chính của tệp csproj:
<GenerateFullPaths>True</GenerateFullPaths>
Đối với những người trong chúng ta không sử dụng VS2k8, một số lượng lỗi sẽ được hữu ích. – Zathrus