TF.EXE를 사용하여 명령 줄 통과 / 로그인 자격 증명을 사용하여 Visual Studio Team Services에서 최신 정보를 얻으십시오.

StackOverflow https://stackoverflow.com//questions/21005274

문제

명령 줄을 사용하여 Visual Studio Team Services (이전 Visual Studio 온라인, Team Foundation Service) 버전 제어 서버에서 프로그래밍 방식으로 자격 증명을 전달하는 Visual Studio Team Services (이전 Visual Studio 온라인, Team Foundation Service) 버전 제어 서버를 성공적으로 얻었습니까?

-i는 명령 줄에서 팀 탐색기 또는 VSO 웹 사이트에 로그인하는 데 사용하는 Windows ID 자격 증명을 사용할 수 없다는 것을 발견했습니다. 팀 서비스에서 사용자 프로필에 대한 대체 자격 증명을 만들어야합니다.

-i는 tf.exe에서 / 로그인을 생략하면 팀 서비스 로그인 대화 상자가 나타나고 Windows ID 자격 증명 또는 Visual Studio에 이미 캐시되지 않은 경우에도 Windows ID 자격 증명을 입력하라는 메시지가 나타냅니다. 또는 아마도 브라우저 및 Windows 자격 증명 캐시가 있음)

-i는 TF.exe의 Java 버전을 사용하여 대체 자격 증명을 사용하는 것으로 밝혔다. Tee CLC는 실제로 통과하는 / 로그인 자격 증명을 사용하여 연결할 수 있습니다. C : \ Program Files (x86) \ Microsoft Visual Studio 12.0 \ Common7 \ IDE \에서 tf.exe에서 tf.exe로 가능하지만이 빌드 환경에 Java를 설치하는 것은 불가능합니다. 따라서 Tee CLC는 실행 가능한 옵션이 아닙니다.

tf get $/MyProj /collection:https://myaccount.visualstudio.com/DefaultCollection /login:user:pass 
.

위의 명령은 Windows ID 자격 증명이 캐시되거나 오류 메시지를 리턴하는 경우 / 로그인 자격 증명을 무시하거나 오류 메시지를 반환합니다. TF30063 : myAccount.visualStudio.com (자격 증명이 작동하기 때문에 사실이 아님)에 액세스 할 수있는 권한이 없습니다. Java 클라이언트와 함께)

Java를 설치할 필요가없는 다른 대안이 있습니까?

도움이 되었습니까?

해결책

Microsoft 지원에서 답변을 얻었습니다. AA ress for VSO는이 시간에 TF.EXE에서 작동하지 않습니다.Tee CLC 또는 Object 모델 코드 사용은 현재 유일한 대안입니다.우리는 미래에 이것을보고 있습니다.

객체 모델 코드는 동일한 이름으로 DLL의 microsoft.teamfoundation.versioncontrol.client 네임 스페이스를 나타냅니다.Java를 설치하지 않고 최신 코드를 다운로드하려면 빠른 C # 콘솔 앱을 작성하여 끝 냈습니다.이 접근 방식의 추가 된 이점은 knowraway 작업 공간을 만들지 않아도됩니다.

아래 코드를 사용하여 tfsget.exe라는 실행 파일을 만들면 다음과 같은 명령 줄에서 호출 할 수 있습니다.

tfsget https://myvso.visualstudio.com/DefaultCollection $/MyProj/Folder c:\Projects login password
.

다음과 같이 사용할 수있는 각 파일 목록을 억제하기 위해 자동 스위치를 추가했습니다.

tfsget https://myvso.visualstudio.com/DefaultCollection $/MyProj/Folder c:\Projects login password silent
.

여기에 코드가 업데이트 될 때까지 도움이되기를 바랍니다.

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace TfsGet
{
    class Program
    {
        static void Main(string[] args)
        {
            var tfsParams = TfsDownloadParams.Create(args);

            var tpc = new TfsTeamProjectCollection(new Uri(tfsParams.ServerUrl), tfsParams.Credentials);

            CheckAccess(tpc, tfsParams);

            Download(tpc, tfsParams);

        }

        private static void CheckAccess(TfsTeamProjectCollection tpc, TfsDownloadParams tfsParams)
        {
            try
            {
                tpc.Authenticate();
            }
            catch
            {
                Console.WriteLine("TFS Authentication Failed");
                Console.WriteLine("Server Url:{0}", tfsParams.ServerUrl);
                Console.WriteLine("Project Path:{0}", tfsParams.ServerProjectPath);
                Console.WriteLine("Target Path:{0}", tfsParams.TargetPath);
                Environment.Exit(1);
            }
        }

        static void Download(TfsTeamProjectCollection tpc, TfsDownloadParams tfsParams)
        {   
            var versionControl = tpc.GetService<VersionControlServer>();
            // Listen for the Source Control events.
            versionControl.NonFatalError += Program.OnNonFatalError;

            var files = versionControl.GetItems(tfsParams.ServerProjectPath, VersionSpec.Latest, RecursionType.Full);
            foreach (Item item in files.Items)
            {
                var localFilePath = GetLocalFilePath(tfsParams, item);

                switch (item.ItemType)
                {
                    case ItemType.Any:
                        throw new ArgumentOutOfRangeException("ItemType.Any - not sure what to do with this");
                    case ItemType.File:
                        if (!tfsParams.Silent) Console.WriteLine("Getting: '{0}'", localFilePath);
                        item.DownloadFile(localFilePath);
                        break;
                    case ItemType.Folder:
                        if (!tfsParams.Silent) Console.WriteLine("Creating Directory: {0}", localFilePath);
                        Directory.CreateDirectory(localFilePath);
                        break;
                }
            }
        }

        private static string GetLocalFilePath(TfsDownloadParams tfsParams, Item item)
        {
            var projectPath = tfsParams.ServerProjectPath;
            var pathExcludingLastFolder = projectPath.Substring(0, projectPath.LastIndexOf('/')+1);
            string relativePath = item.ServerItem.Replace(pathExcludingLastFolder, "");
            var localFilePath = Path.Combine(tfsParams.TargetPath, relativePath);
            return localFilePath;
        }

        internal static void OnNonFatalError(Object sender, ExceptionEventArgs e)
        {
            var message = e.Exception != null ? e.Exception.Message : e.Failure.Message;
            Console.Error.WriteLine("Exception: " + message);
        }
    }

    public class TfsDownloadParams
    {
        public string ServerUrl { get; set; }
        public string ServerProjectPath { get; set; }
        public string TargetPath { get; set; }
        public TfsClientCredentials Credentials { get; set; }
        public bool Silent { get; set; }

        public static TfsDownloadParams Create(IList<string> args)
        {
            if (args.Count < 5)
            {
                Console.WriteLine("Please supply 5 or 6 parameters: tfsServerUrl serverProjectPath targetPath userName password [silent]");
                Console.WriteLine("The optional 6th 'silent' parameter will suppress listing each file downloaded");
                Console.WriteLine(@"Ex: tfsget ""https://myvso.visualstudio.com/DefaultCollection"" ""$/MyProject/ProjectSubfolder"" ""c:\Projects Folder"", user, password ");

                Environment.Exit(1);
            }

            var tfsServerUrl = args[0]; //"https://myvso.visualstudio.com/DefaultCollection";
            var serverProjectPath = args[1]; // "$/MyProject/Folder Path";
            var targetPath = args[2]; // @"c:\Projects\";
            var userName = args[3]; //"login";
            var password = args[4]; //"passsword";
            var silentFlag = args.Count >= 6 && (args[5].ToLower() == "silent"); //"silent";
            var tfsCredentials = GetTfsCredentials(userName, password);

            var tfsParams = new TfsDownloadParams
            {
                ServerUrl = tfsServerUrl,
                ServerProjectPath = serverProjectPath,
                TargetPath = targetPath,
                Credentials = tfsCredentials,
                Silent = silentFlag,
            };
            return tfsParams;
        }

        private static TfsClientCredentials GetTfsCredentials(string userName, string password)
        {
            var networkCreds= new NetworkCredential(userName, password);
            var basicCreds = new BasicAuthCredential(networkCreds);
            var tfsCreds = new TfsClientCredentials(basicCreds)
            {
                AllowInteractive = false
            };
            return tfsCreds;
        }
    }
}
.

다른 팁

여기에 사용되는 스 니펫이 있습니다. net tfs libraries & powershell tf.exe 에서 일한 통합은 vso와 잘 작동하지 않습니다권한 부여.다른 사람 이이 경로를 사용하여 성공한 경우 궁금합니다.우리는 ADFS 을 사용하고 있으므로 PowerShell 프로세스가 사용자가 인증하려는 사용자로 실행됩니다.

TF 최신 workspace.ps1

$path = "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ReferenceAssemblies\v2.0" 
Add-Type -Path "$path\Microsoft.TeamFoundation.Client.dll"
Add-Type -Path "$path\Microsoft.TeamFoundation.VersionControl.Client.dll"
Add-Type -Path "$path\Microsoft.TeamFoundation.VersionControl.Common.dll"

$collection = "https://mycorp.visualstudio.com/defaultcollection"
$tpc = [Microsoft.TeamFoundation.Client.TfsTeamProjectCollectionFactory]::GetTeamProjectCollection($collection)
$vc = $tpc.GetService([Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer])

# retrieve workspace by path 
$projectPath = "$/MyApp/MyBranch"
$workspacePath = "C:\Projects\MyApp\MyBranch"
$workspace = $vc.GetWorkspace($workspacePath)


# get full download every time (tf get /force /recursive)
function DownloadAllFiles([Microsoft.TeamFoundation.VersionControl.Client.Workspace] $workspace, [string] $projectPath) {     
    $recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
    $versionSpec = [Microsoft.TeamFoundation.VersionControl.Client.LatestVersionSpec]::Instance
    $itemSpec = new-object Microsoft.TeamFoundation.VersionControl.Client.ItemSpec($projectPath,$recursionType)
    $getRequest = New-Object Microsoft.TeamFoundation.VersionControl.Client.GetRequest($projectPath,$recursionType,$versionSpec)
    $getOptions = [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::GetAll -bor [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite 
    $workpaceStatus = $workspace.Get($getRequest, $getOptions)
    write-output $workpaceStatus 
}

# get delta download - changes only (retrieves all mapped items)
function DownloadWorkspaceUpdates([Microsoft.TeamFoundation.VersionControl.Client.Workspace] $workspace) {
    $workpaceStatus = $workspace.Get()
    write-output $workpaceStatus 
}

# get delta download - changes only (retrieves specific mapped items)
function DownloadWorkspaceUpdates([Microsoft.TeamFoundation.VersionControl.Client.Workspace] $workspace, [string] $projectPath) {
    $recursionType = [Microsoft.TeamFoundation.VersionControl.Client.RecursionType]::Full
    $versionSpec = [Microsoft.TeamFoundation.VersionControl.Client.LatestVersionSpec]::Instance
    $itemSpec = new-object Microsoft.TeamFoundation.VersionControl.Client.ItemSpec($projectPath,$recursionType)
    $getRequest = New-Object Microsoft.TeamFoundation.VersionControl.Client.GetRequest($projectPath,$recursionType,$versionSpec)
    $getOptions = [Microsoft.TeamFoundation.VersionControl.Client.GetOptions]::Overwrite 
    $workpaceStatus = $workspace.Get($getRequest, $getOptions)
    write-output $workpaceStatus 
}

# force latest download (slower)
DownloadAllFiles -workspace $workspace -projectPath $projectPath

# download deltas (fast), all mappings
DownloadWorkspaceUpdates -workspace $workspace

# download deltas (fast), specific mapping
DownloadWorkspaceUpdates -workspace $workspace -projectPath $projectPath
.

이것은 TfsClientCredentials ( i.e.e.e. 대체 액세스 자격 증명 )를 지원하도록 쉽게 확장 될 수 있습니다.나는 그것이 편집이 필요하지 않거나 복사 할 여분의 exe가 필요하지 않기 때문에 Powershell 접근 방식을 선호합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top