Showing posts with label Visual Studio 2015. Show all posts
Showing posts with label Visual Studio 2015. Show all posts

Tuesday, December 13, 2016

Creating an AngularJS project in Visual Studio

If you want to create an AngularJS project in Visual Studio, you can use an IDE such as Visual Studio 2015 to do this.


  1. Create an empty ASP.NET Web Project
  2. Right click and then add New items
  3. You then have options to add the following:
    • AngularJS Controller
    • AngularJS Controller using $scope
    • AngularJS Directive
    • AngularJS Factory
    • AngularJS Module
  4. For a basic AngularJS application, you can add the following:
    • AngularJS Module
    • AngularJS Controller
  5. That is all there is to it!





Saturday, October 1, 2016

Running Code Coverage for Unit Tests in Visual Studio 2015

If you want to run Code Coverage for your Unit Tests, unfortunately, you will need to use Visual Studio 2015 Enterprise Edition.  Visual Studio 2015 Professional Edition still does not offer this crucial feature for most .NET Developers.

In any case, once you run the Unit Tests for your application from within Test Explorer, you can click on the "Run.." link to pull down the drop down menu options:


From there, you can select the option for "Analyze Code Coverage for All Tests", which will then present you with a "Code Coverage Results" pane:


Within the "Code Coverage Results" pane, you can further drill down into your individual namespaces and classes to determine how well your Unit Tests are covering your code!


Friday, September 30, 2016

Expand or Collapse Regions in Visual Studio 2015

I frequently work with regions throughout my C# code, so I usually need to expand or collapse all regions in my code especially when I am refactoring code.

Therefore, I wanted to see if there was an easy way to accomplish this within Visual Studio.

Well, by default, Visual Studio uses the Edit-->Outlining menu to control the expanding and collapsing of regions:


However, there are some Quick Launch commands also available to you specifically while working with Regions!

These Quick Launch commands come to you courtesy of the Productivity Power Tools 2015: https://visualstudiogallery.msdn.microsoft.com/34ebc6a2-2777-421d-8914-e29c1dfa7f5d

Installing this extension adds Quick Launch items for "CollapseRegions" and "ExpandRegions":



In case you are not already aware, the Quick Launch menu appears in the top right hand corner of Visual Studio and allows you to search for various commands available to Visual Studio:



Wednesday, September 21, 2016

Clear Recent File and Clear Recent Project List returns to Productivity Power Tools!

With the initial release of the Productivity Power Tools for Visual Studio 2015, the ability to use the commands for "Clear Recent File List" and "Clear Recent Project List" were unfortunately removed and required the usage of a PowerShell script to remove these values instead.

Thankfully, however, these 2 commands have returned to the Productivity Power Tools!

Now, with the most recent release of the Productivity Power Tools, you can once again use these commands directly from the Visual Studio IDE!

You can download the latest version of the Productivity Power Tools from here: https://visualstudiogallery.msdn.microsoft.com/34ebc6a2-2777-421d-8914-e29c1dfa7f5d

Tuesday, September 20, 2016

Differentiating between Project and Assembly References in Visual Studio

I was recently working on a project whereby I was encountering failed builds when the code was pushed up to our continuous integration server, but the build was successful when building on my local machine.

It took me a long time to try and figure out the root cause of this problem, but as it turned out, it had to deal with Project vs. Assembly References!

Unfortunately, in Visual Studio, as soon as you add a Project Reference to your Project, there is no EASY way to determine if a particular reference is a Project or an Assembly Reference!

The best way to try and check if you have a Project Reference is to right click on the References icon and select "Add Reference":


Then, once you have the dialog open, you can "guess" which projects are project references by looking at the checkboxes next to the corresponding project names.

As you can tell, this is a VERY, VERY tedious and error prone method of verifying and validating references in your project and across your solution.

Therefore, if you are like me and would prefer to have different icons for project references vs. assembly references in the Visual Studio IDE, you should definitely vote for this UserVoice item: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/4747824-different-icon-for-project-reference-and-assembly

Wednesday, September 14, 2016

Configuring Enterprise Library for Visual Studio 2015

If you are using Visual Studio 2015 for your development, you may encounter a problem with downloading NuGet packages while running the install-packages.ps1 PowerShell script that comes with the Microsoft Enterprise Library 6 download (https://www.microsoft.com/en-us/download/details.aspx?id=38789).

Well, the reason this occurs is because Microsoft Enterprise Library 6.0 still ships with v. 2.0 of NuGet.exe!

Therefore, when it attempts to connect to the NuGet server, it inevitably fails!

So how do you resolve this issue?

First of all, go ahead and download the latest version of NuGet.exe from the NuGet distribution site: https://dist.nuget.org/index.html

Then, you need to place the latest version of the NuGet.exe executable in the .nuget folder that was originally created when you ran the install-packages.ps1 PowerShell script.

Now, when you re-run the PowerShell script, it should successfully download the NuGet packages!


Saturday, September 10, 2016

Connecting to Team Foundation Server/Visual Studio Online using Visual Studio

As a consultant, I often end up working with teams which have not used Team Foundation Server or Visual Studio Online before and therefore end up training them on how to connect to TFS/VSO using Visual Studio.

Since I do this often enough from project to project, I thought I would finally write a blog on how to do this!

First of all, Microsoft has already written 2 articles on just how to do this:

Connect to Visual Studio Team Services from Eclipse, Xcode, Visual Studio, and morehttps://www.visualstudio.com/en-us/docs/setup-admin/team-services/connect-to-visual-studio-team-services

Connect to team projectshttps://www.visualstudio.com/docs/connect/connect-team-projects#connect-from-visual-studio-or-team-explorer

This article also addresses how to connect using Visual Studio 2013, but this still applies to Visual Studio 2015: https://binary-stuff.com/post/connecting-visual-studio-to-vso

One of the easiest methods the above article does not mention is connection from the Team menu!






From there, all the steps remain the same!  That is really all there is to it!

Thursday, September 1, 2016

Setting up Code Coverage Analysis in TeamCity

If you are using Visual Studio 2015 Professional Edition, unfortunately, you are out of luck when it comes to getting Code Coverage of your Unit Tests since this is only available in Visual Studio Enterprise edition (https://www.visualstudio.com/en-us/products/compare-visual-studio-2015-products-vs.aspx)

However, Jetbrains TeamCity has provided a solution for those development teams lacking licenses to Visual Studio 2015 Enterprise Edition in the form of dotCover!

dotCover is bundled for FREE with Jetbrains TeamCity and can be used to perform Code Coverage Analysis of your Unit Tests.

For information on how to set up dotCover to run Code Coverage for your Unit Tests, you can check out this article: https://confluence.jetbrains.com/display/TCD10/JetBrains+dotCover

Unfortunately, one of the main limitations of TeamCity documentation is the lack of screenshots for how to accomplish a particular task.

Thankfully, though, this blog article addresses that gap by providing screenshots of just how to configure dotCover within TeamCity: https://blog.jetbrains.com/dotnet/2010/12/10/coverage-with-dotcover-teamcity-mstest-nunit-or-mspec/

Once you have set everything up correctly, you will end up with Code Coverage Reports in TeamCity like the following:



Friday, August 26, 2016

Code Metrics PowerTool for Visual Studio 2015

If you want to run Code Metrics for your Visual Studio solution, you will need to download the appropriate version of Code Metrics Power Tool corresponding to your Visual Studio version.

For Visual Studio 2015, you can download the Code Metrics Power Tool from here: https://www.microsoft.com/en-us/download/details.aspx?id=48213

If you need to integrate the calculation of Code Metrics into your automated build process (such as Jetbrains TeamCity), then you can learn how to use Code Metrics from the command line here: http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx

If you need to make the XML results viewable, then you will probably need a set of XSLT and CSS files to transform the XML into HTML, then you will want to take a look at this article: https://blogs.msdn.microsoft.com/camerons/2011/02/20/code-metrics-reporting-and-xslt-debugging/

Unfortunately, the links to the XSLT and CSS are broken!

I was able to dig up a version of the MetricsResultsTransform.xslt file from another site which I am providing for your reference below:

However, I was not able to find the Default.css file, so this functionality is still missing from the XSLT transformation.

If you think Microsoft should ship a default set of XSLT and CSS files with the Code Metrics PowerTool, you can vote for this UserVoice item here: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/15832576-ship-default-xslt-and-css-files-with-the-code-metr



Thursday, August 25, 2016

Where is FxCopCmd.exe located?

If you are looking for the location of FxCopCmd.exe that ships with Visual Studio 2015, you can find it at this path:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe

In addition, you will find the FxCop Rule Sets available in this folder location:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Static Analysis Tools\Rule Sets




Tuesday, August 23, 2016

Running Code Analysis on your Visual Studio solution

In previous versions of Visual Studio prior to Visual Studio 2015 (such as Visual Studio 2013), Code Analysis was not available to editions of Visual Studio lower than Premium edition.  However, with the release of Visual Studio 2015, Code Analysis is now available even with the Professional Edition!

Now that Code Analysis is available to a much wider audience of developers, you may be wondering how to perform Code Analysis on your solution or on your individual Visual Studio Projects.

You can run Code Analysis on your solution simply by right-clicking on your solution and selecting "Analyze-->Run Code Analysis on Solution":



You can then enable Code Analysis on individual projects by going into the Project Properties and selecting the tab for "Code Analysis":


Finally, you can suppress specific error messages and warnings from the Build log by selecting the "Build" tab and semicolon-delimiting the specific error messages and warnings you wish to suppress:



Lastly, you can view any Code Analysis Error Messages and Warnings directly from the Error List window:


To read more about Visual Studio Code Analysis, you can check out the following articles:



Friday, August 19, 2016

Managing NuGet packages for your solution

When you have multiple projects in a solution, you may find it difficult to ensure that all of the NuGet packages in the solution are all using the same NuGet package versions.

Fortunately, you can manage all of these various NuGet package versions at the solution level!


  1. Right click on your solution and select "Manage NuGet Packages for Solution"
  2. You will then be presented with a dialog which allows you to see all of the NuGet packages that are being used in your solution
  3. In addition, if there are differing version numbers of NuGet packages in different projects, you also have the option to "Consolidate" to ensure that all of your projects are using the same NuGet package version numbers!



Thursday, August 18, 2016

Using the FxCop Build Runner in Jetbrains TeamCity

If you want to use the FxCop Build Runner in Jetbrains TeamCity, you can consult the documentation here: https://confluence.jetbrains.com/display/TCD10/FxCop



For the path to FxCop, using the option for "Autodetect installation" should work well for you in most cases:



In some cases, if you have multiple versions of Visual Studio installed on your machine, you may want to select a specific version of FxCop:




  • For Visual Studio 2013, you will select 12.0
  • For Visual Studio 2015, you will select 15.0
For the list of Assemblies, you can specify a relative path to the assemblies by using a wildcard expression such as *.dll.  Of course, since you are probably compiling a solution with multiple projects, you will want to specify the path to each set of assemblies in your solution such as MyProject\bin\MyProject.dll, MyProject2\bin\MyProject2.dll as follows:






You need to make sure that the names of your assemblies are all SPACE SEPARATED in order to ensure that FxCop runs correctly against them.

You must then configure the Advanced Options for FxCop in order to be able to run correctly against referenced assemblies etc.:


I like to specify the path to "Search referenced assemblies in directories" and uncheck the option for "Search referenced assemblies in GAC".  This is especially relevant since I distribute most of my assembly references through NuGet packages rather than installing them into the GAC.

Optionally, you can also configure the "Build Failure Conditions" such that any "Fail on analysis errors" in FxCop will also trigger a failure of the build

Personally, I avoid this setting since I generally work with offshore development teams which do not run regular code analysis on their projects/solution nor may they be licensed to run Code Analysis on their solution with their edition of Visual Studio.  Visual Studio 2015 Professional and above now offers Code Analysis and Code Metrics, but earlier editions of Visual Studio such as Visual Studio 2013 did not.  However, setting this value can potentially be disruptive to any team which is not very particular about following all of the guidelines outlined by FxCop.

Finally, once you have specified the correct path for your build, you will be able to use the TeamCity FxCop Build Runner to generate a Code Inspection report!

You can access the Code Inspection report from the "Build shortcuts" dropdown menu:









Thursday, August 11, 2016

Setting up a Private Extension Gallery

If you use Visual Studio Extensions extensively, then you are probably very familiar with the Visual Studio Gallery, but what if you want to set up a Private Extension Gallery just for use with your internal development team?

Well, there is a solution for that as well!

If you read this article from MSDN, you will think that you need to set up your own Atom feed in order to accomplish this: https://msdn.microsoft.com/en-us/library/hh266746.aspx

https://msdn.microsoft.com/en-us/library/hh266717.aspx

Moreover, if you read this article, you will think that the only options you have available to you are an Atom Feed or SharePoint: https://msdn.microsoft.com/en-us/library/hh266735.aspx

But, thanks to CodePlex, you can download an MVC Web Application which provides this support for you!  http://inmetavsgallery.codeplex.com/

You will need to install WebDeploy so that you can deploy this Web Application to your IIS site.  But, you may find that it does not work even after installing the Web Application into IIS!  This is because of a registry key that needs to be imported before Visual Studio will recognize the WCF Service for hosting the Extensions as documented here: http://blog.ehn.nu/2013/12/inmeta-visual-studio-extension-gallery-version-2-0/

The key value for this is the "VSGallery" value for the Protocol Registry Subkey.

Unfortunately, the registry key that is provided on the CodePlex site is a bit outdated and does not work for later versions of Visual Studio such as Visual Studio 2015.

I have written a convenient PowerShell script to handle newer versions of Visual Studio:


If you prefer to add the Private Gallery directly through Visual Studio, you can do that as well as follows:



You will then end up with something like this in the Registry:



Now once you have done that, you simply have to run the following PowerShell script to update the Protocol Registry Subkey so that it is updated to "VSGallery" and provide the appropriate matching GUID:
Alternatively, if you are only planning to have a single Private Extension Gallery, you can use this script to dynamically retrieve it and update the Protocol for you:

Wednesday, August 10, 2016

Viewing your TODO tasks in Visual Studio

As you work through your code in Visual Studio, you may accumulate quite a number of //TODO: items interspersed throughout your code base.

So how exactly do you go back and view all of those TODO items in your code base?

You simply select "Task List" (Ctrl + W, T) from the View menu as follows:



However, as soon as you address these TODO items, you should remove those TODO comments from your code, otherwise they will not be removed from the Task List pane.

That is all there is to it!

Saturday, August 6, 2016

Creating Custom Scaffolding Templates for ASP.NET MVC and ASP.NET Web API

If you need to heavily customize the out-of-the-box templates that come with ASP.NET MVC and ASP.NET Web API, you can either create a brand new T4 Templates project or simply use the CodeTemplates directory functionality for Scaffolding that is already available with ASP.NET MVC and ASP.NET Web API!

You can read more about creating your own Custom Scaffolding Templates below:

http://weblogs.asp.net/imranbaloch/customizing-the-asp-net-mvc-5-web-api-2-scaffolding-templates

http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx

https://www.credera.com/blog/technology-insights/microsoft-solutions/create-custom-scaffold-templates-asp-net-mvc/

All of these articles refer to paths from earlier versions of Visual Studio, so if you are wondering about the correct path for Visual Studio 2015, it is this:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates

Inside that folder, you will find the following folder structure which displays all of the possible default scaffolding templates that you can override by bringing it directly into your solution:



Once you have your Scaffolding templates in place, you can simply right click in your ASP.NET MVC or ASP.NET Web API project and select Add --> New Scaffolded Item:





This will then use your own custom Scaffolding Template instead of the out-of-the-box Scaffolding templates that ship with Visual Studio!  In addition, you can also add new Scaffolding templates as well that can further extend what ships with Visual Studio!

How cool is that??

Friday, August 5, 2016

T4 Editor with Intellisense for Visual Studio

If you find yourself requiring Intellisense for T4 Templates that you are writing for your Visual Studio Projects, then you will definitely want to take a look at these 2 editors:

The tangible T4 Editor has support for Visual Studio 2015 but has limited features and functionality in its FREE edition: http://t4-editor.tangible-engineering.com/t4editor_features.html#Compare


Thursday, August 4, 2016

Unit Testing with AutoMapper

If you are using AutoMapper in your projects, you may know that there are multiple ways to use AutoMapper within your application.  There is both static and instance based configuration for AutoMapper.  https://github.com/AutoMapper/AutoMapper/wiki/Static-and-Instance-API

The most common method of using AutoMapper in most applications is using the Static API.  However, if you are used to using an IoC container such as Ninject, you may consider this problematic when it comes to your Unit Tests, because when you begin executing Unit Tests which depend on the static instance of AutoMapper, you may receive an error such as this:


So how do you work around this exception?

Well, if you are using a Unit Testing framework such as MSTest, the solution is very simple!

You can leverage the [TestInitialize] attribute to initialize your AutoMapper configuration before your Unit Tests execute like so:



Now, when you run your Unit Tests which leverage the static instance of AutoMapper, they should execute without any exceptions or errors!!

Unit Testing with MSTest

Even though many development teams are beginning to transition over to xUnit.Net for their Unit Tests, many teams are still continuing to develop Unit Tests with MSTest simply because the Visual Studio IDE integration is much better than xUnit.Net and it comes with the Visual Studio IDE out-of-the-box without installing any additional packages or extensions.

Therefore, if you are also working with MSTest, then you will probably want to use a handy reference guide for working with MSTest!

Microsoft has created a basic reference guide for MSTest:  https://msdn.microsoft.com/en-us/library/ms243147(v=vs.90).aspx

Of course, this guide has not been updated in several years which probably explains why many developers are beginning to move over to xUnit.Net which is better maintained and more frequently updated.

In any case, hopefully this guide helps you in writing your MSTest Unit Tests!

Wednesday, August 3, 2016

Hidden features in Visual Studio 2015

Microsoft recently published an article on Hidden features in Visual Studio 2015: https://blogs.msdn.microsoft.com/visualstudio/2016/07/29/visual-studio-hidden-gems/

One of the most surprising features to come out of this article was a feature I never knew about called the C# Interactive Window!


I had previously used tools such as LINQPad to effectively work as a C# Scratchpad for me, but now that I know about this hidden feature, I will be able to test out my code directly in the Visual Studio IDE!!