Running A Remote NuGet Feed

Following the NuGet docs site to setup a NuGet feed won’t get you one if you follow it (as of Jun 30). There’s one missing step in that doc (it’s here at the end of this one), but I’ve added all the steps below so you can walk through for yourself.

I’ve also created a fork and submitted a pull request to include the missing step, so the online docs should be updated soon.

Setting Up for Eventual Deployment

Create a new site in IIS. 

Edit the Application Pool and make sure the .NET Framework is set to version 4.

image

Get Your Project Together

Open Visual Studio in Administrator mode (right-click, Run as administrator).

Create a new, Empty Web Application project.

Open the Package Manager Console and at the PM> prompt, type

image

Let NuGet do it’s sweet, sweet, beautiful magic.

Right-click on your solution and select Open Folder in Windows Explorer. 

image

There is a packages directory there that has a half-dozen packages installed for you.  Go through your packages directory, and copy the .nupkg files to the clipboard, then return to Visual Studio and paste them in the Packages folder under your project. It only takes a moment to add a few. Again, you’re copying all the .nupkg files from your solution (file system) to the Packages directory in your project (Visual Studio).

image

Press CTRL+F5 and run the site. Click on the packages link and verify that your packages are in the feed.  Sweet.

Publish Your Feed

Close the browser and return to Visual Studio.  Select the project in Solution Explorer, then click on Build –> Publish from the menu.

image

This is why we ran as admin…we need to deploy to our local IIS.  If you’re logged in as admin you should get a successful publish.

Navigate to your site on localhost.

image

Unfortunately, at this point…our feed is empty. Click on the packages link:

image

Lamesauce.  Okay…so now to fix it. 

The Missing Step

Go check your packages directory to the published site.  Empty, ain’t it?

No worries…you have two choices here:

  1. Paste all your packages into the site directory (where IIS is looking)
  2. Change the build action on all your .nupkg files to “Content” and republish your site.

 

I was originally under the assumption that it was a permissions problem or a DLL version problem due to a couple of comments out on the interwebs.  When I had 5 minutes to look at things here this afternoon, it was quickly clear as to what the problem was. 

Hope this helps!

Do Your Like a Good Game of Rock, Paper, Scissors? In the Cloud?

My head is in the clouds.  I just played the most intense game of Rock, Paper, Scissors ever.  It was a “best of 1,999” format.  And my arm didn’t even get tired.  In fact, I played about 40 rounds of it, with 8 different competitors and by the end I was winning every match.

Folks, what I’m talking about is the Rock, Paper, Azure competition that Microsoft is hosting right now, and if you are in the least bit interested in the cloud this is a relaxed, fun way to get yourself started.  Plus: free t-shirts!  Learning cloud development and a free t-shirt? How can you not?!

What It Is

The game is hosted on the Azure platform and every participant has a chance to create an entry bot – the “player” used by the game engine to play out  your game.  You play every other registered player.  Each game is played to 1,000 wins, and the first to 1,000 gets 3 points to their name.  There are leaderboards, prizes and at the end of the practice rounds a Grand Tournament for the ultimate bragging rights.

What You’ll Really Learn

Now, this game isn’t so much about cloud development as it is to walk developers through the process of deployment.  The “bot” project – used to create your player in the game – is set up for you as part of the download.  All you have to do is write a bit of c#, vb or f# to determine what move your bot will play next, and you’re off the races. 

There is one catch: your bot can only be entered into the competition if it’s hosted in Azure.  Said another way, you have to deploy to the cloud to enter and win.  To get your Azure account (free trial) you can visit the getting started page for the contest.

Having Some Fun

Brace yourself, because you may not know this: RPS is serious game.  Seriously.  There are international organizations, widely accepted rules and derivatives, annual competitions with big prize money and the works.

In light of all this seriousness, you can still have fun with this competition.  You just have to remember that a “random” throw isn’t going to get you anywhere.  In my testing, even a bot that favors a particular throw does better than a random bot.

(Really) Getting Started

Once you get through the guide and get yourself running, you’re going to want to get some bots in your local Azure emulator so that you can test strategy.  If you’re only working in one language, simply remove the other projects from your solution (I work in c#).

Other bot developers aren’t going to give you their bots, but you can easily create some pseudo-strategies to make sure you don’t fail in the simplest of cases.  Point in case: an early version of a bot I was making won every time against every bot in my lab, except the bot that through mostly scissors.

So, let’s get started.

  1. Open the BotLab solution with Visual Studio running as Administrator and run the app.  While the Azure fabric is getting going, we’ll create some bots to unleash fury in the lab.
  2. imageOpen the MyBot solution in a new VS instance (you don’t need to be admin here). Build the app by pressing Shift+Ctrl+B. Right-click on the project folder and click “Open Folder in Windows Explorer”.  Here, along with your bin, obj, and properties folders, create a “bots” folder.
  3. Now, back in Visual Studio, imageopen the Properties of your project and navigate to the Build Events tab.  We need to add a new post-build event similar to “copy $(TargetPath) $(ProjectDir)\bots\”.  This will copy our built bot to a bot folder every time we build one.  We’re using this as a technique to build a quick army of bots. Every time we build, our target dir gets cleared, so we want to have a bit of a locker to keep them penned in and out of harm’s way.
  4. Next, go back to the Application tab inside your project properties.  Change the Assembly name to “ScissorBot”.  When you build your app again (Shift+Ctrl+B) your ScissorBot dll will be copied to the bots folder.

Now we’re ready to get some bots together.

Building Some Bots

Go to the MyBot class and you’ll see that we inherit from IRockPaperScissorsBot, which ultimately inherits from IBot.  We have but one responsibility to fill with this contract: MakeMove.

We want to create some bots that will just favor certain moves.  This isn’t likely a strategy that another bot maker will employ, but if by chance they do favor a move, you’ll know that you can fare fairly well against them.  Wow. I don’t think I’ve ever used “fare” and “fairly” side be each before.

Replace the meat of your MakeMove function with the following code:

image

This little guy has an affection for sharp things and will throw scissors better than half the time.  Build your app and make sure the DLL is in your bots directory.

Now do the following:

  1. Change the Assembly name in your project settings to PaperBot.
  2. Modify the above code above to favor paper.
  3. Build your app and make sure PaperBot’s in that bots folder too.
  4. Do steps 1-3 over for RockBot.  Queue epic guitar solo.

 

Now you have some competition…they’re not great, but they’ll give you a fighting chance if your bot can survive against them.

Testing out the BotLab

Now we get to see how things play out. Pop back over the browser that is running the BotLab. You’ll see a window there with a few sample bots in inventory.  Use the form there to select and add the bots you’ve just created. It should look something like this when you’re done:

image

Next, click the “Start Battle!” button and let the rain fall. All bots in the lab will square off against each other and the results will be tabulated for you.  By the way, note how far down the list the Random bot is.

image

Clicking on a bot brings up the game log in a little modal dialog that lets you see how things transpired.  In this way, you can review the details of the way you played and how you won (or lost) as well (or as badly) as you did. This is how I came to discover that when one of my bots was getting into trouble, it panicked and started throwing water balloons.

I do want to point out an interesting thing here that is part of the game rules and critical to winning:

image

Notice that after BigBang has gone up 10-0 there are two draws (ties) and then PaperBot wins?  The points accumulate through a tie, so PaperBot was awarded three points when Scissors cut Paper.  Which brings us to some strategy.

Some Strategy

What if you knew that the points were accumulating?  Well you can. Your class, one instantiated, is stateful for the duration of the game. You can have member fields that hold values and therefore can track some things to gain an advantage.  Using this tip from the RockPaperAzure blog, we are able to build a Dynamite-favoring bot that simply OWNs the competition.  Rename your assembly and modify your bot’s class to the following:

image

Now we’re combining strategies: if we have a tie on the line worth three or more points we’re going to throw Dynamite. If not, we’re favoring a throw (paper).  Now when we check our results we see the following:

image

DynaBot wins every time I run this.  The one mark in the loss column is always against ScissorBot.

Time for some smarts!

Making the Bot a Little Smarter

So, here’s the deal: I want to have a sporting chance in this competition, but I want to throw out some ideas as to approaches you can take to help you win too.  I’ll give you the ideas (and some code) and you work out the details.  I’ll help you with the code once the competition is done Smile.

The first thing I did was start to keep track of the last 20 moves of the other player. This is easily done by adding a Queue<Move> to our class.

image

Next, I moved my _pointsOnTheLine logic to an UpdateStats method.  That’s also where I’ll keep track of the _lastPlays Queue.

image

Now I have the ability to do a bit of analysis on the opponent’s moves.

Next, I wanted an easy flag to see if I was currently winning in the game.  This lets me switch between offensive and defensive strategies. I started by creating a variable that allows me to just check a bool anywhere else in my code.  This is a class-level field.

image

Then, in my UpdateStats method, I do the check:

image

Finally, I wanted a way to set up a playbook.  I created a series of List<Move> collections that easily let me pick my next few moves.  Some examples of that are as follows:

image

To use these moves, I simply created a class-level queue…

image

…and test to see if it’s empty. If it is, I can load up a few plays rather easily…

image

Get it?  If I’m “WINNING”, I foreach over “the Avalance” and add them to the queue.  Finally, I can pop my results back off the queue easily and make plays from my populated playbook:

image

The last thing I did was to create a simple function that returns the throw that beats whatever you pass in.

image

Part of the stats I keep watching for a mirroring strategy (where the other bot just plays whatever I just played).  Now I can easily throw back at the mirror and guarantee a win:

image

Now, obviously I’m not giving away all my secrets here, but you can use strategies similar to this to get the ball rolling.  I wrote three really good bots with different strategies…in a list of 20 bots I created, one of these three always won.  Now, I’m working on the bot that can beat all the bots in my arsenal.

Next Steps

All that’s left to do is deploy your bot to the cloud. Head over to the game site and watch the video on deployment; that is, after all the point of this game: to see how easy it is to deploy a project to the cloud.  When you’ve finished deploying, you can then enter the contest and start kicking bot butt!

Good luck!

HTML5 Boot Camp in Winnipeg

I just had the privilege and pleasure of speaking at the HTML5 Boot Camp Extravaganza in Winnipeg at the Delta Hotel.  The event was hosted and organized by Microsoft Partner of the Year Imaginet and sponsored by Microsoft.  There were prizes for all attendees as well as breakfast, lunch and snacks…not to mention great conversation!

Post-Camp Connection

You can get in touch with any of the presenters through the links below:

David Wesst – blog, twitter Kelly Cassidy – blog, twitter Tyler Doerksen – blog, twitter and me!  James Chambers – blog (you’re already here!), twitter

Hey, what was that site where….?

We covered a ton of content and flew through all kinds of territory.  Here’s some of the links, tools and technologies we covered:

There’s a ton out there, but if you’re looking for something in particular don’t hesitate to ask. 

Thanks, Winnipeg, for participating in this event.  We had 50 folks of all levels of experience in the room, which made for some great questions.  I really enjoyed the format – tandem presentations with lots of dialogue – and hope that you guys did too.

See you at the SIG meetings in the ‘Peg over the next few months!

NuGet Reaches 1,000,000 Package Downloads

The .Net community is beginning to embrace open source software.  For years, we’ve struggled to find a way to elegantly share and use other people’s code – and ultimately leverage billions of lines of code – in a way that fits into our existing toolset and workflow.

NuGet has begun to solve those problems, and now, it’s here in force.

Adoption rate is beginning to grow, new projects are being started with NuGet in the kit and people are beginning to see that there are great gains to make on existing projects as well.

Now It’s Really Real

This morning, NuGet reached a significant milestone, marking it’s official arrival: 1,000,000 package downloads.

image

Why is this significant?  Well, for starters, it means that it’s no longer just folks messing around. People are using it.  It’s rapidly approaching 2,000 packages and the diversity is good, if not great.  I’ve got three projects already in production that I’ve added packages to – not including dependencies – and I would venture a guess that others have as well.

The hourly downloads have been trending upwards (save a few spikey days).  The 1,000,000 downloads in and of itself isn’t the significant part, but it’s a beacon of what’s happening.

So, what is happening?  Well, as developers on the .Net stack, we’ve finally got a tool that makes reusing code efficient.  We have the ability to consume and update packages (and with the latest version of NuGet we have the ability to define constraints for updates, as well). We can leverage the great work of other devs.  We have open source tools to publish open source libraries, helpers, templates, extensions and more. We can package up pre-configured trials of commercial products, wrap licensing around our content, or give it all away.

Because of all these pieces coming together, we are able to move at our own comfortable pace with no barriers to entry. We can choose to be consumers or contributors to this space.

And NuGet is the critical, now widely-used, cog in the wheel to make it happen.

More to Come

While NuGet is already fantastic in new projects, existing projects that need some love and smaller enterprise projects, it’s tough to get it fully going in enterprise scenarios.  This is the next focus for the folks working on NuGet, and one they’re taking seriously.

Improvements to critical features like NuGet.Server publishing, adding support for authenticated sources, and facilitating CI build products outside the MS domain are all in the works.

Now It’s On You

For anyone who doubts that you can influence this product, you’re wrong in two ways:

  1. It’s easy to post problems you run into. If you find something that doesn’t tick the way you like it, post it on the project site. If others are running into the same thing, they will vote on it.  If there’s enough traction, it’ll get promoted to a work item and someone will implement it.
  2. You can implement it. If it’s a feature/bug/workflow issue that’s really got you hemmed in, you might as well quit yer bitchin’ and get to work. Fork the source, post the patch and request a pull.  Done.  And then you can go to sleep a less horrible person.

And, once you get into this and you find out how easy it is to share code, you might get the inkling to share some of yours.  It’s free and easy to publish to the NuGet site, and you can do some pretty interesting things with your packages during the execution of you installation or initialization scripts.

Your Turn

There are so many examples out there of great pacakges ready to use for all kinds of project types and scenarios. There is simply no reason for a developer to put off learning how to use this tool, especially because it’s going to take you all of 10 minutes. Folks, that is less time than it will take you to go and find code that you want to use and get it integrated into your project.

Though some folks have been using it for months, others have been hesitant to explore it enough to fully understand what it can do for them. Hopefully, hitting this 1,000,000 package mark will wake them up.

After all, the only effort required to try NuGet in a safe environment is this:

File –> New Project

So, go on. I’ll wait here while you do it.

NuGet Presentation Follow-Up

I received an email from one of the folks at the NuGet talk last night asking about some of the packages we had a look at and I said I’d post a quick list, along with a few others that were handy to have around.

  • jQuery, jQuery.UI & jQuery.Validation – these are all in the new MVC3 templates by default, but you can use the Package Manager Console in VS2010 to update them to the latest version (along with the vsdoc file).  You can also easily add them to existing projects.
  • EntityFramework (EFCodeFirst) – with the CodeFirst bits now built into EntityFramework we are able to quickly and easily define POCO classes and let the framework do the heavy lifting…kinda like scaffolding for databases.
  • Modernizr – old browsers suck, but Modernizr makes them suck a loss less.  It also exposes the presence of all the modern functionality of the client’s browser (missing or not) via boolean values, allowing us to degrade our functionality gracefully.
  • Glimpse – What? Client side debugging for ASP.NET MVC? Ohhh yeah. Glimpse lets you dive deep on both sides of the request and response, letting you get a ‘glimpse’ of what happened when you made a call.  Support for MVC, Ajax now, and more coming soon.
  • Pluralizer – A simple but elegant solution that lets you contextually set up strings to be pluralized based on the count of the collection you pass it.
  • jQuery.ie9ify – Helps you add site pinning features and set up things like notifications, icons and the like.  A must have for installed user bases (like intranets) where you can standardize on a browser, or where your user base is large enough that adding extras for those on IE9 is worth your time. 

Also, Scott Hanselman has started an NPoW – “NuGet Package of the Week” – posting series on his blog. You can check that out here.

Finally, I fielded a couple of questions about init, install and unistall scripts when creating your own packages for NuGet.  Here’s my post on script tips and PowerShell commands commonly used in other packages.

Thanks again all for coming out!  See you June 24th at HTML5 Fest in Winnipeg!

Introduction to NuGet – My Talk at Prairie Dev Con 2011

Another great session today with some good questions and some great conversation afterwards.  Thanks peeps!

Here’s some great resources to get you plugged in with NuGet and to help take those first few steps:

 

You can also follow the NuGet conversation on Twitter (#NuGet), or join in the StackOverflow.com chat room on the subject.

And as always, feel free to send me a note with any questions you may have.