Archive

Archive for May, 2011

WCF Data Service Exception: The LoadAsync method cannot be called when the DataServiceCollection is not a child collection of a related entity


In code you most likely called the no argument LoadAsync() method. Make sure you call pass the correcgt URI to the LoadAsync method. For example: if you service is located at http://localhost:1033/Services/PersonInfoService.svc/People

Make sure you pass the service URI without /People to the service context and pass /People to to the LoadAsync method

var people = new PersonEntities(new Uri("http://localhost:1033/Services/PersonInfoService.svc/"));
var Items = new DataServiceCollection<Person>(people);
//Pass the collection path to the LoadAsync method
Items.LoadAsync(new Uri("/People", UriKind.Relative));
Categories: .NET, C#, OData, Services, WCF Tags: , , ,

Customize Binaries folder in TFS Team Build Part 1


A new approach is posted here

Requirements

  • Output binaries must have the following structure

    –Binaries folder

    —-(Build configuration)

    ——–(Project name)

    ————-Binaries files

Issues

The default build template has few limitations that required some customization to meet our requirements. The following are the limitations found:

  • The workflow treats a solution as single project
  • The output of building projects in a solution doesn’t follow the same output directory structure when building in visual studio. For instances, web applications output binaries in the Bin folder while ClassLibrary and Windows applications projects output binaries into the Bin\(configuration) folder.
  • In visual studio, binaries are copied to a bin/(configuration) folder where “configuration” is the configuration of the build (e.g. debug, release..etc) whereas the team build outputs all binaries into one folder called Binaries and that folder doesn’t contain sub folders per project

Solution

I know of two ways to customize the binaries folder. First solution is to modify build template to:

  • Create a folder per project in the solution in the output folder
  • Copy the binaries from the bin folder of each project

Second solution:

  • Modify each project in the solution to output binaries into a common bin folder e.g $(SolutionDirectory)\Bin\$(Configuration)\$(ProjectName)
  • Team build to copy the contents of the bin folder to the binaries folder

This article is a walkthrough for solution 1. I will blog about the second solution in a different post

Modification to Projects

Assume we have the following projects in a solution:

  • Make the Output path for all projects to be the same for all configurations (e.g. debug, release …etc)

Creating new Team Build Workflow Definition

  • Create new Teambuild definition
  • Fill the necessary fields
  • Click on Process on the left
  • Show Details
  • Click the New button
  • Click browse next to “Select the file to copy”
  • Select the Default Template
  • Give it a name

  • Click OK
  • Fill the other fields you need. Make sure you select a configuration for the solution you are selecting
  • Save the build template
  • Browse to the BuildProcessTemplates folder
  • Get latest version of the template we just created

Changes to the Default Template to Meet the Requirements

  • Open the CustomBinariesFolderTemplate.xaml workflow xaml file created in the previous section
  • Click Collapse All

  • Expand On Agent

  • Expand the follow activities:
    • Try Compile, Test, and Associate Changesets and Work Items
    • Sequence
    • Compile, Test, and Associate Changesets and Work Items
    • Try Compile and Test
    • Compile and Test
    • For Each Configuration in BuildSettings.PlatformConfigurations
    • Compile and Test for Configuration
    • If BuildSettings.HasProjectsToBuild
    • For Each Project in BuildSettings.ProjectsToBuild
    • Try to Compile the Project
    • Compile the Project
  • Select MSBuild Activity
  • Set the OutDir property to “”

  • Remember we want to output the binaries into the Binaries folder\Configuration\projectFolder\
  • Add a CreateDirectory Activity under “RunMsBuild for Project”
  • Set the DisplayName property
  • Set the Directory property to

    IO.Path.Combine(BinariesDirectory, platformConfiguration.Configuration)

  • Add FindMatchingFiles activity

  • Set the MatchPatter property to IO.Path.Combine(IO.Path.GetDirectoryName(localProject),“**\*.csproj”). If you want to files of different types you need to use the following syntax:

    IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.vbproj”) & “;” & IO.Path.Combine(IO.Path.GetDirectoryName(localProject), “**\*.csproj”)

  • Set the Results property to VSProjects. Notice that you will get the Error icon because VSProjects doesn’t exist. Make sure you have the Find Project files activity selected when you are adding the variable to make sure the variable is created in the appropriate scope
  • Create a new variable called VSProjects of type IEnumarable<string> ie IEnumarable(Of String)

  • Add ForEach<String> project found activity, a loop to create a folder in the binaries directory for each project found and then copy the contents of the bin/configuration or bin folder to that created folder below the binaries folder

  • Add a Create directory activity with the following code in the Directory property

    Path.Combine(BinariesDirectory, platformConfiguration.Configuration, Path.GetFileNameWithoutExtension(item))

  • Add a copy directory activity

  • Change the destination and the source properties to copy the files in the bin folder of in the source folder to the Binaries\project folder\ directory

  • Save the work flow build template and check in the template

  • Queue a build
  • When build is complete go to the binaries folder and notice that you have three folders, one per project.

Categories: Team Build, TFS, TFS2010 Tags: , ,