Skip to content

Recent Articles

13
May

Git for Visual Studio Developers–Get your .gitignore right and save yourself needless merges

One of the most common issues I am finding with teams moving from Team Foundation Version Control to TFS-Git is that they are including files in their repositories that they shouldn’t. The most common offenders are .suo user settings files, Nuget packages and Azure publish settings.   Luckily, the solution is straightforward.  

1. Ensure you have no pending changes.

2. Close the solution

3. Go into Team Explorer and click Settings image  

 

4. In the Settings tab select Git Settings image  

 

5. Open the .gitignore file from GitHub that is specific to Visual Studio projects and copy the contents to the clip board. https://raw.githubusercontent.com/github/gitignore/master/VisualStudio.gitignore image
Figure: the .gitignore includes a list of all of the files that you want to avoid committing to your repository 

 

4. In Settings | Repository Settings, click the Edit link next to ‘/,gitIgnore’ image  

 

 

6. Paste the contents of the .gitIngore from GitHub into the .gitignore file and Save it. image  

 

7, In Team Explorer, navigate to the Changes window. Enter a comment and click Commit. image  

 

8. Click the Sync link to take you to Unsynched Commits image  

 

9. Click the Sync button to push your updated .gitIgnore image  

 

10. If you have included files in your repository that you wish to exclude from the repository but not delete from your local working directory refer to

Remove files from your repository (so that they aren’t tracked), but leave them in the working directory

on my page for

Git: Essential Commands for Visual Studio Developers

Advertisements
4
May

What skills do you need to have on your tool-belt to be a great .Net developer?

This is what I consider to be my list of ‘essential’ tools / skills for a serious .Net developer.

An Agile or Lean methodology

Learn Scrum

If your projects are not being delivered successfully Scrum will either enable you to start delivering software, or highlight the reasons why you aren’t.
The Scrum Guide which contains all the rules of Scrum is 13 pages long. There is no excuse for not having read it.
If you aren’t doing Scrum, or you aren’t doing it well… get some help.

ALM

Learn TFS

Out of the box, it gives you so much. I find it incredible how many people have TFS but are only using it for Source Control.

Source Control

Learn both Team Foundation Source Control and Git, and the strengths of each.

Work Item Tracking

Being able to successfully deliver value to the customer while triaging bugs requires efficient work item tracking processes and tools.

Continuous Integration

Why-oh-why isn’t everyone doing CI?
Check in your code, have a magic fairy build it, test it and tell you if you’ve broken anything – sounds too good to be true AND it only takes 60 seconds to setup!
‘Fail Fast’ is probably my favourite development catch-phrase: If you find out that the code you’ve just checked-in conflicts with some-one else’s code 2 minutes after you’ve checked it in, it’s easy to resolve the issue. If you only find out there is an issue a week later, it’s much harder.

Deployment:

Get your CI fairy to take the code she builds and then deploy it to a server for you.
If every time you finish a task you can send the user a link to the test server that you just deployed to and say ‘tell me what you think’. The customer will LOVE you… and you get feedback when it’s most helpful.
If you are using Azure, continuous deployment is just so damn easy.
Also, I am having a little love affair with a tool called Octopus Deploy http://www.octopusdeploy.com. Check it out!

Cloud

As a .Net guy… you need to be familiar with Azure.
It’s remarkable how easy it has become to build and deploy web applications to the cloud. In 30 minutes I can create a source code repository on http://visualstudio.com, check in an MVC project and have it continuously deploying to an Azure website with both Release and Staging environments.
Check out Andrew Coates from Microsoft doing continuous deployment to Azure at FireBootCamp.

Azure is so much more than just websites… but as this is a ‘need to know’ list, I’ll force myself to not go on about how awesome Azure VMs and Web Roles are. If you take an interest in the cloud, Azure is a platform that will have you boring all your friends with tales of how cool it is.

Communication

Communication and interpersonal skills cannot be overemphasised. No matter how smart someone is, you don’t want them on your team if they can’t work as part of the team.

  • You need to know how to take instructions
  • You need to know how to provide feedback
  • You need to know how and when to push back, and when to give in
  • Sometimes, you just need to shut-up

Patterns, Practices and Principles.

This is the stuff I’m REALLY passionate about.

Building a complex application, that is still going to be maintainable after you have added features to it for several years requires some skills. My mission is to increase the understanding amongst .Net developers that the following are essential, not hard to learn, will improve your job satisfaction and your employers opinion of you when you continue to add value to his application well after other projects have ground to a halt.

Dependency Injection

This is not about swapping your SQL Database for an Oracle one!

There are many, many benefits to Dependency Injection: Here is the major one for me – you need dependency injection to ensure that your complex system is built in such a way that changes to one module does not cause flow on effects in other modules.

Typical on many projects: first 10 features get thrown together in a week, the next 10 features take 2 weeks, the next 10 take a month, and then every subsequent feature takes longer and longer because of the changes that need to be made throughout the project to implement the new features.

Dependency Injection is about ensuring you can continue to add features to your complex project.

Essential Reading: Dependency Injection in .Net by Mark Seeman

Unit Testing

I’m not a code coverage guy. I don’t believe every single line of code needs a unit tests.

I believe the following

You NEED to be able to write great tests.
Your application should have unit tests over 100% of the code that requires unit tests.

This is a topic that I can (and do) talk about for hours, but in summary:

I write tests

  • for fragile code, or code that is likely to break

  • for important code that you cannot afford to break

  • for code that is hard to read: Well written unit tests are the best form of documentation after well written code.

  • when writing the test provides me clarity about the code that I am about to write (slipped my TDD hat on there for a minute)

and

  • When writing a unit test will save my boss money because it’s faster than the (damn) debugger

One of my favourite rants: It is often faster to write a unit test than to test the code you have just written any other way.

I see this a lot and it drives me crazy: I’m testing the credit card validation of my online store. I want to test the submitted card number against a regex before I submit it to the Bank.

Debugger Guy: I hit F5, wait for the whole solution to compile, the website to spin up and the debugger to attach. I then select several items to add to my cart, click next, enter my name, phone number and address, click next, enter the credit card number and click next, realise there is a typo in the Regex, click Stop, change one character and press F5 again ! aaaaaarrrrggghhh !

Unit Test Guy: Writes a 5 line unit test in half the time it takes Debugger guy to even reach the code, gets feedback in milliseconds, provides great documentation about what the regex is validating and ensures that changes to the code in the future do not invalidate the current requirements.

Essential reading: The Art of Unit Testing by Roy Osherove

My session on unit testing: Eat your vegetables! Baking Healthy Projects with Unit Testing and Dependency Injection

Common patterns like Repository and Unit of Work

Patterns are important.

They provide a way for developers to communicate about common problems and suggested solutions.

I hate to re-invent the wheel when smarter people have already come before me and done most of the heavy lifting.

Familiarity with common patterns (the good and the bad) is essential to any senior developer.

Clean Code & SOLID Principles

If software were disposable, I wouldn’t be writing this post.

If I could write software today, and then walk away and never have to look at it again I may not care about the day next year when I have to come back and make sense of it – but I do.

Because I have to maintain my code – I should very much care about making it easy to maintain. This is where the idea of ‘Clean Code’ and the SOLID Principles come in.

Essential reading: Clean Code by Robert Martin

Professional developers should be proud of the code they write.

 

I struggle to understand why most developers still don’t have a good understanding of the above topics. I strongly believe that these areas should be lived and breathed by every member of a development team.
Once again, you don’t have to always use them… but if you don’t have them in your tool-belt you’re selling yourself as a professional carpenter when you don’t even own a hammer.

Technologies

I’ve deliberately left this until last.

Although most job descriptions are full of technologies, I believe that knowledge of the topics above are far more important.

Here is the current set of technologies that we use by default to build most of our web applications.

  • Obviously C#, HTML, JavaScript and jQuery.
  • Frameworks and Toolsets-> we like to keep across what’s out there, and being consultants doing new projects all the time we get to try out different things but our default stack at the moment is
    • Twitter Bootstrap
    • Angular.js
    • Telerik KendoUI
    • SignalR

Summary

I deliver large, high performing web applications for enterprises. The processes, tools and technologies above are what I believe an enterprise web developer needs to know. Obviously other development disciplines require very different skills sets.

In many scenarios other tools, frameworks or methods may be more appropriate, but before you start learning all the alternatives you should know and understand the mainstream choice. Then you are qualified to have an opinion about whether something else is better.

2
May

Upgrading from ASP.NET.Identity 1.0 to 2.0

ASP.NET.Identity 2.0 is out, and it adds a bunch of great features.

– Two-Factor Authentication (SMS, Email or custom)
– Account Lockout
– Account Confirmation via Email
– Password Reset
– Sign out everywhere
– Choose your Primary Key type (string, int, Guid)
– IQuerable Users and Roles
– Delete User
– Enforcing Unique User Names

 

The upgrade was more fiddly than I thought it would be. Here is what I had to do. I hope it helps.

 

1. Update Entity Framework to 6.1

2: Update all your OWIN components if they already exist in your project.

(Yes. NuGet should handle this for me. It didn’t. Upgrading the Owin components before the Identity packages resolved some issues for me)

image

 

3: Update Microsoft ASP.Net Identity Core and then ASP.Net Identity EntityFramework

image

 

4: Your model has now been updated to v2.0 !

If you are running Code First Migrations you now need to create a migration to reflect the changes to the database.

image

Figure: When you try to create the migration, it will tell you that the model backing the db context has changed. To resolve it, you need to update the constructor of your dbcontext.

 

image

Figure: Adding ‘, throwIfV1Schema:false’ as a parameter to the constructor will allow you to run the application, and create the required Code First Migration.

 

image

Figure: After updating the db context constructor, Add-Migration works as expected.

 

image

Figure: You can now inspect the changes to the schema in the Migration.

Upgraded !

Now check out the links below to get help on how to implement the great new features in ASP.Net Identity 2.0.

 

Resources:

ASP.NET MVC and Identity 2.0: Understanding the Basics

http://typecastexception.com/post/2014/04/20/ASPNET-MVC-and-Identity-20-Understanding-the-Basics.aspx

– a great overview of Identity 2.0

 

Announcing RTM of ASP.NET Identity 2.0.0

http://blogs.msdn.com/b/webdev/archive/2014/03/20/test-announcing-rtm-of-asp-net-identity-2-0-0.aspx

– definitely worth reading !

– contains list of features and some upgrade notes

23
Apr

Implementing SSW.HealthCheck – Step by Step

We ALWAYS automate our deployments. We always deploy often.

This has many, many benefits. The most important of which is early feedback.

An essential tool when managing deployment of many sites to different environments is a smoke-test page that validates the configuration of the website in that particular environment.

SSW.HealthCheck makes it easy to check your site status.

 

clip_image016[4]

Figure: SSW.HealthCheck let’s us see at a Glance that on this site: the database connection is valid, but Debug mode has not been turned off and SMTP is not configured. We can also easily extend SSW.HealthCheck to perform other tasks like ensuring your database is up to date. I’ll address this in a future article.

 

Create a new web project

Lets start with a new web project, then we’ll add SSW.HealthCheck.

clip_image002[5]

Figure: Create a new web project called Northwind.MusicStore.WebUI

 

clip_image004[5]

Figure: Select the MVC template and click OK.
Optionally: add the ‘Web.API’ and ‘Add unit tests’ options.

Add SSW.HealthCheck.MVC5 to WebUI

clip_image006[4]

Figure: Select Tools | Library Package Manager | Package Manager Console. Enter Install-Package SSW.HealthCheck.MVC5 and press Enter.

Note: Alternatively you can use Tools | Library Package Manager | Manage NuGet Packages for the Solution, and then search for SSW.HealthCheck.MVC5 and click Install.

clip_image008[4]
Figure: Ensure SignalR is configured: Open Startup.cs from the root of your application. Ensure app.MapSignalR() is being called in the Configuration method.

clip_image010[4]

Figure: Run the application and navigate to /HealthCheck

Configure HealthCheck to Test Your Connection Strings

clip_image012

clip_image014
Figure: Because we are using Entity Framework Code First, and it does not actually create the database until the first time it is accessed: Click the Log In link from the toolbar, enter any username and password and click Log In. Because we are trying to access the database to verify credentials this will cause the database to be created.

clip_image016[4]

Figure: The HealthCheck status of your DefaultConnection should now be Passed !

Also, check out the SSW.HealthCheck user guide here http://sswhealthcheck.com/user-guide/

22
Apr

Testing an IIS Express app from an IE 8 VM on my Macbook

I am running Windows 8 and Visual Studio on my Mac using Parallels.

The project I am currently working on is configured to use IIS Express, but I want to test it using a VM that contains IE8.

As it turns out this was quite simple to setup.

1. Download the VM from http://www.microsoft.com/en-au/download/details.aspx?id=11575  or http://www.modern.ie/en-gb/virtualization-tools

2. Open the VM using Parallels (File, New, Add Existing Virtual Machine).

3. Change the Windows 8 VM and the VM containing IE8 to both obtain their own IP addresses from the local WiFi router.

            Virtual Machine | Configure | Hardware | Network. Change type to WiFi

4. Change the configuration of the web application to use the Windows 8 VMs IP Address

             e.g. change it from http://localhost:63527/  to http://10.0.0.20:63527/

5. Edit the binding in your IIS host config file

(You can find it in  %userprofile%\Documents\IISExpress\config\applicationhost.config )

Find the entry for your application and change it from from

<binding protocol=”http” bindingInformation=”*:63527:localhost” />

to

<binding protocol=”http” bindingInformation=”*:63527:10.0.0.20″ />

6. Disable windows firewall on the Windows 8 machine.

7. Run Visual Studio as Administrator and run the application. It will now be accessible from the IE8 Virtual Machine.

References:

http://stackoverflow.com/questions/5442551/iisexpress-returns-a-503-error-from-remote-machines

4
Apr

Repository Encapsulation

It’s important to consider how strictly you should encapsulate your data access logic within the repository layer

Repository Layers allow us to abstract our data access away from our application.

There are two common approaches.

 

Approach #1: Fully Encapsulated – The Strict Repository

In this model you pass in simple types or DTOs as parameters to repository methods and receive enumerated lists of results in return. (ie. IEnumerable / ICollection / IList)

 

Benefit: Your data access is 100% completely abstracted away from your core application.
This model only requires the Entity Framework to be added to your Data project.

Cons: It’s more work. Every data access query requires a new repository method and a change to the interface.

 

Approach #2: The Flexible Repository

In this model you encapsulate complex queries, or queries that will be re-used inside your repository, but simple queries can be performed by the calling client because the Get() method accepts a filter operator and returns an IQueryable that provides great flexibility.

 

Benefit: It’s less work. A developer can build user interface that performs simple CRUD operations on the entity without needing to add methods to the Repository.

 

Cons: This is a ‘leaky’ abstraction where your implementation is likely to leak into your other layers. The Entity Framework is required as a reference in any project where you are performing queries that require EF specific extensions (e.g. .Include(c=>c.Children) )

 

For each application you need to weight the cons and benefits of the two options.

For a long-lived enterprise application, I recommend fully encapsulated repositories.

For simple applications that are essentially providing forms over data functionality, the flexible repository enables developers to quickly add value to the application, while still leveraging most of the benefits of implementing a repository layer.

 

TODO: Add Code Samples

21
Mar

FireBootCamp – Gala Day Highlights

FireBootCamp has been an amazing experience.

After 9 weeks of intense training, the FireBootCampers present the solutions that they built during the course, celebrate their successes with a glass of Champagne and mingle with potential employers.

6
Mar

Entity Framework Code First: Delete a LocalDb instance

When working with the Entity Framework Code First I will often get the error below:

An exception of type “System.Data.SqlClient.SqlException’ occurred in EntityFramework.dll but was not handled by in user code’

Additional information: Cannot drop database [database name] because it is currently in use.

To force a delete of the database, follow the steps below.

error_6-03-2014 11-04-30 AM

Figure: This exception is common after you have opened a LocalDb database in Visual Studio.

 

Open Library Package Manager and Stop the LocalDb instance

a: Select Tools | Library Package manager | Package Manager Console

b: Execute the following two statements

                  sqllocaldb stop v11.0

                  sqllocaldb delete v11.0

error_6-03-2014 11-05-59 AM

Figure: The steps above will stop and delete the LocalDb instance.

 

Delete the database file from the database

image

Figure: Open the Solution Explorer and choose Show All Files

error_6-03-2014 11-05-07 AM

Figure: Delete the mdf from the App_Data folder

7
Feb

FireBootCamp – Week 2 in review

Sprint 1 was great, but now the guys are really getting going.

Check out their progress in Sprint 2.

6
Feb

60 Second Demo – Configure a CI Build + Setup Build Notifications

Configure Your Build

1. Open the Build Pane

clip_image001

Figure: From Team Explorer choose Builds

 

2. Create a new build definition

clip_image002

Figure: Click on the New Build Definition link

 

3. Enter build definition name “AdamS.MembershipSample.CI”
(CI for Continuous Integration)

4. On the Trigger tab choose ‘Continuous Integration’

 

5. On the Source Settings tab remove any unwanted Source Control folders
clip_image003

Figure: Remove any items that do not apply to your project (sometimes items from other solutions will appear in this list – remove them)

 

6. On the Process tab, ensure that the solution is being built

 

7. Save the Build

Configure Build Notifications

1. Run the Visual Studio Build Notification application.

From C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\BuildNotificationApp.exe

 

2. Select the build

clip_image004

Figure: Select the Build that you just created and click OK

Start a Build

clip_image005
Figure: Go to Team Explorer | Builds. Right click on the Build and choose Queue New Build

 

clip_image006

Figure: When the build is complete, you will get a green or red icon indicating the status.