Scott Hanselman

NuGet Package of the Week #3 - PhoneyTools for Windows Phone 7

March 21, '11 Comments [0] Posted in NuGet | NuGetPOW | Silverlight | WinPhone
Sponsored By

image Have you implemented the NuGet Action Plan? Get on it, it'll take only 5 minutes: NuGet Action Plan - Upgrade to 1.1, Setup Automatic Updates, Get NuGet Package Explorer.

The Backstory: I was thinking since the NuGet .NET package management site is starting to fill up that I should start looking for gems (no pun intended) in there. You know, really useful stuff that folks might otherwise not find. I'll look for mostly open source projects, ones I think are really useful. I'll look at how they built their NuGet packages, if there's anything interesting about the way the designed the out of the box experience (and anything they could do to make it better) as well as what the package itself does.

PhoneyTools includes new controls, classes and techniques for Windows Phone 7

I've heard that since NuGet is bundled with ASP.NET MVC that some folks think it's just for Web Development. This weeks package is one for Windows Phone 7. You can make packages for pretty much whatever you like. Looks like there are already 26 libraries that are tagged with "phone" on the NuGet site.

These tools are by Shawn Wildermuth and include a bunch of useful classes and controls that make Windows Phone application creation easier.

image

I'll fire up Visual Studio with Windows Phone Tools that I downloaded from http://create.msdn.com. (See how clean my Visual Studio looks? Yours can be tidy as well.)

My Totally Nothing Windows Phone 7 App

You can see that I created a totally basic do-nothing Windows Phone 7 application and that the NuGet Package Manager Console is docked at the bottom.

I type:

PM> Install-Package PhoneyTools
'SilverlightToolkitWP (≥ 4.2011.2.1)' not installed. Attempting to retrieve dependency from source...
Done.
Successfully installed 'SilverlightToolkitWP 4.2011.2.1'.
Successfully installed 'PhoneyTools 0.5'.
Successfully added 'SilverlightToolkitWP 4.2011.2.1' to WindowsPhoneApplication2.
Successfully added 'PhoneyTools 0.5' to WindowsPhoneApplication2.

Looks like PhoneyTools brought in the SilverlightToolkitWP as a dependency. If I want to poke around, I can double click on the NuPkg (which is associated with the NuGet Package Explorer you can get here with ClickOnce) and see what's going on.

NuGet Package Explorer - PhoneyTools.0.5 (11)

Looks like he's got his project's assembly as well as an install.ps1 and uninstall.ps1 in the tools folder. What's in there?

References to assemblies are added by convention automatically

The install.ps1 and uninstall.ps1 run automatically when you, ahem, install and uninstall. He's got a check for the version of NuGet in there (that looks like it was copy/pasted from one of my packages) as well as a manual stop to add a reference. That extra line for adding References is not needed. I know Shawn so I'm sure he'll be fine with me using this as a teaching moment as it's not 100% obvious how this new stuff works.

param($installPath, $toolsPath, $package, $project) 

if ($host.Version.Major -eq 1 -and $host.Version.Minor -lt 1)
{
"NOTICE: This package only works with NuGet 1.1 or above. Please update your NuGet install at http://nuget.codeplex.com. Sorry, but you're now in a weird state. Please 'uninstall-package PhoneyTools' now."
}
else
{
$project.Object.References.Add("AgiliTrain.PhoneyTools"); #don't need this
}

It might seem intuitive to add the reference manually, but assemblies that are in the lib folder will actually be added and removed automatically as references just because they are in the lib folder! There's no need to do it manually.

In fact, you can have one package that includes versions of assemblies for many different Framework Versions. From the NuGet documentation on Supporting Multiple .NET Framework Versions and Profiles:

\lib
\MyAssembly.dll
\MyAssembly.Core.dll
\Net40
\MyAssembly.dll

In projects that target the .NET Framework 2.0 and the .NET Framework 3.5, NuGet copies both MyAssembly.dll and MyAssembly.Core.dll. But in projects that target the .NET Framework 4, only MyAssembly.dll from the Net40 folder will be copied. If you want MyAssembly.Core.dll to be installed in a project that targets the .NET Framework 4, you must include it in the Net40 folder

For Silverlight, he should do:

lib    
\sl4
\AgiliTrain.PhoneyTools.dll

And when NuGet 1.2, he can use \sl4-wp. That way someone can release a package that includes a different payload for Silverlight 4 vs. Silverlight on the Windows Phone 7.

Playing with PhoneyTools

Now that I've got the PhoneyTools installed, what can I do? According to the PhoneyTools CodePlex project, this is a project that contains several classes and controls for use with Windows Phone 7 applications. There are plans for:

And the word is that he's targeting Mix for the first release. This release is in beta. There's nice simple utility stuff like automatically fading "toast" style messages...

FadingMessage.Show("Doing something important...");

That do what you'd expect (you can make them look like whatever)...

image

To more sophisticated controls like an alternative SelectSwitch:

SelectSwitch

And a SimpleLongListSelector Control that handles a lot of boring work for you and makes creating a giant long list with categories easy so that this XAML:

<my:SimpleLongListSelector x:Name="longList">
<my:SimpleLongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{Binding ImageUrl}"
Height="75" />
<TextBlock Style="{StaticResource PhoneTextNormalStyle}"
Text="{Binding Name}" />
</StackPanel>
</DataTemplate>
</my:SimpleLongListSelector.ItemTemplate>
</my:SimpleLongListSelector>

Along with this LINQ query against a data source:

// For Complex Object and ItemTemplate
var qry = from g in games
orderby g.Genre, g.Name
group g by g.Genre into genre
select genre;

longList.SetGroupingItemsSource<Game>(qry.ToList());

Gives you a nice clean result, and you can click on the category headers to quickly jump to another category.

ItemTemplate

There's lots more, and remember that we noticed the Silverlight Toolkit for Windows Phone "'SilverlightToolkitWP" was a NuGet package as well? There's lot of info on that Toolkit at Tim Heuer's blog as it contains useful controls and classes as well. Between Phoney and the Silverlight Toolkit I think I'm ready to write my app.

Please continue to insist on NuGet packages for useful stuff. Put pressure on the groups you work with and convince them this is a useful thing.

Also, please join me at TechEd 2011 in Atlanta as I present DEV338 NuGet: Microsoft .NET Package Management for the Enterprise!

I'm glad folks are using NuGet for more than just Web Apps. I hope you do to, Dear Reader.

Related Links

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
Comments are closed.

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