Archive for the ‘Development’ Category

Using NuGet in TFS Without Committing Packages to Source Control

Wednesday, December 21st, 2011

And, without modifying your project “*.*proj” files.

And, without storing nuget.exe in your project’s source control.

NuGet 1.6 is out and with it is a new update to Visual Studio that will update your solution and projects with some extra code and even the NuGet.exe application so that your build process will dynamically download the required NuGet packages.  Rightly so, this is in response to the request that NuGet packages not be stored in source control as they just take up space since they are always available via download.

I understand the approach that was taken (including a .targets file as well as the nuget.exe as well as updating the **proj files) however, I think all of that is unnecessary clutter if your build process can handle it alone.

So, I looked at the NuGet commands and updated the standard TFS 2010 build template to manage this additional step automatically.  With this new template, there is no need to update your solution or projects or include NuGet.exe in your project source.

The only thing you really need to change in your project source control is remove the “packages” folder from source control.  That folder will automatically be created during the build.

Even if you already have custom build templates, you should be able to copy the NuGet restore section over since it is all contained in a single sequence.

The one thing this solution does not do is download the packages locally on your dev machine.  So, if you are getting a solution from source control for the first time, you won’t get all of the references you need since the packages folder isn’t in TFS.  That is easily fixed with a simple PowerShell script that you can run locally to set you up.  All of this is provided below.

The solution:

The Template:

Download the “NuGetRestoreTemplate.xaml” template and add it to source control.  This can be anywhere -  it doesn’t need to be part of your Team Project, it just needs to be in a location where your build can access it.

NuGet.exe:

You have 3 options here.

  1. The easiest and least intrusive your build machine is to add NuGet.exe to source control.  Like the template, this does not need to be in your Team Project.  Just put it in a location where your build can access it.  You then tell the build definition where it exists in source control.  This approach makes updating NuGet.exe easy since it’s all done through source control.  You never have to get on the build machine which in some environments is next to impossible.
  2. Put it on your build server and remember the exact file path.  You can tell the build definition exactly where to look for it.
  3. Put it on your build server and add that folder to your PATH environment variable.  If you do this, then you will leave the location blank in the build definition.  It will be found automatically.  One note here: if you do this, you may have to reboot your machine so the build process realizes the right path.

One suggestion for the template and the NuGet.exe location in source control:  Create a general Team Project that will house all of your build goodies such as custom templates, custom activities and support applications.  I generally create a “BuildActivities” project and put everything in there.  You just need to give everyone read access to it.

To follow along with this recommendation, I created a “BuildActivities” Team Project.  In it I have a “BuildProcessTemplates” folder where I keep all of the generally available build templates.  I have a “NuGet” folder where I keep the “NuGet.exe” application.  I also have subfolders in here for previous releases (just in case).  I also have a folder called “Custom Activities” for all of the custom activities that my templates require.  Note: the template I created for the solution I am describing does not require any custom activities.  I just included that suggestion for completeness.

Creating the Build Definition

Creating the build definition is pretty straight forward.

  1. When you get to the Process, click “New…” next to your “Build process file:”.
  2. Click “Select an existing XAML file”
  3. Click “Browse” and navigate to where you placed the template in source control
  4. Click “OK”

image

The “NuGet Restore/Install” section will appear in the build process parameters

image

Enter the location of the NuGet.exe file.  In this example I placed it in source control but you can just as easily enter the full path on the build machine if that’s where you placed it.  Leave this blank if you put NuGet.exe on the build machine and in the “Path”.

Next, you can add the locations of where to look for the NuGet packages during download.  You can enter multiples here – just delimit with a semi-colon “;”.  If you leave this blank, NuGet will attempt to look at “%AppData%\NuGet\NuGet.config” for NuGet repositories.   Keep in mind that if you leave the parameter blank and expect the build machine to look in the config file, that location is account specific.  The ID of the build process will need to have that file available.

In my example, I included a local network share I set up as a gallery as well as the official NuGet Gallery.

The “Additional Install Arguments” is there if you want to include other parameters like “-Prerelease” or “-ExcludeVersion”.  Note: include the “-“ before each parameter.

That’s it.  You can now remove the “packages” folder from source control and do a build.

Of course, and as always, I would recommend testing this first on a sample app within your environment just to see how it works.

When you run the build, you will see in your log file something similar to this:

image

This shows that the build process has dynamically downloaded all of the required NuGet packages.

Resources:

NuGet Restore/Install/Update:

Here’s the templates and PowerShell Script:

The 2nd template I’ve provided will do the same “restore” process but will also update to the latest version of the NuGet packages rather that just the versions listed in the projects.  It is called NuGetRestoreUpdateTemplate.xaml.  Note: it may or may not break your code to use the update template depending on the version of the package that is downloaded.  See the NuGet documentation for more details.  You can include the “-safe” option in the build definition to avoid the breakage.

The PowerShell script will restore all of the NuGet packages locally if you are not storing the “packages” folder in source control:  NuGetRestore.ps1

 

My Other TFS Build Template Projects:

TfsVersioning Automated Assembly Versioning on CodePlex

NuGetter Automated NuGet Package Generation on CodePlex

NuGetter Project “Pick of the Week” on Channel 9

Thursday, August 25th, 2011

I just found out that Brian Keller mentioned my TFS NuGetter (CodePlex) project that automates the creation, push and publish of NuGet packages through TFS 2010  as his “Pick of the Week” on the August 19th episode of TWC9 (“This Week on Channel 9″).

You can see that episode here:  http://channel9.msdn.com/Shows/This+Week+On+Channel+9/TWC9-August-19-2011

That part was very cool.  The only thing that would’ve made it even more exciting (to me anyway) would have been if he knew who actually created it.  Oh well, it was still cool that it was his pick.  I appreciate the mention Brian!

TfsNugetter-shortened

Kinecting with the Cosmos with Jonathan Fay, Dr. Mark SubbaRao & Michelle Yehling (Part 2)

Wednesday, August 3rd, 2011
In this episode (part 2), we complete the interview on location at Adler Planetarium. Mark and his guest cohost sister, Michelle (Nichols) Yehling talk to astronomer Dr. Mark SubbaRao of Adler Planetarium and Principal Software Architect Jonathan Fay of Microsoft Research about the details of developing the Worldwide Telescope, the conversion to Silverlight, Kinect in the WWT and future plans at Adler.,

Play Now


Show Notes

In this episode (part 2), we complete the interview on location at Adler Planetarium.  Mark and his guest cohost sister, Michelle (Nichols) Yehling talk to astronomer Dr. Mark SubbaRao of Adler Planetarium and Principal Software Architect Jonathan Fay of Microsoft Research about the details of developing the Worldwide Telescope, the conversion to Silverlight, Kinect in the WWT and future plans at Adler.

Resources

Who is:

Jonathan Fay: Principal Software Architect on Microsoft Research’s Worldwide Telescope project in the Next Media Research group at Microsoft. He has been at Microsoft for over 16 years and his area of expertise is the visualization of data over remote networks. He lead the development of several Microsoft projects such as: Microsoft Image Composer, Microsoft Home Advisor, Microsoft bCentral Site Manage, and MSN AdExpert. He is also an avid “amateur” astronomer who even built his own personal domed observatory.
Dr. Mark SubbaRao: Astronomer and Director of the Space Visualization Laboratory at the Adler Planetarium. He is also a senior research associate at the University of Chicago. His area of research is cosmology, particularly the large-scale structure of galaxies, their clustering properties and evolution. He was a builder of the Sloan Digital Sky Survey, working as a developer of their spectroscopic software that measured redshifts, hence providing 3D positions for nearly one million galaxies and quasars. In the Space Visualization Laboratory, Dr. SubbaRao supervises the development of scientific visualizations utilizing cutting edge stereoscopic and ultra-high resolution displays.
Michelle (Nichols) Yehling: Besides being Mark’s sister, Michelle is Master Educator for NASA Forum Programs at the Adler Planetarium in Chicago. She is currently working on several projects with NASA – one of which is Education and Public Outreach for the Interstellar Boundary Explorer spacecraft.
Special note: Great thanks go to Jonathan, Dr. SubbaRao and Michelle for spending so much time with me in recording this podcast. They are an inspiration with the passion they demonstrate in their work and their desire to pass on their knowledge to others.

Sponsors

ThatConference is a brand new conference coming to the Kalahari Resort in the Wisconsin Dells on August 13th, 14th, 15th of 2012. This is a conference is founded by Developers who want to create the conference they’ve always want to go to and for a price that’s easy to justify to your boss. First and foremost this is a developer’s conference. 3 days of any technology and nothing but code. You can find more at ThatConference.com.
WebSite Hosting is provided by Applied Innovations.

Music

Get Started with Windows Azure – Training and Resources

Tuesday, July 26th, 2011

I’ve been gathering up a bunch of resources around doing development on Azure and decided to post them where anyone, including me, can find them.

 

Windows Azure Site

 

Project Templates

 

Lightswitch

 

Development / SDK’s

 

Information, blogs, videos, etc.

 

Training

Last count there was 70+ examples here showing you how to get started with Azure. From the beginning with “Hello World” through SQL Azure, WCF, Silverlight, ASP.Net, LINQ, Storage, Workflow, etc. In VS08/VS10 – C# & VB.NET.

There is a lot of code out here…

 

Planning

Microsoft Assessment and Planning Toolkit 6.0

  • Catalog all of the applications in your environment
  • Estimate the needed capacity to run your applications on the Windows Azure platform
  • Evaluate applications based on migration difficulty
  • Stack rank applications in terms of migration suitability
  • Obtain a TCO-ROI analysis for the application

 

Management

SQL Azure Management REST API Reference

Installing the Windows Identity Foundation (WIF) SDK

Monday, July 18th, 2011

WIF gives you the ability to develop claims-based applications and separate or externalize the authentication of users from your application.  It is a better separation of concerns for the application and gives you more capability for creating a secure application that accesses local or web (cloud) services.

Features you can add to your app using WIF

  • Authentication
  • Personalization
  • Federation
  • Identity Delegation
  • Single Sign On (SSO)

Supported OS Bases

  • Windows 2008 Server SP2
  • Windows 2008 Server R2
  • Windows 7
  • Windows Server 2003 SP2
  • Windows Vista

Development Framework Versions

  • .NET 3.5 SP1
  • .NET 4.0

Installation (Step 1)

To develop using the WIF SDK you will first need the Windows Identity Foundation run-time installed on your machine.  Obviously, this suggests that you will need to install this runtime on any machine that is providing WIF-based services.  You will also need IIS as well.

When I went to do the installs I realized that they were in separate places and have different requirements based on the OS that you are using.  Hopefully, the information I have below will organize that a little better so you can just go get what you need and not have to weed through a bunch of “use this here” and “use that there” statements across multiple pages.

One side note.  The reason I started down this path is that I wanted to work with some sample code that a colleague gave me using WIF.  In the application there in a reference to “Microsoft.IdentityModel.dll”.  My search for that assembly led me here.  So, if you’re looking for that assembly, you’ve now found it.

WIF Runtime Installation Downloads

OS Look here for installation download
Vista / W2K8 Server Windows6.0-KB974405-x64 or x86.msu
Windows 7 / W2K8 R2 Windows6.1-KB974405-x64 or x86.msu
W2K3 Server SP2 Windows5.2-KB974405-x64 or x86.exe

WIF SDK Downloads

Runtime Installation

 

It will call this installation the “Update for Windows (KB974405)”

image

Accept the license terms to continue…

image

It will then do the installation…

image

And complete…It only took about a minute on my x64 laptop.

image

SDK Installation

image

Slightly different license acceptance screen…

image

Where do you want the files…

image

Are you sure…

image

Install…

image

Done.  This install took significantly longer than the runtime – around 5 minutes.

image

TfsVersioning 1.5 – Automated Build Extension Released

Friday, July 15th, 2011

TfsVersioning

Download from CodePlex: http://tfsversioning.codeplex.com/

The goal of this project is to create a way to modify the automated build process of TFS 2010 so that versioning is automatic while giving the user the flexibility that they need given the project’s process requirements. I’ve done this in the past using the angle-bracket programming paradigm of MSBuild – powerful but hard. This time I took advantage of the WF capabilities of TFS Build.

Version 1.5.0.0 Features:

  • Control over assembly attributes has been extended to include:
    • AssemblyTitle
    • AssemblyDescription
    • AssemblyConfiguration
    • AssemblyCompany
    • AssemblyProduct
    • AssemblyCopyright
    • AssemblyTrademark
    • AssemblyCulture
    • AssemblyInformationalVersion
  • Use “Replacement Patterns” to include dynamic (build-time) information in the attribute values
  • Control over AssemblyVersion and AssemblyFileVersion exists as in the previous versions
  • New (Version 1.5.0.0) custom activity assembly is backward compatible so you can replace the assembly and you do not have to change any existing build definitions
  • New Build Process Template is included to provide build definition access to the additional assembly attributes: VersioningBuildTemplate15.xaml


Example:
The Build Definition screen when using the updated build process template:
image


Example
: Properties dialog from within Windows Explorer showing the attributes generated dynamically in the build process.

image

 

Previous and Related Posts to TfsVersioning:

Application Security with Glenn Leifheit

Friday, July 15th, 2011
In this episode, we talk to Glenn Leifheit, a Senior Information Security Consultant at FICO in Minneapolis-St. Paul, Minnesota about security – what to think about, where to start, approaches and best practices.,

Play Now


Show Notes

In this episode, we talk to Glenn Leifheit, a Senior Information Security Consultant (Application Security Program Leader) at FICO in Minneapolis-St. Paul, Minnesota about security – what to think about, where to start, how to approach it and best practices.
We talk about things like initial areas for concern (input validation, encoding output, whether to trust internal or external data, etc.), how Glenn goes about reviewing application security, threat modeling, static and dynamic analysis, trust boundaries, best practices and then provides some resources to help you get started.

whois Glenn Leifheit

Glenn Leifheit, CISSP, CSSLP is a Senior Security Architect at FICO. He has worked in developing, managing, architecting and securing large scale applications for over 15 years. His day is spent rolling out an Enterprise secure software development lifecycle and managing PCI requirements as well as secure software reviews. Glenn is active in the Technology community as the Co-Chair of (ISC)2 Application Security Advisory Board, President of TechMasters Twin Cities, as an active member of IASA (International Association of Software Architects) and OWASP (Open Web Application Security Project) as well as a regional speaker evangelizing secure software. Glenn’s blog is located at www.glennleifheit.com.

Resources

Sponsors

ThatConference is a brand new conference coming to the Kalahari Resort in the Wisconsin Dells on August 13th, 14th, 15th of 2012. This is a conference is founded by Developers who want to create the conference they’ve always want to go to and for a price that’s easy to justify to your boss. First and foremost this is a developer’s conference. 3 days of any technology and nothing but code. You can find more at ThatConference.com.
WebSite Hosting is provided by Applied Innovations.

Music

What’s that Version?

Sunday, April 24th, 2011

Not sure why but in Windows 7 when you look at the properties of a .NET assembly and go to “Details” it shows you the “File version” and “Product version”.  Unfortunately, they are both the same and it’s confusing trying to figure out what version number it is really showing.

image

With Microsoft .NET assemblies, there is an assembly version and there is an assembly file version.  The assembly version is the version you think of when you want to know an application’s version number.  E.g., version “1.2.3.4” and I believe that it should be in the “Product version” in the details window but it’s not.  The assembly file version is used more to indicate which build created the assembly.  E.g., version “1.2.2234.332”.  Therefore, it is usually a more accurate version number and it’s the one that is displayed in the “Details” window (for both version numbers listed).

Now, back to Windows 7.  You can’t just look at the properties and get all of the version information that you need.  For this reason I created a utility to tell me the version info (assembly and assembly file versions) and the strong naming information as well.

Here’s what it looks like when you start it up:

image

If you drag an assembly from Windows Explorer into that window it will extract the name and version information and display it like below:

image

You can keep dragging files into the window as many times as you want.

Julian Date in the version:

I use “Julian” dates in my versioning so that the Assembly File Version can increment with each build.  If you look at the version above you will see that the third version value in the Assemby File Version is “11112”.  It’s nice that it’s a Julian date but what day is it?  Right click on the window and you will find out through a message box like this one:

image

Now you can see that it was April 22, 2011.

You can get the code for the Version Reporter here: http://bit.ly/e4Mu5L

Anyway, this is a useful utility for testing to see if your build versioning process is working and for verifying version numbers in assemblies as you are trying to deploy.

MSTest Aggravation and a Solution (For Me Anyway)

Friday, February 25th, 2011

I’ve created data driven tests many times in Visual Studio and I’ve used Excel spreadsheets, comma separated value (CSV) files and XML.  I’ve even written a blog post or two on the subject.  No matter how many times I do it though, it seems that I always get stuck at the beginning because the data files don’t get deployed. WTF? You’d think I would remember how to do it.  Apparently, that’s not the case cuz tonight I ran into the same fricken, aggravating error message and just stared at it like I’d never seen it before.

Here’s the error message:

“The unit test adapter failed to connect to the data source or to read the data. For more information on troubleshooting this error, see "Troubleshooting Data-Driven Unit Tests" (http://go.microsoft.com/fwlink/?LinkId=62412) in the MSDN Library.”  BTW, this was in VS 2010.

Best part is that if you go to that link, it’s not “Troubleshooting Data-Driven Unit Tests”.  It’s titled "Working with Unit Tests” and it’s under VS 2005.  No troubleshooting tips to be found there.  Nothing that helped anyway.

So, I stared at my code and thought, why can’t MSTest find the stupid file and deploy it?!!! It’s not like it’s hidden.  It’s sitting right there in a folder next to the test.

   1:  [DataSource("Microsoft.VisualStudio.TestTools.DataSource.XML", "|DataDirectory|\\WidthTestData.xml", 
   2:              "Row", DataAccessMethod.Sequential)]
   3:          [DeploymentItem("MyProjTest\\TestData\\WidthTestData.xml")]
   4:          [TestMethod]
   5:          public void WhenObjectCreatedShouldValidateWidthValues()
   6:          {
   7:             ...
   8:          }

 

I did searches on the error and came across many frustrated forum messages trying to find out where the RelativePathRoot is because the DeploymentItem attribute file location is supposed to start from “RelativePathRoot” and go from there.  With that problem in mind, I pointed the DeploymentItem path to many, many variations. Project folder\subfolder\file, ..\subfolder\file, ..\..\subfolder\file, etc. None worked.  I even hardcoded the path and that didn’t work.  Hmmm, a clue.

RelativePathRoot wasn’t the problem.  (BTW, if you were wondering, RelativePathRoot is just the folder of the solution that contains your test project.  Maybe that will be useful to someone.)

I decided to use the Test Settings / Deployment option (double click on “Local.testsettings” in Solution Items and you will get the Test Settings dialog) to force deploy the file rather than rely on the DeploymentItem attribute.  When I clicked on the “Deployment” option I saw it immediately (again).  I forgot to check to see if the “Enable deployment” option was checked.  There’s 45 minutes of aggravation I’ll never get back.

image

Once I clicked that option, my data driven tests started working and all was good – for the moment anyway.  So, keep that in mind when you run into that cryptic error message when you’re creating data driven tests. 

One other thing, setting the file to “Copy always” or “Copy if newer” is NOT the answer.  Don’t do it.

And now, back to my regularly scheduled testing…

Creating an MVC3 Site (ASP.NET Web Pages and Razor) on Azure

Thursday, February 10th, 2011

Today I thought it be cool to create a web site on Azure and use all of the great new capabilities of MVC3 and Razor.  So, I fired up Visual Studio 2010 and unfortunately there were no templates that allow you to do such a thing.  Well then, knowing that you can “bin deploy” MVC 3 apps on servers that don’t have MVC3 installed on them by including the right binaries I figured I would give it a go anyway.  Here’s what I did and this may look like a lot of steps but I was able to do this all in the span of about an hour sitting at Hooters, coding, talking to some friends and having a beer.

  1. I created 2 solutions in 2 different folders. One to create the Azure setup (I just used the existing MVC2 template to get things started) and a separate one with MVC3 using Razor as the view engine.
  2. In the Azure solution, I deleted all of the common MVC folders (Content, Controllers, Models, Scripts and Views) to get them out of the way
  3. In Windows Explorer, I copied those same folders from the MVC3 project over to the Azure project (the MVC2 and MVC3 folder structure is consistent)
  4. Back in Visual Studio (in the Azure project), I clicked on the “Show All Files” icon so I could see the folders and files
  5. Right-click on each of the folder names that I had previously deleted then copied and selected “Include in Project”.  All of the subordinate files are included automatically.
  6. Now, to help make sure that the MVC3 assemblies are available for the application, I created a “Binaries” folder in the Azure project.  Thanks to Scott Hanselman’s Post and Reflector I found out which assemblies to copy and from where.  Copy all of the assemblies on the list to the Binaries folder you just created.  Here’s the list:
    System.Web.Mvc.dll (v 3.0.0.0) and System.Web.Helpers.dll are the two assemblies that the application needs direct references to.  The rest of the assemblies are dependencies of those two. 
    -  Microsoft.Web.Infrastructure.dll
    -  System.Web.Razor.dll
    -  System.Web.WebPages.dll
    -  System.Web.WebPages.Razor.dll
    -  System.Web.WebPages.Deployment.dll
    Mvc can be found here:  Depending on your system (Program Files or Program Files (x86))\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies
    The rest can be found here:  Depending on your system (Program Files or Program Files (x86))\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\Assemblies
  7. Make sure the “Build Action” on the dll files in the “Binaries” folder is set to “None” on all files
  8. Remove the existing reference to “System.Web.Mvc” since it is pointing to version 2 and we want version 3
  9. Add references to all the assemblies and set the “Copy Local” property of each to “True”.  Worth noting: The application really only needs references to a couple of the assemblies (mainly Mvc and Helpers) so it is arguable that you should only reference those two in the app and the installation process should make the rest of the assemblies available rather than using the VS project do your dirty work.  I tend to agree with that and in a production setting I would subscribe, however, for the purposes of this post, and to ease the deployment to Azure, I added all 7 of the references directly in the project and set them all to copy local.
  10. Modify Web.config (this is easier doing a side-by-side compare with the original MVC3 app and the Azure app config files)
    1. In “<system.web><compilation …><assemblies>” change the version number of “System.Web.Mvc” to “3.0.0.0
    2. Add “<add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />” and “<add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> to the list of assemblies.  So, ultimately, it will look like this:
      image
    3. Make sure <pages><namespaces> looks something like this: 
      image
    4. Finally, for the sake of being thorough, change the assembly binding at the bottom of the config so that all references point to MVC version 3
      image

Your MVC3/Razor app should now be runnable within the local Azure development environment.  I’m not going to cover it in this post but if you add a certificate and appropriate credentials, you should be able to publish the app directly to a live Azure site.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes