Scott Hanselman

Git support for Visual Studio - Git, TFS, and VS put into Context

January 30, '13 Comments [76] Posted in Open Source | VS2012
Sponsored By

VS loves GitDogs and cats, living together...mass hysteria. This classic Ghostbusters quote is used by many geek-types (myself included) whenever something crazy or unexplained happens.

Today Brian Harry from Microsoft announced Visual Studio 2012 Update 2 (or VS2012.2) the latest quarterly update. That's interesting, but it's the announcement of Git integration with Visual Studio and TFS that is really significant, in my opinion.

TFS in the Past

For me personally, the term "TFS" has historically meant "big scary corporate centralized source control" while Git has meant "small scrappy lightweight distributed source control." TFS meant connected (ZOMG, I can't code on a plane!) and Git meant occasionally connected (ZOMG, I don't know what rebase means!).

However, I learned that Team Foundation Server (TFS) isn't just source control, it's a whole bug tracking, change management, application lifecycle management (ALM) suite. Source control is one pluggable piece.

On the other hand, Git isn't just source control either. Git has become effectively FTP for code. I use Git to deploy most of my sites as mentioned in this blog post where have a site automatically deploy as I publish to GitHub. Git is also used as an interchange tool to move code between different SCMs, and it's supported everywhere, although Git tooling support on Windows has historically lagged behind.

Things start getting interesting if one could have Git as their source control with Team Foundation on the backend for ALM tools. Now Visual Studio 2012 supports both centralized version control and distributed version control in a cleanly integrated way.

Open Source - Working WITH Git

So Visual Studio is integrating Git. Suspicious? This might sound like the "embrace and extinguish" Microsoft from the 90's. Arguments can always be made, but I'm a coder, so I look at the code.

If you dig into the GitHub repo, you can see at least five Microsoft employees (phkelley, ethomson, jamill, martinwoodward, congyiwu) submitting pull requests to the libgit2 GPLv2 library (GPL'ed with a linking exception), including direct commits from phkelley who has earned that access. They work with all the libgit2 committers including Vicent Marti from GitHub. The team has been doing this for months and months. In fact, if anyone was paying attention to commits and pull requests they would have seen this whole convergence coming down Main Street.

 Libgit2 is a great library with a lot of attractive features (from their site):

  • written in portable and standards compilant C
  • completely multi-platform: Windows, Linux, Mac OS X, xBSD and more
  • compiled natively under all platforms (yes, even MSVC on Windows)
  • re-entrant, with sane error handling
  • designed with a solid and consistent API
  • available as bindings for all major scripting language

You can see below that this new Visual Studio Git support actually ships git2 and libgit2sharp and integrates it via a VSIX (Visual Studio Extension).

git2 and libgit2sharp

Visual Studio and Git

This Git support will require VS2012.2 (currently in preview) so you'll need to install that first, then get the VSIX. You'll be able to update both when VS2012.2 is released, and the Git VSIX will continue to update automatically via the VS Gallery. It's a full source code provider for VS so you can use it to do most anything without leaving VS, or you can hang out at the command line and use it for a visual reminder as to the state of your repository.

One file added, one file modified

You can see what will be included in a commit and what's excluded:

Commits to git, both included and excluded

You can make new branches, check them out, as well as see what branches are published or unpublished.

branching in Git in VS

In this screenshot you can can see Keith and I going back and forth on a Pull Request. Note that I've allowed VS in Git Settings to go to Gravatar and get a picture of Keith.

Git History and Gravatars in VS

Here's a screenshot of me managing a recent merge conflict with the VS diff editor then committing the change and pushing it to GitHub. All the diffing is integrated as you'd expect it to be, and available via a Right-Click.

Diff/Merge Conflict within Visual Studio with Git Support.

What's next?

I'm told that while this Git integration is currently in preview. The team work on a three week sprint cadence so expect to see frequent updates.  The plan is that in a future release Git will come baked in to all editions of Visual Studio - including Express. Perhaps we'll see PoshGit command line integration/support and maybe better support for the Git command line within the NuGet Package Manager Console inside VS.

Git within the NuGet Package Manager Console

Hosted Team Foundatation Services - Git or TF Version Control

You can use VS Git support with all your Git projects by just opening projects. It's just Git. I am pushing branches to CodePlex, to GitHub and other Git repos. I'm also continuing to use my other Git tools interchangeably, as I like.

Some teams I work on use Git, others  use TFS. It depends on the team, the company and the goals. Some teams have servers they run themselves, some use hosted Git services at BitBucket or GitHub. There's also hosted Team Foundation Services.

For teams, you can go up to http://tfs.visualstudio.com and sign up for a account and get 5 users for free. You can choose either Git or Team Foundation Version Control (TFVC) as the source provider and use all the Team Foundation agile, scrum or other templates for your ALM tools. I've actually got https://hanselman.visualstudio.com now for my "team." There's issue tracking, backlogs, scrum templates, a Kanban board, burndown charts and more. You can use the web app or use the Visual Studio integration to manage your bugs and backlog. There's even cloud build servers in preview.

TFS online kanban

I've said this before, but I'll say it again. This kind of open source collaboration stuff is why I went to work for The Man. Playing well with others, competing well while using and promoting open source. I don't think every group at Microsoft "gets" it yet, but it's cool to see the open movement spreading. I'm looking forward to using these Git tools for Visual Studio, as well as GitHub for Windows and PoshGit.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Plex is the media center software ecosystem I've been waiting for

January 30, '13 Comments [51] Posted in Musings
Sponsored By

Example Plex UI showing a MovieI've blogged about my Synology 1511+ NAS before and how I have added a few things to it like CrashPlan Cloud Backup and even discussed it on my podcast. When you have a headless server in your home, you're always looking for ways to utilize it.

I've long had shares like \\server\movies and \\server\photos for accessing family files from laptops around the house, as well as streaming home videos to the Xbox or PS3 via DLNA. I talk about how I streamed things in 2008 in this "Geek Developer Cribs" video.

More recently, I've tried using a Raspberry Pi as an ersatz media player along with AirPlay to throw videos from my iPhone/iPad up on the big screen.

Fast forward to 2013 and I've found Plex. It's amazing.

*pause for gravitas*

Plex is a whole ecosystem that is extremely polished, easy to setup and available on every device you'd ever want.

There are two main heavyweights in the media server space. Plex and XBMC. I've used both extensively. Plex is starting to monetize their platform while XBMC has more of a hacker/enthusiast vibe. You can accomplish most all you'd ever want with both, but at this point in my life, I'm OK with throwing a little money at the problem and I have happily given Plex my $30 for their UI polish and their new PlexPass feature that unlocks some goodies. I'm totally happy to pay a company for value and Plex provides extreme value. I'm choosing Plex.

What's Plex and Why?

So what is it? Plex is media server software that you have running all the time at home. Then, Plex is client (or clients) on your device (or devices) that you run to access your stored media. Most importantly, the killer feature is that Plex will transcode your videos depending on your device and network. That means that Plex will use the power of your server at home to dynamically squish videos so that they still play smoothly on your smart phone over 3G or your tablet over hotel Wi-Fi.

You install the Plex server on any system you have. You can run it on Windows, Mac, Linux, but that's not all. You can also put Plex on your Network Attached Storage appliance (NAS) like I have with my Synology. (For Synology systems, I strongly recommend a faster Intel machine, not the little ARM ones.)

Plex will also get art, descriptions, and generate thumbnails for your media. You might think this is a little thing but it really makes your whole setup feel more pro. It's also very clever. All you need to do is name something "title (year).ext" for movies and "show name/whatever SxEy.ext" (where x and y are season and episode) and Plex does the rest.

Plex Clients

There are Plex clients for iOS, Android, Windows Phone 7 phones, as well as for Windows 8 and Surface. On other Macs or PCs you can use Plex Media Center, and there's also Plex for Roku, LG TVs, Samsung TVs, and Google TV. It's magical.

Here's an example screenshot of the Plex Windows 8 client:

Plex example on a Microsoft Surface RT with Windows 8

Here's the VERY competent and recently updated web client. You can see my home movies in there with a Year filter. Here's a fishing trip from 2010.

Plex for Home Movies

Plex keeps track of the devices that have accessed your library. You can see some of my devices below.

Plex has a list of devices atached

Here's my home movies via the Plex iPhone app on the left, and an example screenshot showing movies on the right. You can add other "channels" for web video like CNN, Funny or Die, and more. There's even a bookmarklet you can put in your browser toolbar to add video to your queue for later. Great for those long Vimeo documentaries you'll never watch.

Plex Libraries on iPhone Plex movies on iPhone

The PlexPass I bought adds a feature called PlexSync that squishes content on the server then transfers the custom-transcoded result to your device for offline viewing. Super useful for airplanes and offline viewing.

Accessing Media Remotely with Plex

Plex really shines when you can access all your media from a hotel on your tablet. Forward a port, publish your server with your Plex username and you're set, in theory.

Port Forwarding is a hassle, but it's part of life if you want to really exploit your home internet connection. If you can successfully forward a port (or if Plex and use UPnP to ask your router to forward it for you) then you may be able to access your home movies from afar!

Once you've logged into the MyPlex service with your username, it will keep track of your servers and devices and let you access them when you're not on your home network (not on the same subnet.)

Plex with a port forwarded

I have an Actiontec Router, so be aware that every router is different, but the general idea is that you've got a Plex server running INSIDE your house and listening (always) on port 32400. That port - inside the house - never changes. What you want to do is to "forward" that port to some other port on the outside.

Here's what my Port Forwarding rule looks like in the list of rules. Note that this is a little confusing because I thought the arrow would point the other way, but the you would read this as "port 32400 on 192.168.1.18 is available outside at port 11366."

image

If you have trouble with high numbered ports, as I've heard some folks had, try mixing it up and be patient. None of the ports over 30000 worked for me but a lower number (not too low!) did work. Here's the form I filled out on my Router's admin page. Your mileage may vary, again.

Your settings are generally:

  • Source Ports, ANY.
  • Destination Ports, *the number you picked or that Plex picked for you*
  • Forward to Port, always 32400

A common mistake is putting your custom port number in source or destination. Remember that "Source Port" is their port, not yours.

image

Again, for lucky folks with new routers, Plex will handle all this hole punching for you. It not, open two browsers, one for Plex and one for your router and try different values. Plex will let you know when it's "published" your server. The MyPlex service will then associate your user name with your home's IP address and port, allowing you to access your home movies when elsewhere.

Conclusion

I really think Plex is something special and I encourage you to think about how Plex could become a part of your media server solution. I am not affliated with Plex in any way. I just think they are the cat's pajamas.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Integrating Mozilla Persona with ASP.NET

January 24, '13 Comments [13] Posted in ASP.NET | ASP.NET MVC | ASP.NET Web API | Open Source
Sponsored By

imageASP.NET and Web Tools 2012.2 is coming soon, but one of the features of ASP.NET that you can use TODAY is support for Google, Twitter, Microsoft and Facebook logins out of the box with ASP.NET templates. I show how OAuth in ASP.NET works in this 5 minute video. We are also continuing to look at ways to make membership easier in coming versions of ASP.NET like including things like this out of the box.

Mozilla has a new identity system called Mozilla Persona that uses browserid technology to let users log in to your site without creating a custom login or username.

I wanted to see how Persona would work in ASP.NET and hacked up a prototype (with some sanity checking from my buddy Hao Kung). There's some comments and some TODOs, but it's a decent proof of concept.

First, I read the Mozilla Persona Developer docs and got their fancy button CSS, then added it all to the ExternalLoginsListPartial view.

The Magic Persona button is very blue

The ProviderName check is there just because all the buttons look the same except the Persona one. A better way, perhaps, would be partial views for each button, or a custom helper.

@foreach (AuthenticationClientData p in Model)
{
if(p.AuthenticationClient.ProviderName == "Persona") //ya, ya, I know.
{
if (!Request.IsAuthenticated) {
<p><a href="#" class="persona-button" id="personasignin"><span>Sign in with your Email</span></a></p>
}
<!-- The CSS for this is in persona-buttons.css and is bundled in in BundleConfig.cs -->
}else{
<button type="submit" name="provider" value="@p.AuthenticationClient.ProviderName" title="Log in using your @p.DisplayName account">@p.DisplayName</button>
}
}

After the login dialog, an AJAX call to do the login locally posts data to my new PersonaController. except it doesn't POST its assert as JSON, but rather as a simple (standard) POST value. That is, just "assertion: longvalue."

function onAssertion(assertion) {
if (assertion) {
$.ajax({ /* <-- This example uses jQuery, but you can use whatever you'd like */
type: 'POST',
url: '/api/persona/login', // This is a URL on your website.
data: { assertion: assertion, },
success: function (res, status, xhr) { window.location.reload(); },
error: function (res, status, xhr) { alert("login failure" + res); }
});
}
else {
alert('Error while performing Browser ID authentication!');
}
}

ASP.NET Web API doesn't grab simple POSTs cleanly by default, preferring more formal payloads. No worries, Rick Strahl solved this problem with this clever SimplePostVariableParameterBinding attribute which allows me to just have string assertion in my method.

Armed with this useful attribute (thanks Rick!) my PersonaController login is then basically:

  • Get the assertion we were given from Persona on the client side
  • Load up a payload with that assertion so we can POST it back to Persona from the Server Side.
  • Cool? We're in, make a local UserProfile if we need to, otherwise use the existing one.
  • Set the FormsAuth cookie, we're good.

Here is the work:

[SimplePostVariableParameterBinding]
public class PersonaController : ApiController
{
// POST api/persona
[HttpPost][ActionName("login")]
public async Task<HttpResponseMessage> Login(string assertion) {
if (assertion == null) {
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
var cookies = Request.Headers.GetCookies();
string token = cookies[0]["__RequestVerificationToken"].Value;
//TODO What is the right thing to do with this?

using (var client = new HttpClient()) {
var content = new FormUrlEncodedContent(
new Dictionary<string, string> {
{ "assertion", assertion },
{ "audience", HttpContext.Current.Request.Url.Host }
//TODO: Can I get this without digging in HttpContext.Current?
}
);
var result = await client.PostAsync("https://verifier.login.persona.org/verify", content);
var stringresult = await result.Content.ReadAsStringAsync();
dynamic jsonresult = JsonConvert.DeserializeObject<dynamic>(stringresult);
if (jsonresult.status == "okay") {
string email = jsonresult.email;

string userName = null;
if (User.Identity.IsAuthenticated) {
userName = User.Identity.Name;
}
else {
userName = OAuthWebSecurity.GetUserName("Persona", email);
if (userName == null) {
userName = email; // TODO: prompt for custom user name?
using (UsersContext db = new UsersContext()) {
//TODO: Should likely be ToLowerInvariant
UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == userName.ToLower());
// Check if user already exists
if (user == null) {
// Insert name into the profile table
db.UserProfiles.Add(new UserProfile { UserName = userName });
db.SaveChanges();
}
}
}
}

OAuthWebSecurity.CreateOrUpdateAccount("Persona", email, userName);

FormsAuthentication.SetAuthCookie(email, false);
return new HttpResponseMessage(HttpStatusCode.OK);
}
}
return new HttpResponseMessage(HttpStatusCode.Forbidden);
}

[HttpPost][ActionName("logout")]
public void Logout() {
WebSecurity.Logout();
}
}

You click Sign in and get the Persona login dialog:

Animation of the Persona login

At this point, you're logged into the site with a real UserProfile, and things with ASP.NET Membership work as always. You can add more external logins (Twitter, Google, etc) or even add a local login after the fact.

You are logged in!

As I said, this isn't ready to go, but feel free to poke around, do pull requests, fork it, or comment on how my code sucks (in a kind and constructive way, because that's how we do things here.)

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

You are not your code.

January 24, '13 Comments [60] Posted in Musings
Sponsored By

Photo by Ed Yourdon used under CC http://flic.kr/p/55YkTjI'm a lousy programmer. However, I am less lousy than I was last year, and significantly less lousy than I was 20 years ago. Even still, there's a lot of crap on my GitHub and Bitbucket repos - but I'm totally OK with it.

I am not my code.

Yes, it's a reflection of me, but just as I am not my 8th grade English paper or my college entrance scores, I am not the code I wrote last year. Feel free to tear it apart. I will be better this year.

Your code does affect your reputation, truly. It is possible that you are a bad programmer. You'll never know until someone better sees it. Sharing your code may find you a mentor, or get a teacher's critical eye and help fixing it. Pull requests can't happen until you've shared your code.

I'll steal clone David Copeland's summary of this week's "social coding scandal."

So, someone shared some code on Github and some classic developer snark rolled in. And then there were some apologies about it.

The irony is, of course, that the code in question was actually rather useful, didn't require idiomatic command line knowledge, and, most importantly solved someone's problem.

Don't let any of internet drama stop you from writing on your blog or from contributing to open source. In fact, I would encourage you to release some source code right now. Go find some, I'll wait.

Have a code garage sale. One person's junk is another person's treasure.

"I can't believe I found code that does exactly what I needed."

"Wow, I learned a lot from that algorithm."

Feel free to share some of your lousy code in the comments, and we all promise not to judge you. Feel free also to share some awesome code if that makes you happy, as long as you share.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Cancer

January 22, '13 Comments [273] Posted in Musings
Sponsored By

What would your list look like on the day of your second cancer surgery?

Cancer. My wife has, or hopefully by now, had Cancer.

See that To Do List in the picture at the right there? That's how awesome my wife is. This is her list for the day of the surgery that would remove organs and important stuff and lay her up for many weeks.

Pack.
Cut toenails.
Paint toenails.
Clean bathrooms.

God forbid one should enter a major surgery with a messy bathroom or unkempt toenails. This is just how my wife rolls and I think she's awesome.

It's been a crazy several months since this Cancer was picked up by the lab during a routine check up. This was then followed by a PET scan, a surgical procedure and then another more major surgery.

School was starting soon for the kids, my wife is embarking on a new career and had classes all week. I needed to prep and attend the BUILD conference, be in the keynote, host 4 hours of live TV, plus deliver two talks. Just to make the point - life was happening when Cancer happened.

Let me tell you, Cancer is damned inconvenient when you're trying to live your life. It blindsided us completely but we continued to manage all our commitments while our little boys played and danced even though "mommy had a tummy-ache."

As of today there will be checkups every 3 months for some years. We think it's all handled and gone but now we wait. We wait five years, in fact, because that's when Cancer People graduate and get the "cancer-free" label.

I asked my wife when we could get her an "I beat Cancer" T-Shirt. She said that it's a little early. I may just buy a "She beat Cancer ->" shirt for myself and stand next to her.

Negative for Tumor - pathology

They took so much out of her it hurts me to think about it. Weeks later, dressed to the nines for the family Christmas party but with a hidden catheter bag on her leg, I've never been prouder of her strength and patience. Two months into various side effects while she is at a low point I am reminded she is only human, and as fragile as I. We're both a mess but we're together.

She's handling this whole thing with grace and aplomb and I'm so proud of her. If I could have taken it away and been the one that had Cancer (I always see the C as a Capital C when I say Cancer in my head) I would have.

The boys don't know anything about this, but perhaps 5 years from now we'll tell them that Mommy beat Cancer when they were younger. Even better if in 5 years medicine will find a way to keep Cancer from needing a Capital C.

Why am I telling you this, Dear Reader? Because we found this on a regular checkup. Please, get whatever regular screenings are appropriate for your age and gender. If you haven't been to the doctor in years, go today. These things are easier to beat when they are found early.

Let's hope that 2013 is an easier year.

UPDATE: A number of kind people have asked about funds and bills. We are fortunate to have insurance and will be able to pay our bills. If you want to help, please read Troy Howell's family's story and donate. He will die soon and they are raising money to cover the funeral costs and medical bills. http://www.troyhowellcancerfund.com

UPDATE #2: My wife and I have taken 6 months of our personal audio Cancer Diary and turned it into an episode of This Developer's Life. We hope you enjoy it.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.