Download only required solutions from workspace

喜夏-厌秋 提交于 2019-12-11 18:16:45

问题


I have a piece of code that sets up a work space and download files from tfs work space programmatically. I want to extend to specify what solutions can I download in that work space. Any ideas how I can do this?

private GetStatus DownloadLatestFiles()
    {
        Workspace workspace = null;

        try
        {
            workspace = SetupWorkSpace();

            workspace.Map(_repositoryCredentials.RepositoryProjectPath, _repositoryCredentials.WorkingDirectory);
            GetRequest request = new GetRequest(new ItemSpec(_repositoryCredentials.RepositoryProjectPath, RecursionType.Full), VersionSpec.Latest);

            return workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);
        }
        catch
        {
            throw;
        }
    }

    private Workspace SetupWorkSpace()
    {
        VersionControlServer sourceControl = SetupVersionControlRepositoryConnection();
        Workspace workspace = sourceControl.QueryWorkspaces(
                 Environment.MachineName,
                 sourceControl.AuthorizedUser,
                 Environment.MachineName).SingleOrDefault();

        if (workspace == null)
        {
            workspace = sourceControl.CreateWorkspace(Environment.MachineName, sourceControl.AuthenticatedUser, "newworkspace");
        }

        return workspace;
    }

I made a change so now it shows...

private GetStatus DownloadLatestFiles()
    {
        Workspace workspace = null;
        GetStatus status = null;

        try
        {
            workspace = SetupWorkSpace();
            List<Solution> services = _serviceList.GetAll();

           foreach (Solution solution in services)
            {
                WorkingFolder workingFolder = new WorkingFolder(ConvertLocalToTfsPath(solution), GetSolutionFolder(solution));
                workspace.CreateMapping(workingFolder);

                //GetRequest request = new GetRequest(new ItemSpec(_repositoryCredentials.RepositoryProjectPath, RecursionType.Full), VersionSpec.Latest);
                //status = workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite);
                status = workspace.Get();
            }
        }
        catch
        {
            throw;
        }

        return status;
    }

Currently still downloads all files.


回答1:


Just add below piece of code:

     var workspace = sourceControl .CreateWorkspace("workspaceName","workspaceOwner");

        String ServerFolder = @"$/TeamProject/Solution1";
        String LocalFolder = @"D:\Folder\";

        WorkingFolder workfolder = new WorkingFolder(ServerFolder,LocalFolder);
        workspace.CreateMapping(workfolder);

        workspace.Get();

Refer to this article for detials: Download Project from TFS online With .NET C#




回答2:


I found the answer. Just a little bit of an adaption from what the above answer.

private List<GetStatus> DownloadLatestFiles()
    {
        Workspace workspace = null;
        List<GetStatus> statusResult = new List<GetStatus>();

        try
        {
            workspace = SetupWorkSpace();
            List<Solution> services = _serviceList.GetAll();

           foreach (Solution solution in services)
            {
                WorkingFolder workingFolder = new WorkingFolder(ConvertLocalToTfsPath(solution), GetSolutionFolder(solution));
                workspace.CreateMapping(workingFolder);

                GetRequest request = new GetRequest(new ItemSpec(ConvertLocalToTfsPath(solution), RecursionType.Full), VersionSpec.Latest);
                statusResult.Add(workspace.Get(request, GetOptions.GetAll | GetOptions.Overwrite));
            }
        }
        catch
        {
            throw;
        }

        return statusResult;
    }


来源:https://stackoverflow.com/questions/49051671/download-only-required-solutions-from-workspace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!