title: Vim errorformat for Visual Studio
body: <p>I want to use Vim's quickfix features with the output from Visual Studio's devenv build process or msbuild.</p>
  
  <p>I've created a batch file called build.bat which executes the devenv build like this:</p>
  
  <pre><code>devenv MySln.sln /Build Debug
  </code></pre>
  
  <p>In vim I've pointed the :make command to that batch file:</p>
  
  <pre><code>:set makeprg=build.bat
  </code></pre>
  
  <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>set errorformat=%*\\d&gt;%f(%l)\ :\ %t%[A-z]%#\ %m
  set errorformat=\ %#%f(%l)\ :\ %#%t%[A-z]%#\ %m
  set errorformat=%f(%l,%c):\ error\ %n:\ %f
  </code></pre>
  
  <p>And of course I've tried Vim's default.</p>
  
  <p>Here's some example output from the build.bat:</p>
  
  <pre><code>C:\TFS\KwB Projects\Thingy&gt;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 ==========
  </code></pre>
  
  <p><strong>UPDATE:</strong>
  It looks like using msbuild instead of devenv is probably the right way to go (as per Jay's comment).</p>
  
  <p>Using msbuild the makeprg would be:</p>
  
  <pre><code>:set makeprg=msbuild\ /nologo\ /v:q
  </code></pre>
  
  <p>Sample output whould be:</p>
  
  <pre><code>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?)
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>ANSWER:</strong>
  I figured it out...</p>
  
  <pre><code>set errorformat=\ %#%f(%l\\\,%c):\ %m
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>&lt;GenerateFullPaths&gt;True&lt;/GenerateFullPaths&gt;
  </code></pre>