将代码上传到VSTS团队项目

时间:2017-06-25 12:54:23

标签: azure-devops-rest-api

是否有将代码(从zip文件)上传到空的VSTS团队项目的选项? 我使用VSTS API(Projects)来创建团队项目,但我没有看到任何选项将代码推送到新创建的VSTS项目。

我们可以从Visual Studio连接到团队项目并检查代码,但我正在寻找一些可以在没有人工干预的情况下添加代码来清空VSTS项目的过程。

任何帮助/指针都将不胜感激。

1 个答案:

答案 0 :(得分:1)

首先,您应该在空文件夹中解压缩zip文件。然后提交并将文件推送到新创建的仓库中。

解压缩zip文件:

string zipPath = @"C:\a\1.zip"; \\zip file you want to uncompress
string extractPath = @"C:\a\2"; \\empty path to extract files in zip
ZipFile.ExtractToDirectory(zipPath, extractPath);

将解压缩文件添加到git repo:

对于git repo

您可以将REST API用于add files and push to git repo

或者您可以使用System.Diagnostics.Process执行git命令,例如

ProcessStartInfo gitInfo = new ProcessStartInfo();
gitInfo.CreateNoWindow = true;
gitInfo.UseShellExecute = false;
gitInfo.RedirectStandardError = true;
gitInfo.RedirectStandardOutput = true;
gitInfo.FileName = @"path to git.exe"; \\such as D:\program files\Git\bin\git.exe
gitInfo.Arguments = "git remote add origin https://account.visualstudio.com/project/_git/repo";
gitInfo.WorkingDirectory = @"C:\a\2"; \\path where extract files in

Process gitProcess = new Process();
gitProcess.StartInfo = gitInfo;
gitProcess.Start();
string stderr_str = gitProcess.StandardError.ReadToEnd();  
string stdout_str = gitProcess.StandardOutput.ReadToEnd(); 

gitProcess.WaitForExit();
gitProcess.Close();

对于TFVC回购

您可以使用the commands