Friday, July 29, 2016

Running Visual Studio Unit Tests in TeamCity

As I start writing Unit Tests for my application, I usually also want to ensure that all of my Unit Tests are also passing whenever I check in my code!

The easiest way to accomplish this is to integrate the execution of my Unit Tests within TeamCity is to add a "Visual Studio Tests" build step:



Once you add the Visual Studio Tests Build Step, you will need to add the paths to the Unit Test assemblies.  I usually like to create TeamCity parameters and then pass the list of Unit Test assemblies to the Visual Studio Tests Build Step.



However, even though it is stated in the TeamCity User Interface and documentation that you can pass multiple Unit Test assemblies by including each path on a separate line, this has been quite unreliable since in a long list of Unit Test assemblies, any problems are not reported if those Unit Test assemblies are missing!  Therefore, I prefer to create separate Build Steps for each of my Unit Test assemblies to ensure I am able to see any errors that occur with any of my Unit Tests:





That is all there is to it!!

TeamCity server requires technical maintenance

With the recent release of TeamCity 10.0, I decided to upgrade my TeamCity instance when I suddenly saw this message:







Based on the information provided in the message, I would have to check the teamcity-server.log for the Maintenance Authentication Token.

So where is that log file exactly?

It can be found here for most installations of TeamCity: C:\TeamCity\logs\teamcity-server.log

Time Tracking for Team Foundation Server/Visual Studio Online

One of the most highly requested features for Team Foundation Server and Visual Studio Online is to add support for a timer or a similar time tracking feature that allows users of TFS and VSO to track the ACTUAL time spent on a particular Work Item Task.

Unfortunately, Microsoft is quite adamant about not providing support for this functionality within the base TFS/VSO product as evidenced by this UserVoice item: https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/4096739-tfs-task-timer-tool-to-measure-working-time-in-a-t

However, this UserVoice item was declined back in 2013, but there is another UserVoice item which is still active that might garner some attention for the either TFS 2015 or the next release of TFS if enough people vote on this UserVoice item: https://visualstudio.uservoice.com/forums/330519-team-services/suggestions/8219763-start-work-starts-a-timer

Aside from that, there are a few commercial options for TFS Time Tracking:

http://www.tfs-timetracker.com/

http://www.teamexpand.com/product/tfs-timesheet

http://www.imaginet.com/imaginet-timesheet-for-tfs/#pricing

https://sswtimepro.com/#Pricing

There is also a free project called TFS Working On, but this project seems to no longer being actively developed for recent releases of TFS: http://tfsworkingon.codeplex.com/


Sequence contains no elements while using Ninject

I was recently working on an ASP.NET Web API project that used Ninject as its IoC container when I was suddenly faced with this error message:


As you can see from above, the error message provided no real insight as to what might be the root cause of the problem!

Therefore, I decided to do some further digging into the documentation for Ninject and came across this article: https://github.com/ninject/Ninject.Web.Common/wiki/Setting-up-an-IIS-hosted-web-application

Based on this documentation, I needed to make sure that my NuGet package reference to Ninject.Web.Common.WebHost was correct.

Of course, when I went into my packages.config file, the NuGet package reference was listed and it was also listed as installed in NuGet Package Manager.

However, based on the error message, I figured there was some problem with this installation and its corresponding references so I removed the line from packages.config in my Web API project and re-installed the Ninject.Web.Common.WebHost NuGet package reference.

As you can already probably guess, this did the trick for me and resolved this very elusive Ninject problem!!

NOTE:  Another time I have encountered this problem has been due to invalid assemblies in the bin folder of my ASP.NET Web API project.  Simple deleting the bin folder of my ASP.NET Web API project and rebuilding my solution also resolved the problem!

Thursday, July 28, 2016

Implementing the Repository Pattern in C# with Entity Framework

If you are looking to implement the Repository Pattern in C#, you may find lots and lots and LOTS of conflicting solutions about how to implement the Repository Pattern in your own application.

If you just do a quick search just on MSDN, you will find articles such as the following:

https://blogs.msdn.microsoft.com/wriju/2013/08/23/using-repository-pattern-in-entity-framework/

http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application

If you look through the examples above, you will see that they offer different solutions to the same Repository Pattern problem.  However, the second example provides the ability to create a Generic Repository which is much more appealing than creating a different repository for each class in your entire data model!

Unfortunately, the MSDN example lacks a definition of a generic interface which GenericRepository implements.  Looking at the code, you can derive your own IRepository interface, but the example still lacks support for a Dependency Injection or IoC container.  As you will readily notice, the example directly requires an implementation of SchoolContext to be created.  The way in which the example gets around direct creation of the SchoolContext is by using a Unit of Work class which handles the creation of this instance.  While the Unit of Work class can be useful in aggregating multiple repositories, it may not make much sense for instances when you simply need a single repository, which is why an IoC container is very useful!

So how exactly do you get Ninject to work in this scenario?

For Ninject, you simply use the following code to inject your SchoolContext instance:


You can simply add the following code to your RegisterServices method inside of your NinjectWebCommon.cs file and this should do the trick for you!

Renaming classes in ASP.NET MVC with Visual Studio

One of the things in Visual Studio is that it makes it relatively easy to rename classes in C# using the "Rename" command.  Visual Studio will then attempt to apply this rename operation throughout the project to ensure all references are also renamed.

However, one area where Visual Studio fails is in ASP.NET MVC Razor Views.

For example, if you have a binding to a Model class such as this:

@model List<MyModel>

and you then change the name of the Model class to MyViewModel, the C# code will be updated, but the Razor View will not subsequently be updated!

Therefore, you will still have to manually update the reference in the Razor View to match your new Model class name such as:

@model List<MyViewModel>

Just something to watch out for as you perform your refactoring and renaming within ASP.NET MVC!!

Tuesday, July 26, 2016

Setting a Default Value for a ViewModel using Data Annotations

In some cases, you may want to set a Default Value for an attribute in your ViewModel (or Model).  Of course, you can do this in your class constructor, but it is much easier and cleaner to set these values using Data Annotations!  This is especially true if you are already using Data Annotations to decorate your ViewModels.

You can do this readily using the DefaultValue Data Annotation as documented here: https://msdn.microsoft.com/en-us/library/system.componentmodel.defaultvalueattribute(v=vs.110).aspx

If you do not use a constant value to assign a value for your DefaultValue attribute, you may encounter the following error message:


This is easily remedied though by simply assigning your value to a constant instead of a statically assigned property such as:

Ultimately, this ends up looking like this for your Data Annotation:

Rendering a Partial View in ASP.NET MVC

If you look for documentation regarding rendering a Partial View in ASP.NET MVC, unfortunately, most of the links will point to StackOverflow forum threads.

This becomes a mixed bag of answers, so it may take numerous threads before you discover the right solution!

If you just type @Html.RenderPartial, then you will end up with the following error in Visual Studio:


Since so many Html Helpers just work this way, the actual answer to using the RenderPartial Html Helper is a bit more elusive:

As you can tell from the code sample, the RenderPartial Html Helper needs to be surrounded by curly braces ({...}). After you do this, your RenderPartial Html Helper will work correctly!

Understanding the Kendo UI Hierarchical Grid

I needed to implement a Hiearchical Grid with the Kendo UI Grids recently and when I looked at this demo (http://demos.telerik.com/aspnet-mvc/grid/hierarchy), I could not understand how to get the code sample to work for my particular scenario since the code sample seemed rather cryptic!

Well, as it turns out, the key element to understand in the Hierarchical Grid sample are these 2 pieces of the code:

.Name("grid_#=EmployeeID#") // template expression, to be evaluated in the master context

.Read(read => read.Action("HierarchyBinding_Orders", "Grid", new { employeeID = "#=EmployeeID#" }))

So where is this EmployeeID value ACTUALLY used??

Well, in this case, it is being used in the MVC Controller in this snippet of code:

The EmployeeID is the ACTUAL value that must be passed to the LINQ Query in order to filter the expression based on the parent record Id. If this value is ANYTHING else in the Razor View than what is being used in the LINQ Query expression, the Hierarchical Grid will not work!!

Hopefully that clarifies things a bit regarding this somewhat confusing code sample!

Debugging Kendo UI with Google Chrome

If you are developing with Telerik Kendo UI, you may want a few more tools to help you out in your development with Kendo UI.

Fortunately, the Kendo UI team has released an extension for Google Chrome to allow you to do just that!

You can download the Google Chrome Extension from here: https://chrome.google.com/webstore/detail/telerik-kendo-ui-chrome-i/npcmgpnfknjmndbbakdhchgibaajnlpe?hl=en

If you want to learn more about how to use the Kendo UI Chrome Extension, you should check out this article: http://developer.telerik.com/products/say-hello-to-the-kendo-ui-chrome-inspector/

VSCommands is back for Visual Studio 2015!

One of the extensions that I used frequently in my development was VSCommands.  However, with the release of Visual Studio 2015, it seemed that the project had eventually died out and would not be supporting Visual Studio 2015 anytime soon.

Thankfully, though, VSCommands has now been released to support Visual Studio 2015!

You can download the VSCommand extension from here: https://visualstudiogallery.msdn.microsoft.com/c84be782-b1f1-4f6b-85bb-945ebc852aa1

Staged and unstaged files in Git using Visual Studio

Most developers have a common scenario of managing Web.config files among teams due to differing database connection strings.  If everyone is using a local instance of SQL Server or SQL Server Express, this might be able to be managed readily but if the connection strings are pointing to a shared server, this database connection string might change across development teams.  This issue is particularly prominent in offshore development teams whereby onshore and offshore development teams might need to use different database connection strings.

If you are using a source control repository such as Git, though, managing these individual changes among developers is a relatively easy task by leveraging Staged and Unstaged files!

Once you have a list of changes in Visual Studio Team Explorer, you can right click on one or more files to choose to Stage these files:





Once you have selected the files to Stage, you will end up with a list of Staged Changes and Changes (Unstaged Changes):


The files that are listed as Unstaged Changes will be excluded from being pushed to Git as follows by using the "Commit Staged" set of commands:


This allows isolated changes (such as those made to the Web.config file) to remain locally on developer machines while changes to other files can continue to be pushed to Git!

Monday, July 25, 2016

Checking SendGrid usage statistics for Windows Azure SendGrid accounts

I recently wanted to check how many e-mails SendGrid was sending every day from my Windows Azure SendGrid account and as you can probably guess, I was not able to find this information from within the Windows Azure Portal!

Well, I decided to try logging in with my Windows Azure account into http://sendgrid.com/ and I was able to view my graphs of my e-mail usage!


Ensure that you have defined a binding for HttpConfiguration only once

I was recently working on adding Ninject to an ASP.NET Web API web application, when I suddenly encountered the following error message:



Well, as it turns out, after adding the Ninject.Web.WebApi.WebHost NuGet package reference, I also had a reference to Ninject.Web.WebApi which was causing the HttpConfiguration to be injected twice!

I had originally added the Ninject.Web.WebApi.WebHost NuGet package reference so that the NinjectWebCommon.cs file would be added automatically to my App_Start directory for injecting my dependencies.

Once that file was added, I no longer needed this NuGet package reference, so I went ahead and removed it and I could successfully browse my ASP.NET Web API Web Application once again!

Wednesday, July 20, 2016

Visual Studio support for Beyond Compare with Git

If you have worked with Git inside of Visual Studio, you probably quickly discovered that the Git integration in Visual Studio does not provide support for any 3rd party tools such as Beyond Compare out-of-the-box (unlike TFS Integration).

But, as they say, where there is a will, there is a way!

Therefore, a clever developer has provided Git Extensions for Visual Studio: https://visualstudiogallery.msdn.microsoft.com/8f594baa-e44e-4114-8381-e175ace0fe97

This is further dependent on the installation of the Git Extensions project: http://gitextensions.github.io/

Once you have installed both of these tools, you will get a menu similar to the following:




Then, once you click on "Git Config" in the left hand navigation menu, you will get options similar to the following:



In this configuration, you can setup support for Beyond Compare!

Unfortunately, the integration is not quite complete with Visual Studio since when you open up the Repository Settings in Visual Studio, you will discover that only the "Merge Tool" displays as BeyondCompare4 while the "Diff Tool" still displays as Visual Studio.


Oh well!  Maybe they will fix this slight oversight in a future release of Git Extensions!

Also, if you want Microsoft to include support for Beyond Compare and other 3rd party diffing and merging tools, you should vote for this UserVoice item here: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/13375314-allow-3rd-party-compare-tools-when-using-git-integ

Developer Assistant for Visual Studio

I was recently reading an MSDN Blog article and came across this tool: https://blogs.msdn.microsoft.com/onecode/p/devassistant/

The features it provided seemed really intriguing so I went ahead and downloaded it from here: https://visualstudiogallery.msdn.microsoft.com/5d01e3bd-6433-47f2-9c6d-a9da52d172cc

After installing it, I just began typing some C# code and found these new Intellisense pop-up menus:


Just this immensely improved Intellisense while typing was enough to sell me on using the tool whenever I work with Visual Studio!


Roadmap and upcoming changes to .NET Core

Microsoft has published a roadmap of upcoming changes to the .NET Core platform: https://blogs.msdn.microsoft.com/dotnet/2016/07/15/net-core-roadmap/

One of the exciting changes coming (back) to the .NET Core platform is the re-introduction of MSBuild/.csproj support!

As many people know, Microsoft decided to pull out this support in .NET Core but since this drastic change did not go over very well, they will be bringing it back into a future release of .NET Core.

Unfortunately, you may have to wait until the end of this year or beginning of next year for this change to be implemented, but for most development organizations that are already using ASP.NET MVC 5 and ASP.NET Web API 2.2, this won't be a problem!


Managing alerts in Team Foundation Server and Visual Studio Online

If you want to manage Alerts for yourself or your team members, you can set up Alerts by following this article: https://www.visualstudio.com/en-us/docs/work/track/alerts-and-notifications

Basically, when you log into Team Web Access, you have to click on your gear icon in the toolbar to get to the Control Panel:



Once you get into the Control Panel, you will want to click on the Alerts tab:


You can then set up the different types of Alerts for yourself.  I normally configure Alerts for Work Items:


You should then have the Alerts show up as follows:


Microsoft giving away FREE E-Books!

Microsoft is giving away a TON of FREE E-Books!

You can get a list of all of the FREE E-Books from here: https://blogs.msdn.microsoft.com/mssmallbiz/2016/07/10/how-to-download-all-of-the-free-ebooks-and-resources-in-my-free-ebooks-giveaway/

3rd party ASP.NET MVC Controls

When it comes to ASP.NET MVC Controls, there are a wide variety of options to choose from!

Some of the most notable ones that come to mind are the following:

DevExpress ASP.NET MVC Extensions: https://demos.devexpress.com/MVC/

Telerik Kendo UI: http://demos.telerik.com/kendo-ui/

Infragistics Ignite UI: http://www.igniteui.com/combo/_ga=1.84958809.1131719451.1467812808

ComponentOne MVC Edition: http://www.componentone.com/Studio/Platform/MVC

Syncfusion Essential Studio for ASP.NET MVC: https://www.syncfusion.com/products/aspnetmvc

The editors of Visual Studio Magazine have also published an article reviewing several of the ASP.NET MVC Control vendors: https://visualstudiomagazine.com/Articles/2015/09/01/9-Top-NET-UI-Component-Collections.aspx?Page=1

While my personal favorite is Telerik Kendo UI for ease of use and technical support, Kendo UI does not have the same types of controls nor the same breadth of controls as other competing products such as Syncfusion Essential Studio or DevExpress MVC Extensions.

Based on your project's needs and requirements, you will have to decide which suite (or suites) of ASP.NET MVC controls best suit your development team!

Tuesday, July 19, 2016

Web Extension Pack for Visual Studio 2015

If you have used Web Essentials in the past, you may have noticed that they began unbundling several of the features previously available in Web Essentials: https://visualstudiogallery.msdn.microsoft.com/ee6e6d8c-c837-41fb-886a-6b50ae2d06a2

However, this was becoming difficult for developers to manage all of the separate extensions, so they were once again bundles and re-released as the Web Extension Pack: https://visualstudiogallery.msdn.microsoft.com/f3b504c6-0095-42f1-a989-51d5fc2a8459


We can't install the 64-bit version of Office

I was recently trying to install the 64-bit version of Visio, when I encountered the following error message:


Well, a quick search on Google came up with this search result: http://www.rbrussell.com/2015/12/29/fix-for-microsoft-office-setup-error-please-uninstall-all-32-bit-office-programs-office-15-click-to-run-extensibility-component/

Based on the article, I proceeded to follow the instructions it provided:




I then tried re-installing Visio 2016 on my system and was presented with this new error message:


I noticed there were a few more "Office 16 Click-to-Run" components on my machine so I proceeded to uninstall those as well:


Once those were uninstalled, I STILL received the above error message!

Well, as it turns out, the error message was ACTUALLY a result of having the Retail version of Microsoft Office 2016 installed on my system and I was trying to install the Volume License version of Visio 2016!

Once I attempted to install the Retail version of Visio 2016, the installation worked just fine!



External editing from a Kendo UI Grid

I recently had a requirement to edit records in a Kendo UI Grid from an externally available form.

There is some documentation which addresses how to accomplish this: http://docs.telerik.com/kendo-ui/controls/data-management/grid/how-to/Editing/grid-external-form-editing

But it does not specifically address the ASP.NET MVC Kendo UI controls...

Unfortunately, the Kendo UI Grid does not currently offer this functionality out-of-the-box even though other competitors such as DevExpress DO offer this functionality: http://demos.devexpress.com/MVCxGridViewDemos/Editing/ExternalEditForm

If you want to see the Telerik Kendo UI team also offer this functionality, then I would recommend that you vote for this Kendo UI Feedback item here: http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/15277692-external-editing-for-kendo-ui-grid

Monday, July 18, 2016

Provide feedback to the Kendo UI Team

If you want to provide feedback and suggestions to the Kendo UI team, then you can provide feedback through this UserVoice forum: http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback

Adding a Search box to a Kendo UI Grid

I was recently working on implementing search functionality for the Kendo UI Grid based  on a set of JavaScript grid controls such as this: https://datatables.net/

If you look at the Search functionality implemented in these controls, you will notice that the search functionality is very nice in that it can readily search all of the columns and text in the controls just by typing some search text.

Unfortunately, the Kendo UI Grid control does not offer the same functionality out-of-the-box.  While filtering is available, it does not provide the exact same set of functionality as provided by the search text box in the Data Tables controls.

Competing companies such as DevExpress already provide this functionality out-of-the-box with their controls: http://demos.devexpress.com/MVCxGridViewDemos/Filtering/SearchPanel

However, with the Kendo UI Grid control, you have to go and roll your own solution to accomplish this by following one of the following posts:

https://telerikhelper.net/2014/10/21/how-to-external-search-box-for-kendo-ui-grid/

http://www.telerik.com/forums/grid-with-filterable-and-external-search-inptus

If you want to see a demo of this functionality, you can check it out here: http://dojo.telerik.com/idOVU

If you would like to see this feature included in an upcoming release of the Telerik Kendo UI Grid control, you can vote for this UserVoice item here: http://kendoui-feedback.telerik.com/forums/127393-kendo-ui-feedback/suggestions/8441518-grid-simple-search-panel


Pinging an IPv4 Network Address

Now that most Windows machines have IPv6 installed by default, I have noticed that when you do a ping of a machine, you will get the IPv6 address instead of the IPv4 address!!

Well, I still prefer reading and remembering the IPv4 addresses, so I wanted to find out how to get the IPv4 address instead when I performed a ping.

Thankfully, it was rather easy to accomplish as follows:

ping MYSERVER -4

That was all that was needed to return the IPv4 address!

If I still want to get the IPv6 address, I can get it by just changing the command to this instead:

ping MYSERVER -6

How simple is that??

Saturday, July 16, 2016

Failed to delete storage account

I was attempting to delete one of my storage account containers in the new Windows Azure Portal, when I suddenly encountered this error message:



I went to link provided in the error message: https://azure.microsoft.com/en-us/documentation/articles/storage-cannot-delete-storage-account-container-vhd/

This indicated that I needed to switch the Azure Classic Portal in order to rectify this problem!

I needed to go into my Virtual Machines and check the disks and images.

When I initially looked at my Virtual Machines, there were none there!



However, the article further stated that the Disks and Images might still exist so I proceeded to check my Disks:



Sure enough, the disk was still there!  I went ahead and deleted the disk and then moved on to the Images:



Once again, I went ahead and deleted the Image.

Now, when I went back to the new Windows Azure Portal, I tried to delete the storage account and got the successful message: "Successfully deleted storage account"!!

Friday, July 15, 2016

Performing database deployments using AliaSQL

Most continuous integration build processes have a need to perform database deployments over the course of development, which is why a tool such as AliaSQL arose to fulfill that need!

You can find out about AliaSQL from here: https://github.com/ClearMeasure/AliaSQL

AliaSQL is available for download directly as an executable or can be installed via a NuGet package.

Once you download the tool, you will probably want to learn how to use it, so you should check out the "Getting Started" guide here: https://github.com/ClearMeasure/AliaSQL/wiki/Getting-started

If you want to look at a demo project, you can find that here: https://github.com/ericdc1/AliaSQL-Demo/tree/master/Source/Database.Demo/scripts

While I was working with AliaSQL, however, I found a problem in the samples that were provided in the Getting Started Guide:

AliaSQL.exe Update .\sqlexpress Demo ./scripts

First of all, the example assumes that you have SQL Server Express installed.  Fortunately, the name of the database server can just as easily be substituted as follows:

AliaSQL.exe Update SQL2014Svr Demo ./scripts

But what about remote SQL Server instances?  What do you do then?  Thankfully, a solution for that is also available:

AliaSQL.exe Update SQL2014Svr Demo ./scripts mysqluser mysqlpassword

Lastly, I could never get this command to work!!  So what was wrong?  Well, even though the AliaSQL.exe file is placed in the root of the scripts directory, the path that is used in the command assumes that AliaSQL resides OUTSIDE of the scripts directory!!  This was fixed by using the following command instead:

AliaSQL.exe Update SQL2014Svr Demo . mysqluser mysqlpassword

Notice that I no longer reference the relative path to the ./scripts directory and simply assume that the AliaSQL.exe exists at the root of the scripts directory (as follows the pattern in the demo and the KickStarter project).

That was all that was needed for working with AliaSQL to do my database deployments!

For your reference, I have also provided a sample PowerShell script on doing database deployments using AliaSQL:


Wednesday, July 13, 2016

Creating local branches in Git

If you ever want to do localized development and refactoring without requiring a special branch for the entire team, Git allows you to do that in the form of creating a local branch.

If you are a Visual Studio developer, Microsoft offers an article that provides insight on how to create local branches:

Creating work in Git Branches

https://www.visualstudio.com/en-us/docs/git/tutorial/branches

Now, if you want to merge that code BACK into Git, then you can use a command called Rebase as follows:

Managing history and merging changes with Git Rebase

https://www.visualstudio.com/en-us/docs/git/tutorial/rebase


In these Visual Studio articles, if you are looking for screenshots on how to do this, it may not be readily obvious where those screenshots exist.

When you get to the section in the articles where there are buttons for "Command Line" and "Visual Studio", you have to click on the Visual Studio button to expand the section including the screenshot:





Tuesday, July 12, 2016

Determining which .NET Framework versions are installed using PowerShell

If you want to determine which versions of the .NET Framework are installed on your machine, as of .NET v. 4.5, this is not so easy as in earlier releases because there are multiple iterations of this framework and they all reside in the C:\Windows\Microsoft.NET\Framework64\v4.0.30319 folder!

If you look for a solution on Microsoft's website, you will find this article: https://msdn.microsoft.com/en-us/library/hh925568

Unfortunately, it recommends writing a .NET application to determine the version of the .NET Framework installed on your machine.

But what if you want to use a PowerShell script instead?

Thankfully, one user posted a solution on StackOverflow: http://stackoverflow.com/questions/3487265/powershell-script-to-return-versions-of-net-framework-on-a-machine

You can see the resultant script here:

The problems with Attribute-based routing in ASP.NET Web Api

I was recently working on a project whereby Attribute-based routing was being used in conjunction with Partial Classes for Web API Controllers.

While I will not going into the details of this inherent design flaw, it allowed me to better understand the problems inherent with Attribute-based routing and why so many developers prefer defining explicit routes in the WebApiConfig.cs class file.


  1. The first thing I noticed as an inherent limitation of Attribute-based routing was that you can only define the RoutePrefix attribute on a single class instance even in a partial class scenario.  Therefore, if you have a partial class that splits across 2 files, this means that the RoutePrefix can only exist on one of the 2 files, thus making it more difficult to understand what is the RoutePrefix definition when switching between the 2 files.  Now, just imagine, if that partial class is split across 3 or more files!
  2. Another thing that I noticed was Attribute-based routing does not work perfectly on all methods even when defining a RoutePrefix in a class file.  I had one instance of a class that was using more than 8 parameters in the method definition, and it also had no route attribute assigned to it.  In this instance, the RoutePrefix was being totally ignored by ASP.NET Web API and instead only the Default Route was being used for this particular method.  Scenarios like this make Attribute-based routing even more troublesome.
  3. In simple instances where you are using the RoutePrefix on a class, if you forget to decorate your other methods with the Route attribute, once again these routes will not follow the Attribute-based routing convention and revert to the Default Route defined in WebApiConfig.cs.

These are just a few of the more blatant reasons that I discovered while working with Attribute-based routing.  I am sure there are many more cases than these to prefer defining explicit routes in WebApiConfig.cs, but at least now you know the consequences of choosing an Attribute-based routing scheme for your ASP.NET Web API Web Applications!



Learning AngularJS 2.0

If you are interested in learning AngularJS 2.0, you can get some free training on AngularJS 2.0 directly from Microsoft Virtual Academy!


Introduction to Angular 2.0

https://mva.microsoft.com/en-US/training-courses/introduction-to-angular-20-16540?l=cdKMEZyfC_906218965

Monday, July 11, 2016

Adding Display Formatting to ASP.NET MVC ViewModels

If you have a need to add formatting to your ASP.NET MVC screens, chances are that you want to avoid doing this in your Razor Views since it makes the views more difficult to maintain especially when you use Scaffolding.

Fortunately, you can add Display Formatting very easily to your ViewModels using this DataAnnotation attribute (https://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.displayformatattribute(v=vs.110).aspx):

[DisplayFormat(DataFormatString = "{0:MM / dd / yyyy}")]


That is all that is needed to get something like Date Formatting added to your ViewModel!

Problem with configuring Swashbuckle/Swagger for ASP.NET Web API

I was configuring Swashbuckle/Swagger for one of my ASP.NET Web API web applications using the standard NuGet package, when I suddenly encountered this error message:



I occasionally also received this error message in Google Chrome:


No matter what I changed in my Web API application, however, my Swagger documentation would not work!

I was never able to come up with a solution for this problem other than blowing away the whole project and starting from scratch, so if you find a solution for this problem, leave your answer in the comments below!

Copying files and folders to a remote folder using PowerShell

I have been switching many of scripts from using command-line operations over to PowerShell in recent weeks and one of the operations I had been doing earlier was using the "net use" command to map drives to remote shares on servers before copying them over using Robocopy.

However, I did not really need to use the "net use" command since it was just part of a background process and the drive letter could be deleted immediately after the copy operation was completed so I began searching for PowerShell alternatives.

I found just such an alternative using the "New-PSDrive" command:

https://technet.microsoft.com/en-us/library/hh849829.aspx

https://technet.microsoft.com/en-us/library/ee176915.aspx

Once I understood exactly how to use this PowerShell cmdlet, I was able to compose the following PowerShell script:

Sunday, July 10, 2016

This Admin Console User cannot be removed

I recently upgrade my Team Foundation Server instance and noticed several invalid users in my TFS Admin Console.  When I attempted to remove these invalid users, I received the following error message:


Fortunately, the Microsoft link provided was very helpful and provided this solution:  https://blogs.msdn.microsoft.com/tfsao/2013/05/01/removing-an-admin-console-user-with-dbo-permissions/

Once I followed the instructions to change the dbo owner in the Files property in SQL Server for the TFS_DefaultCollection database, I could remove the user from the TFS Admin Console!

Upgrading to Team Foundation Server 2015

It has been a while since Team Foundation Server 2015 was released and now that Update 3 was recently released, I decided it was time to revisit doing upgrades from earlier releases of Team Foundation Server such as Team Foundation Server 2013.

The upgrade process remains largely the same as earlier releases of Team Foundation Server, however, there is no longer a requirement to UNINSTALL the earlier release of Team Foundation Server prior to installing Team Foundation Server 2015.