Can anyone help me out in adding a workspace(Contains shared projects), These shared projects are used in different projects or workspaces as project reference,We have a option to add the workspace in working folders tab in BD(Build Definition),But when i add this workspace there are many BD which use this, when we try to checkin the shared workspace then it list all the BD’s in which we have the shared workspace, so for this reason i want to add the workspace dynamically in the workflow.

In your build workflow there is already a workspace object which you can use. It is of type WorkSpace see MSDN Docs. To use it for your purposes, First you would instantiate a WorkingFolder object by passing it a Server path and local path (Make sure the local path doesn’t conflist with other mappings already in the workspace). You would then the already present workspace object and call CreateMapping on it passing it the WorkingFolder object you created. After that, to get the code just call Get on the workspace object.
I assume you are trying to get around the Gated Checkin’s limitation although it would also work for limiting CI Builds, this is an interesting approach please let us know how it works. Pretty cool idea.
NEW INFORMATION: I know you accepted my answer, but I just found a Standard Activity in the tool box, so you don’t need to write your own. Under the heading for Team Foundation Build Activities is DownloadFiles. It is documented on that web page. Pass it a server path, local path, and recursion depth and you are done