Edit ASP.NET Web API project with Visual Studio Code



I have been using Visual Studio Code (VSC) in web development for a while and I love its speed, expandability and general design. Today I got an idea, which felt like a lightning strike (not literally, but figuratively). Could I use VSC in my big .NET projects? Lets find out!

I'm currently working with a quite big Web API project. Solution contains multiple projects, Nuget packages, automated tests and so on. I use Postman to test app, so I don't need a Visual Studio to test app. I'm also using IIS to host app, so I don't need IIS Express to run app. Only thing I will lack in VSC is a debugger. That is of course a huge thing, but maybe I can use Visual Studio to debug app and VSC in main coding?

Setup for test run

VSC use PATH environment variable to resolve msbuild path. So first I need add msbuild path into PATH variable. I have regular Windows machine so correct path is C:\Windows\Microsoft.NET\Framework\v4.0.30319

MSBuild in task.json


Then I launch VSC and open project folder. Cool, it took only few seconds to load whole folder. Compared to Visual Studios 15 seconds that is fast. Then press Ctrl+Shift+B to build and vola! Oh, no vola. No task runner configured. Well lets configure one then. Comment TypeScript out because I'm not interested from that now... and uncomment msbuild. Ctrl+Shift+B again to build. Lots of build messages appears into console.

Restoring Nuget packages...
All packages listed in packages.config are already installed.
ResolveAssemblyReferences:..

and vola! Well almost. Time elapsed 17 seconds and 4 error(s).

I have four times error "MSB4019". Put that error code on Stack Overflow and found out following:
It is due to Vs2012 adding in csproj file this part:
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
You can safely remove that part and your solution will build.
Well lets get rid of that nuisance and try again. Note: Its easy to edit project files by just ctrl+clicking the path given in error message. Property group is found from main project. Let's remove it and try again.

    0 Error(s)
Time Elapsed 00:00:17.43

Cheers! I'm up and running.

Well let's test few things next:
I make a little change into code, build, test with Postman and everything seems to work. This seems to go too well. Next let's try to make a little bit bigger change which includes call into another project.

error BC30002: Type 'Customer' is not defined.

Yes I need to add reference, but there is no way to add it. I have to do it manually or use Visual Studio to add it for me. I'm also lacking import/using statement for projects namespace and VSC don't know how to do that. That is also manual labor.

Summary

So what are the benefits and drawbacks of using VSC to edit WebAPI projects.
VSC use about 200 MB of memory with this project.
Visual Studio use 650 MB.

VSC builds project in 17 seconds.
Visual Studio build time depends on size of changes. Visual Studio can optimize build process much more than  msbuild does so it's almost every time faster than VSC.

Visual Studio supports ReSharper, but there is no confirmed timeline for VSC ReSharper plugin and VSC doesn't support nunit/mstest out of the box (those would be a very cool plugins btw.).

VSC don't know how to add references or using/import statements, so for that Visual Studio is still needed. It seems that VSC is suitable for small code editing, but Visual Studio is still king of the hill in WebAPI/MVC projects.

However VSC is good tool to edit project files, make small changes into code and to simply build whole solution quickly.


The best way to predict the future is to implement it.

2 kommenttia:

  1. This is a great post. I like this topic.This site has lots of advantage. It helps me in many ways.Thanks for posting this again.
    Web development Company in India Company | Web development Company Bangalore
    Web Development Company in Bangalore | Responsive Web development

    VastaaPoista
  2. As a website design company .Web India Market offer a full-circle approach in responsive website designing and web development services. Our website designing services covers Strategic Planning, Business Intelligence, Creative Application Development, Digital Marketing, SEO services and e-commerce solutions.

    VastaaPoista