Tag Archives: .NET

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

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

Installing the Windows Identity Foundation (WIF) SDK

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

NuGetter TFS Automated Build Process Creates and Publishes NuGet Packages

I just released to CodePlex a project that I have been working on called NuGetter. It works through Team Foundation Server automated build to help you organize the package files, create the package and then push (and even publish) to a nuget gallery.  The gallery can be the official NuGet Gallery, a local drive, network share or internal site.  Below is a description of the project which is still being developed (as of this post it is version 0.9.0.0).

http://nugetter.codeplex.com

Project Description

NuGetter is a TFS 2010 Build Process which provides packaging and deployment management to projects destined for a nuget Gallery.

Current version is 0.9.0.0. It is still undergoing development and testing although in it’s current state it is operating very well.

Capabilities/Features:

  • Build, package, push and publish simple to complex nuget packages – including multi-framework packages
  • Invoke a PowerShell script to organize or “pre-package” your files before the package step
  • Build single or multiple .net solutions as input to the packaging process
  • Deploy or Push to the nuget gallery OR an internal (localized) gallery (local or network drive, UNC share, internal web site)
  • Manage the package version directly (will be connecting the process with TfsVersioning to provide even better management of the project version)
  • Include the process as part of a continuous integration or daily build process and deploy directly to a server for testing
  • NuGet.exe is used but does NOT have to be installed on the build server so managing the server requirements is made easier
  • Manage your API Keys and store them in files OR include as part of the build definition
  • Includes custom activities and build templates to use directly within TFS

All of this is managed via a Team Foundation Server automated build.

Solus: Technology to Help with Peace of Mind on DeveloperSmackdown #49

In this episode we got a little serious and talk to Nick Pearson, Mike Price and Nishanth Samala about an application they are working on to help friends and loved ones use targeted communications when a medical “situation” make things exceedingly difficult.

Not only did we get serious but we also got very personal as we shared some real experiences of the Smackdown hosts to drive home some of the real benefits of this type of technology.

Play Episode 49

Personal request: Check out the links below. Get in shape and make a difference. Thanks.

2011 Team In Training[4]

 

dslogo4

Find this episode here: http://developersmackdown.com/Archives/Show/49

Find The Smackdown on your phone:

TheSmackdown-QR---fkdyAw[1]

TfsVersioning Build Activity Now Fortified with F#!

Thanks to a response on CodePlex to my TfsVersioning project by “Rickasaurus”, the project was updated to support versioning F# assemblies as well as C#, VB and C++.  Rickasaurus provided a code example on the discussion board of how he used my code and added the functionality.  I took that code and modified it a little to make part of an AssemblyInfo search a little more flexible using Regex (Regex rocks by the way!), created some more tests and then pushed out a new version: 1.3.1.0.

Thanks to Rickasaurus for his assistance and this process has definitely reinforced to me how a project can be improved with community support.

TfsVersioning

So, if you need to version .NET assemblies as part of the build process within TFS 2010 (which is Windows Workflow 4.0 XAML based), go check out the project.

image

Production Ready Assembly Versioning with TFS 2010

TfsVersioning

Summary:

Versioning is part of Visual Studio projects within the AssemblyInfo file. It’s easy to update the version once but how many people actually and effectively manage an application’s version through this mechanism? I don’t actually know but I would bet that most only do it sporadically and eventually give up. Manual editing of the AssemblyVersion and AssemblyFileVersion is much harder that it needs to be.

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.

This documentation describes the solution. There are several of blog posts on this subject and originally I started thinking I could use the post done by Jim Lamb and just add a little. But soon realized that his post, while very instructive, did not meet all of the flexibility requirements that I knew I would need. So instead, I used Jim’s approach as a starting point and generated the solution that I describe below.

Note:  The project behind this post is at TfsVersioning.CodePlex.com

 

First: My Versioning Process Functional Requirements:

1. Must be able to define the AssemblyVersion and AssemblyFileVersion numbers separately
2. Must update the version for all of the assemblies within a solution with the same version numbers
3. Must provide an option to define the version patterns within the build definition OR within a version “seed file” that itself could be versioned in source control
4. Must provide the option to define the location and name of the seed file
5. If using the seed file, then the version numbers for a specific solution (.sln) must be definable by solution name
6. The seed file must be accessible as part of the source base of a project OR even outside of a project. This capability should allow multiple team projects to utilize a single seed file so version management can be managed from a central location
7. The seed file must be able to maintain multiple solution-specific version patterns in a single file
8. The seed file must be able to identify a separate version pattern for each of the multiple solutions simultaneously
9. If a solution name is not provided or is misspelled then a default version pattern should be able to be provided as a failsafe
10. Must be able to handle modifying versions within C#, VB and C++ projects
11. Must provide the option to automatically check the changes made to the AssemblyInfo file back in to source control during the build process (keeping all the code files in synch)
12. Must be able to define a versioning scheme appropriate to the needs of the application (i.e., use a pattern-based approach and/or explicit numbers to define what the version should be)
13. Version pattern options must provide ability for the build to automatically increment the version if necessary – such as with the AssemblyFileVersion so it can be directly tied back to a build, date, etc.
14. Must provide a way (if necessary to the project) to automatically differentiate version numbers when multiple builds use the same versioning pattern or seed file. In other words, The version number in an assembly must be traceable back to a build, its build definition AND the associated source code (this is an extension of requirement #12)
15. Must be a simple addition to a TFS 2010 workflow-based build process
16. Must use inherent TFS build capabilities – do not require any installation/deployment to the build server (GAC or local file system)

The Solution

After several iterations of design and implementation, I came up with a combination of custom code workflow activities (C#) and non-code workflow activities (XAML) that are all combined into a single composite activity that can be added to an existing TFS 2010 build process. I tried to build in as many tests as I could which were highly valuable for letting me know when I broke things but I also used them during development to trigger the execution of the custom activities without having to run them through a full build process. It made development and debugging tons easier.

Ultimately, I created seven custom activities but only one of them “VersionAssemblyInfoFiles” is necessary to be inserted into the overall build process. That is because “VersionAssemblyInfoFiles” is a composite of the other six XAML and code activities that do all the work.

Version Definition Options

As stated in the requirements list, you have the option of defining the version in the build definition or in a “seed file”. You may be thinking why would I need anything more than being able to define the version in the build definition? After all, the build definition performs the build, right? This is true BUT…the build definition only performs one rendition of the build. What if you need to create multiple build definitions to build the same set of code? I almost always create multiple builds. So, the seed file allows you to define a single versioning pattern and use it across any number of build definitions.

Now some background…

Assembly Version Numbers:

· AssemblyVersion: This is also the product version. During development, it is the version number that you are working towards. For example, version 2.3.4.5

· AssemblyFileVersion: This number can be similar to the AssemblyVersion but should indicate a specific build. For example, 2.3.11070.5 indicates that the major/minor is the same as the AssemblyVersion but the build/revision uses a Julian date and build number so that it is unique no matter what day or how many builds occur. Well, mostly unique – to make it completely unique review “Build Number Prefix” below.

Build Versioning Parameters

The Build Versioning parameters will appear when you select the build process template that contains the updated build workflow (more on that below). They will appear with defaults similar to below assuming that the build workflow is modified as described below.

clip_image002_thumb1

Assembly Version and Assembly File Version Patterns

You have two choices for how you want to specify where the build will get the “pattern” for replacing the assembly version numbers.

  • The first is the easiest; you just enter the patterns in the build definition (“Assembly File Version Pattern” and “Assembly Version Pattern” parameters). Those values will then be passed through to the build workflow.
  • The second is a slightly harder but much more flexible. An XML “seed file” is used to hold and specify the patterns. The benefits of this approach include:
    o The same version file can be used across any number of build definitions
    o A single file can contain patterns for multiple solutions and will even work if multiple solutions are specified in a single build – each solution receives their own version patterns
    o Since it is a file, it is versioned along with the source code and therefore history is maintained

Numeric and Symbol Patterns:

A version (AssemblyVersion or AssemblyFileVersion) can be 1 to 4 numbers (Major[.Minor][.Build][.Revision]) where the maximum numeric value for each is 65535 (a U16 number)

  • If a number is used in any position in the version pattern then that number is passed through unchanged
  • Use a symbol pattern and that value will be replaced in the AssemblyInfo file. The symbols are:
    • YYYY: Replaced with the current 4-digit year
    • YY: Replaced with the current 2-digit year
    • M or MM: Replaced with the number for the current month (MM does not give you a leading 0)
    • D or DD: Replaced with the number for the current day (DD does not give you a leading 0)
    • J: Replace with the current date in “Julian” 5-digit format (YYDDD where YY is the year and DDD is the number of the day within the year e.g., 11075 is March 16, 2011 – there are leading 0’s for the day)
    • B: Replace with the current build number for the day. Note, using this pattern requires that the “Build Number Format” ends in “$(Rev:.r)”. TFS does create the build number format with this “macro” at the end as the default so unless you change it there won’t be a problem.

clip_image003_thumb1

Examples:
“yyyy.mm.dd.b” – If you queued up the 2nd build of the day on April 26, 2011 the version would be: “2011.4.26.2”
“1.0.J.B” – Again, if you queued up the 2nd build of the day on April 26, 2011 the version would be: “1.0.11116.2” (This is the default for the assembly file version)

AssemblyInfo File Pattern:

This parameter is included if you want to specify a different name or different pattern for finding the file that should contain the AssemblyVersion and AssemblyFileVersion entries. Normally, you will not need to change this parameter but it is included for completeness and flexibility.

Build Number Prefix:

The ability to use a seed file to version assemblies across multiple build definitions definitely can ease the management of version numbers and lessen the maintenance within the definitions themselves. However, it creates another problem: different build definitions can generate the exact same version numbers. (See the example below)

The Build Number Prefix provides you with the ability to use the same version pattern across multiple build definitions and still be able to look at the version and trace it back to the build definition that built it and even the source code that was used. So, in other words, you can have your CI build, a daily build and even multiple manual builds and always be able to determine what built the code and what source was used. You can also look at a version number and determine if someone decided to insert an assembly into production that was from the wrong build.

The approach is simple. By entering a value in the “Build Number Prefix” parameter, that value will be added to the Build Number in the version (this assumes that the “B” flag is used in the version pattern – typically in the AssemblyFileVersion). So, if the build number is 1 and the Build Number Prefix is 100 then the version will indicate 101.

Example:

Let’s say you have a situation like we already described: 2 build definitions (a CI and a daily build) and both definitions use the following pattern for the AssemblyFileVersion: “1.2.J.B”. Now, queue up an instance of both definitions (assuming they are the 1st builds of the day). When the build process is done, you will have assemblies in 2 different drop folders with the exact same AssemblyFileVersion (e.g.: “1.2.11155.1”). So, to solve that problem, enter the value 100 in the Build Number Prefix parameter for the CI build and a value of 200 in the Build Number Prefix for the daily build. Now, queue them both up again. The resulting version numbers will be different (CI will be “1.2.11155.102” and the daily build will be “1.2.11155.202”). Now they are different and will continue to be different. I can even trace all the way back to the source code that built it via the build definition and the label attached to the source. You can make this tracing even easier if you add the number you use for the prefix to the Build Definition Name. Then, the version, the build definition and the label will all be aligned to the same naming/versioning pattern and easy to search for and find.

Note: The prefix number must always be larger than the build number or you will get number clashes. The example above assumes that you would never build more than 99 times in a day. If that is a possibility then just change the prefix to 1000. If you do more than 999 builds in a day then please contact me because you’re probably melting the build servers and I would love to hear about it. In any event, you could put 10000 in the prefix to handle it. No matter what, prefix + build number can’t go over the UInt16 value of 65535.

Force Create Version:

A “True” value here indicates to the process that even if an AssemblyVersion or AssemblyFileVersion entry does not already exist within the AssemblyInfo files, they should be created. A “False” value will key off their existence in the AssemblyInfo file and will only update a version if it is indicated. Maybe you want the AssemblyVersion but you don’t want to update the AssemblyFileVersion – just set this value to “False” and leave the AssemblyFileVersion entry out of the AssemblyInfo file and no AssemblyFileVersion will be created.

Perform Check-In of the AssemblyInfo File(s):

This parameter is a boolean that lets you say that you want the AssemblyInfo files checked back into source control after they are modified with the correct version numbers and before the source is labeled. This will keep the history current within source control. It defaults to “False” so therefore will not perform a check-in but change to true if you want them checked in.

Use Version Seed File:

This property is an indicator that defaults to “False” which tells the build to use the version patterns in the build definition. Change this to a value of “True” to tell the build to use the version “seed file”. See the descriptions below to find out more about the benefits of using the seed file to manage the version patterns across multiple builds.

Version Seed File Path:

The version seed file is an alternative to using the version patterns included in the build definition. By using the seed file, you can instruct any number of build definitions to use the same version number patterns across all of the builds. So, if you have a CI build and daily build, they both can use the same data file to define the version parameters. Another benefit of the seed file is that you can manage versioning multiple solutions with the same seed file. The solutions can be built separately or (if you wish) you can build multiple solutions in the same build definition and each solution is versioned with its own version patterns.

The example below shows the XML structure for the seed file. There is an overall “VersionSeed” group that contains the “Solutions”. Each solution element corresponds to a Visual Studio solution by name. So, the versioning activity will read the seed file and look for an element name that matches the name of the solution. If it finds one, it will then extract the patterns to be used for the versioning replacement.

<VersionSeed>
  <Solution name="BuildVersioning">
    <AssemblyVersionPattern>1.0.3.0</AssemblyVersionPattern>
    <AssemblyFileVersionPattern>1.0.j.b</AssemblyFileVersionPattern>
  </Solution>
  <Solution name="Default">
    <AssemblyVersionPattern>1.0.2.0</AssemblyVersionPattern>
    <AssemblyFileVersionPattern>1.0.j.b</AssemblyFileVersionPattern>
  </Solution>
</VersionSeed>

To continue with the example, I have a TFS Project that contains a solution file called “BuildVersioning.sln”. With this seed file, the “BuildVersioning” solution assemblies will all receive an AssemblyVersion of 1.0.3.0. All assemblies will also receive an AssemblyFileVersion of “1.0.11106.5” (for example – see the pattern translation below for Julian date and build number). The “Default” value is used if there the solution being built does not have a corresponding Solution Name in the seed file. It is a safety catch but could also be used to version multiple solutions with the same version numbers (I don’t have a good reason why you would want to do that but then everyone has different needs).

Relative Path or Source File Path

Relative Path:

The default value included in the build definition properties is “TfsVersion\VersionSeed.xml”. This assumes that you will create a folder named “TfsVersion” within the solution and in that folder is a file named “VersionSeed.xml”. This is using the relative path approach.

clip_image004_thumb

Building multiple solutions in the same build definition is easy within TFS 2010. If you want to do this, you can move the folder containing the seed file up a level or two (e.g.: “..\..\TfsVersion\VersionSeed.xml”). Then, the build will look at where the current solution being built is located and then traverse upward to the folder containing the seed file. Note: If you do this, the folder containing the seed file must be included in the Source Control Folder when you identify the Workspace in the build definition. Obviously, this is necessary so the file exists locally when the build server gets the source code.

Source File Path:

You have a second option to identify the seed file. Instead of a relative path, you can use a complete source file path to specify where, in source control, the seed file exists. This approach solves a number of issues. Going this route, you can manage version numbers across multiple TFS Team Projects rather than just multiple solutions within a single TFS project. You also don’t have to worry about making sure the seed file exists in the workspace identified in the build definition or if the seed file is the same distance away from each of the solution files.

The only difference is in how you identify the file. Rather than using relative path notation, you use source control notation (e.g.: “$/Project/folder/file.ext”). For example, below you can see that the solution is in the BuildActivities Team Project but the seed file is in the “Shared Source Projects” Team Project. I did this just to show the possibilities of the feature – the file does not need to be in a different Team Project. Also note that the “Use Version Seed File” property is set to “True”. “False” means that the version patterns will be taken right from the build definition.

clip_image006_thumb4

The easiest way to grab the path is to just right-click on the file in Team Explorer and go to properties. You can then just highlight and copy the file location (where ever you decide to put it).

clip_image007_thumb1

Installation and Verification:

Simplified Installation:

This method of installation assumes that you will use the modified workflow (XAML file) that is included with the source. The name of the workflow is “VersioningBuildTemplate.xaml”.

1. Create or identify a Team Project to hold the activity assembly and the updated versioning build workflow (XAML) file. Personally, I created a Team Project called BuildActivities to hold the source for this workflow addon. In that same project I hold the updated build process template as well as the custom activity assembly that does all of the versioning work.

2. Create or identify a folder to hold the custom versioning activity assembly. The TFS build controller keeps track of a folder in source control where all the custom activity assemblies can be stored and used in build workflows. Below you can see the one I created “Custom Activity Storage”

clip_image008_thumb

3. Add the VersioningBuildTemplate.xaml file to your BuildProcessTemplates folder and add the TfsBuild.Versioning.Activities.dll file to your custom activity storage folder

4. Check in the additions to source control

5. Start up the Team Foundation Server Administration Console. You need to tell the TFS Build Controller where it should look to find any custom build activity assemblies

6. Go to “Build Configuration” and select the build controller properties. The window should look something like the one below:

image_thumb1

7. Click the ellipsis for the “Version control path to custom assemblies” and navigate to the folder where you added the TfsBuild.Versioning.Activities.dll file. After you identify the folder in source control, click OK

That’s it for installation. You can close down the administration console for TFS.

Testing the installation

1. Either create or go to a Team Project where you can test the build versioning process.

2. Create a new build definition (you could modify an existing one if you want)

3. Fill in the Name, Trigger, Workspace and Build Defaults as you normally would

4. When you get to “Process”, click on “Show details” in the “Build process template” section

5. Open up the “Build process file” drop-down and look for the “VersioningBuildTemplate.xaml” file and select it. If it is not there, click on the “New” button, click on the “Select an existing XAML file” radio button and browse to the folder location where you checked in the XAML file and then click “OK”

6. Within the “Build process parameters”, a new “Build Versioning” section should appear that contains all of the properties described previously

This is all you have to do to get the build updated with versioning. The defaults should work just fine to create assemblies with an assembly version number of “1.0.0.0” (which isn’t too amazing since that’s the default that comes in the assemblyInfo file) BUT the assembly file version should be recognizable that it has been changed. It should be “1.0.#####.1”. The “#####” number depends on the day you run the build but if it were April 22, 2011 then the number would be 11112. In any event it will be a 5 digit number with the 1st two digits being the year.

Cue up the build and see what happens.

Harder Installation but More Instructive

This version of the installation assumes that you want to be able to modify your own workflow and insert the custom versioning activity. In this option, the versioning assembly must be added to the GAC and therefore signed. The reason it needs to be added to the GAC is so the workflow editor in Visual Studio will see the assembly and allow it to be added to the workflow. The assembly included in the download is signed (albeit not very securely since the key file doesn’t use a password). You can use this assembly or compile your own with your own key.

1. Use the GACUtil utility to install the assembly to the Global Assembly Cache

a. Go to “All Programs\ Microsoft Visual Studio 2010\ Visual Studio Tools\ Visual Studio Command Prompt” and start a command window with elevated privileges (“As Administrator”)
b. Install the assembly into the GAC with a command like this:

image_thumb4

2. Open Visual Studio and the build workflow file (xaml) that you wish to modify

3. You need to tell the Visual Studio toolbox that you want to use the custom activity

a. If you want, add a tab in the toolbox to contain the custom versioning activity. This is not at all necessary but it does organize the activities.
b. Add the custom activity to the toolbox by right-clicking on the tab where you want the custom activity to reside. The tab should highlight to tell you where it will be placed.
c. Select “Choose Items…” from the popup menu. This will bring up an aptly-named “Choose Toolbox Items” window
d. The “System.Activities Components” tab will probably be highlighted. Click “Browse…” and go find the activity assembly. You just need to browse to the file not the GAC.

image_thumb7

e. All of the activities in the assembly you just added will be checked by default. You can make things a little easier for later if you uncheck those activities and only check the “VersionAssemblyInfoFiles” activity. The others are used by “VersionAssemblyInfoFiles” to make up the composite activity.
f. Click “OK” and the toolbox will be updated

image_thumb8

4. Create the “Arguments” in the workflow so that you can pass information to the activity during the build definition and the build itself. Note that all of the arguments use “In” as the direction and below I am giving you the Name, Argument type and Default value:

Argument Name

Type

Default Value
VersionSeedFilePath

String

“TfsVersion\VersionSeed.xml”
ForceCreateVersion

Boolean

True
DoCheckinAssemblyInfoFiles

Boolean

False
AssemblyVersionPattern

String

"1.0.0.0"
AssemblyFileVersionPattern

String

"1.0.J.B"
AssemblyInfoFilePattern

String

"AssemblyInfo.*"
UseVersionSeedFile

Boolean

False
BuildNumberPrefix

Int32

0

5. Insert the activity and tie the arguments to it:

a. Search for the right position to place the activity by looking in the “Run On Agent” sequence. This can get confusing since the workflow will expand when you try to view areas that it hasn’t shown before. So, collapse the activities as you scan downward. For example, right inside of “Run On Agent” is “Initialize Variables” and if you click on the up arrows on the right side of the activity it will collapse down. The next sequence below “Initialize Variables” should be “Initialize Workspace” and that’s where the activity should go – right below “Get Workspace” (after the source is retrieved and before anything is labeled)

b. Drag “VersionAssemblyInfoFiles” from the toolbox and place it right below “Get Workspace”. It will tell you that there is an error since there are required values that have to be filled in.

image_thumb9

c. Add the arguments to the properties. All of the arguments that were created above need to be added to the activity properties but you will see that there are more properties than the number of arguments that we created. This is because the activity uses some of the arguments and variables that already exist in the workflow. (“BuildSettings” is an existing argument, “Workspace” and “BuildDirectory” are existing variables). The graphic below shows you what to change and when you’re done the error icon should go away:

image_thumb11

6. Almost there. Now you need to add the metadata to the workflow so that the build definition will know to ask you the right questions as you create the build. In the “Arguments” for the workflow, look for “Metadata” and click on the ellipsis.

a. In the “Process Parameter Metadata Editor” you need to add an entry for each argument that will get passed from the build definition to the build workflow. Use the table below to copy/paste the entries in to the editor.

b. The “Category” value for each of the parameters should be identical so the properties are all grouped together. I named the category “Build Versioning”.

c. Leave the “Required” box unchecked for all of the entries

d. You can modify the “View this parameter when:” however you would like or you can leave the values at the default of “Only while editing a definition”

Parameter Name

Display Name

Description

AssemblyFileVersionPattern

Assembly File Version Pattern

This is the pattern used to replace the AssemblyFileVersion value.

AssemblyVersionPattern

Assembly Version Pattern

This is the pattern used to replace the AssemblyVersion value.

AssemblyInfoFilePattern

AssemblyInfo File Pattern

This is the pattern used to find the AssemblyInfo files. Generally, you shouldn’t need to change this value.

DoCheckinAssemblyInfoFiles

Perform Check-in of the AssemblyInfo Files

Indicated whether the AssemblyInfo files should be checked back into source control after they are modified.

ForceCreateVersion

Force Create Version

If true, the versioning process will create AssemblyVersion or AssemblyFileVersion values even if they do not already exist.

UseVersionSeedFile

Use Version Seed File

Indicate which values to use as the versioning patterns. If set to True, the "seedfile.xml" file must exist in the location described by the "Version Seed File Path" setting. Otherwise, the "Assembly Version Pattern" and "Assembly File Version Pattern" values will be used.

VersionSeedFilePath

Version Seed File Path

Relative path location for the seed (xml) file containing the Assembly Version and Assembly File Version values.

BuildNumberPrefix

Build Number Prefix

Number added to the version component that uses the "B" symbol pattern (Build Number). This helps create a unique version for a build definition.

7. Last step. This step is a verification step. Sometimes, depending on how the workflow is edited an entry may be left out.

a. Edit the build workflow in text mode so you can see the XML/XAML code

b. Search for “TfsBuild.Versioning.Activities”. The entry should be something like this:

xmlns:tva="clr-namespace:TfsBuild.Versioning.Activities;assembly=TfsBuild.Versioning.Activities"

c. If the “;assembly=TfsBuild.Versioning.Activities” statement is not there then definitely complete the entry otherwise the build will most likely fail when it is run.

That’s it for editing you can now test the build versioning. If you want more instruction on how to do this, just go back up to “Testing the Installation” but you should be ready to create a new build definition (or modify an old one) using the workflow you just created and version your assemblies.

What’s that Version?

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.

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

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.

.NET Rocks AND Chicago Code Camp 2

I volunteered to help out at Chicago Code Camp 2 coming up next week on May 1

Chicago Code Camp 2010

May 1st, 2010 at 8:00 AM
IIT- Stuart Building
10 West 31st
Chicago, IL 60616

.NET Rocks guys: Carl Franklin and Richard Campbell will be there. 

Cool Silverlight app to watch the .NET Rocks roadtrip: http://silverlight.onterrasys.com/dnr_roadtrip/

Looking forward to meeting them.

Here’s where you can register: http://chicagocodecamp.com/ and apparently, they are still looking for volunteers.

Create an OData Feed with VS 2008 and 2010

Creating an OData Publisher

I did a simple overview of OData in a previous post and on our recent Developer Smackdown Podcast (Episode 23) Clark and I talked about the capabilities and how you can use the OData standard to publish all kinds of data without knowing exactly how your consumers will use it.  In this post I will show how you can utilize Entity Frameworks and create an OData service VERY easily.  I will do this in Visual Studio ‘08 as well as 2010 since Microsoft loves to add a little confusion to the mix and changed the names of WCF/ADO.NET Data Services and how you initially get at them as VS projects.

First of all, “ADO.NET Data Services” in .NET 3.5 SP1/VS 2008 is now “WCF Data Services” in .NET 4/VS 2010.  The original name was “Project Astoria”.  Depending on the timing, blogs and articles on the net may be using any of those names.

VS 2008/.NET 3.5 SP1 (with Data Services Update – link below):

For these service applications I installed the AdventureWorks demo database that you can get on CodePlex which can be installed in a SQL Server database.  I installed locally in SQL Express.

1. Start Visual Studio and create a WCF Service Application.  OK, so there’s more confusion.  Why isn’t there an ADO.NET Service Application. Dunno. But this is an easy way at getting the initial project in place.  We will actually delete the service that this template creates and use an ADO.NET Data Service.

image

If you look at your solution, you will see something like this:

image

2. Delete the service class and interface.  They will just get in the way otherwise.

3. Add a new item to the project.  Select Web and an “ADO.NET Data Service”.  In a moment of pure inspiration I named mine “ODataService.svc”.

image

If you look at your references, you will see that several new assemblies were added. System.Data.Entity, System.Data.Services, System.Data.Services.Client and System.ServiceModel.Web are all added.

4. The next thing is to add the database.  I did this through Entity Frameworks.  Some people like EF, some don’t.  Thing is, EF makes this exercise stupid easy so I added a new item “ADO.NET Entity Data Model”.

image

5. This will start the wizard and the next step is to “Generate from database” and click Next.

image

6. Choose your connection and create the connection string.

 image

7. Pick the tables that you want to publish and Finish.

image

System.Security gets added to the references and the EF data model also gets added.

image

8. So you have all the parts but there is code missing.  In the data service code file “YourServiceName.svc.cs” or whatever your file name is, there are some changes. First, for OData to work the service inherits from the “DataService” class and you have to pass in your data type.  In my example, the type generated from the EF wizard is “AdventureWorksLT2008Entities”.  As a result my class definition for the service is:

public class ODataService : DataService<DataEntities.AdventureWorksLT2008Entities>

9. Inside the “InitializeService” method of your new service you will need a few lines of code as well.  Especially since out of the box that method contains nothing but comments.  Unfortunately, for those of us who preach dependency injection and the use of interfaces, you have to change the method parameter from an IDataServiceConfiguration interface type into a DataServiceConfiguration class type.  It appears that the config type contains a required “DataServiceBehavior” property that the interface doesn’t know about.

10. Within the InitializeService method you add a few lines of code.  Here’s the whole thing:

using System.Data.Services;
using System.Data.Services.Common;

namespace OdataWcfServiceApplication
{
    public class ODataService : DataService<DataEntities.AdventureWorksLT2008Entities>
    {
        // This method is called only once to initialize service-wide policies.
        // DataServiceBehavior is part of the DataServiceConfiguration type - not IDataServiceConfiguration
        public static void InitializeService(DataServiceConfiguration config)
        {
            config.SetEntitySetAccessRule("*", EntitySetRights.AllRead);

            // Use this especially for debugging.  This line will respond with additional
            // info if an error is encountered
            config.UseVerboseErrors = true;

            // This line tells your service to use version 2 of the OData services. 
            // Version 2 allows you to do more such as control paging of output 
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V2;
        }
    }
}

OK, that’s it.  You can now run the application, the service will be hosted locally and the browser will pop up.  The result you get depends on the database that you use and the tables selected but it will appear something like this:

image

To test out the OData query capabilities just add your query to the end of the URL.  For example, in my case I have a list of products that I can request. At the end of the URL I add “Product?top=10”.  This says I want the listing of products but to limit it to the first 10.  There are a lot of products in the database and if I didn’t filter then I would be waiting a while till all of the products were put in a list. Nice that I can do that.

Here is the output of that query:

image

If this is what you see…

image

and you want to see the raw data being sent back by the query (and why wouldn’t you?) you need to go into IE/Tools/Internet Options/Content tab/Feeds and Web Slices/Settings button and uncheck “Turn on feed reading view”.  You may need to restart IE for that to take effect but after that you will see the raw data feed.

 

.NET 4/VS 2010

I’m just going to go over the differences here because for the most part, it is all pretty much the same.

  • The first difference is with step 3.  Because of the new names for the services, instead of creating an “ADO.NET Data Service”, create a “WCF Data Service”.
  • In step 7, there is another option in the EF Wizard.  “Pluralize or singularize generated object names” is a checkbox that is defaulted on.  This is important because if I did everything else the same, the object that I exposed in the feed is not called “Product”, it’s now “Products” since the name was pluralized by EF.  Obviously, queries must use the correct name or they don’t work.

I believe that’s it.  Not much difference between the two.  Just remember:

  • To use OData in VS2008/.NET 3.5, you need to install the Data Services Update (link below) – It is now part of .NET 4
  • As stated above, the object names may or may not be pluralized depending on the EF Wizard.  “Product” != “Products”
  • Queries are case sensitive.  “Product” != “product”.  If you are having trouble with a query take a look at the object names
  • If you can’t see the raw data in IE, change the content setting in Internet Options (described above)
  • If you publish OData, the query processing is done on your server so keep in mind how much it is accessed, how much data is being queried and the potential complexity of the queries as this relates specifically to sizing and bandwidth

 

Resources:

OData.Org

Data Services Update for .NET 3.5 SP1: update to .NET that installs the libraries that give you the OData capabilities.

Click here for Win7 and W2K8 R2.

Click here for all other OS versions.

Technorati Tags: ,,