Translate

Saturday 29 August 2015

Visual Studio Code (Code) 2015 - OmniSharp and some tips

The lightweight VS Code has its pitfalls.

For instance, as I made some rapid calculations on the disk space available for VS 2015 Community Edition to download and install (as it says that a minimum of 6 or 4 GB of hard disk space is required across all available drives, I had made a decision - VS Code is what I would use instead.

VS Code requires only 58 MB of space. Not even in our wildest imagination could we ever have thought of downloading a fully functional Visual Studio without having to calculate the internet speed, the disk space and whether any additional service packs and third-party libraries or add-on components had to be additionally installed.

But, as I said at the beginning, VS Code 2015 has its hidden pain areas. It requires node.js and DNX and DNVM (Dot Net Execution and Dot Net Version Manager), though why you required the additional manager is quite a valid question because 'version redirect' and the config changes were doing the same but the new vision to accommodate Mac and make Visual Studio accessible across multiple platforms is possibly the reason.

What this means is that you can switch the 'use' of the current runtime, view or create aliases and manage all the installed versions of the CLR in your machine.


The Execution Engine(DNX)

DNX is the execution environment as Code does not have any executing environment of its own but relies on Node.js or Mono. There is a misconception that I read in one of those 'code...' dot com that ASP.Net 5 now allows you to develop ASP.Net apps using Notepad without having to open Visual Studio - not so. The article probably missed out in mentioning that Roslyn needs to be installed for Ctrl-F5 to work from Notepad.

The hidden problem is because Code is lightweight, it relies on intellisense to be provided as a plugin from OmniSharp

and OmniSharp makes a big deal about being in the same drive as the Node.js installed and this is not documented anywhere! Despite a fix to the omnisharp.cmd file that has been updated in the Git !

To start off, once you have downloaded VS Code, download Yeoman, a scaffolding tool (since Code does not come with templates as in regular Visual Studio versions) to generate complete project related works ! Download the .zip file and extract the downloaded "yo.master".

Next step is to download Node.js, make sure to download the latest version from here. Once downloaded and installed (make sure in the same drive as Yeoman and Code), open a command prompt and type 'npm install -g generator-aspnet'.

This will install the generator that will allow you to use the 'Yo' tool to generate specific projects, for instance,

'yo aspnet'

.


and you are ready to create your first project with Code.

Select the type of application, give it a name and wait for the project directory etc to be created. Once done, navigate to the newly created folder.


execute the command, as shown in the yo command screen, "dnu restore". 

This will download all nuget packages and set the project.json for the newly created app.

Once done, just type "code ." to open the application !


The new 'References' shows how many references to an object, variable or member exists in code plus a new "Unnecessary using directive" helps.

To run, simply type "dnx . web" to start the server in Windows at the command prompt: 


or navigate to 'hosting.ini' (this file may vary as per the type of application) and click the link to open the web app in your default browser. For Mac, you may need to use "dnx . kestrel".



Any changes to code means restart the server.


and the web site is up at localhost.


Awesome, isn't it? :)

No comments: