用poweshell从TFS获取最新代码,并提交到SVN服务器上

本文介绍如何通过PowerShell脚本从TFS获取最新代码,并将其更新到SVN服务器。首先设置环境变量,然后分别获取TFS和SVN的最新代码。接着比较两个项目文件夹的差异,将TFS中的特定文件复制到SVN,并删除或添加SVN中缺失或新增的文件。最后,提交SVN的更改。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#Enable powershell script.
Set-ExecutionPolicy RemoteSigned

#Add environment variables temperally.
$env:path+=";C:\Program Files\SlikSvn\bin";
$env:path+=";C:\Windows\System32";
$env:path+=";C:\WINDOWS\system32\windowspowershell\v1.0";

#Define the path of TFS project, SVN project and redirect temp file.
$tfsFolder="C:\project\tfs";
$svnFolder="C:\project\svn";
$tempFolder="C:\";

#Get the latest code forcely from TFS server.
tf get $tfsFolder /force /recursive;
#Update the code from SVN server.
svn update $svnFolder;
svn cleanup $svnFolder;
#Compare the two folders of TFS project and SVN project. Redirect the result to a temp .txt file.
tf folderdiff $tfsFolder $svnFolder /recursive /noprompt /view:targetonly > $tempFolder\targetonly.txt
tf folderdiff $tfsFolder $svnFolder /recursive /noprompt /view:sourceonly > $tempFolder\sourceonly.txt

#Copy the specific files from TFS project to SVN project by filter.
xcopy  $tfsFolder\*.java $svnFolder /s/e /y
xcopy  $tfsFolder\*.xml $svnFolder /s/e /y
xcopy  $tfsFolder\*.properties $svnFolder /s/e /y

#Read the difference redirected previously, SVN delete the missing files(except .svn info).
For ($file = [system.io.file]::OpenText("$tempFolder\targetonly.txt");
!($file.EndOfStream); $line = $file.ReadLine())
{
   if($line.IndexOf(".svn").Equals(-1) -and ($line.IndexOf("\") -gt 0) -and ($line.IndexOf("Items That Exist Only in").Equals(-1)))
   {
      $line;
      svn delete $line ;
   }
}
$file.close()

#Read the difference redirected previously, SVN add the added files(except .svn info).
For ($file = [system.io.file]::OpenText("$tempFolder\sourceonly.txt");
!($file.EndOfStream); $line = $file.ReadLine())
{
   if(($line.IndexOf("\") -gt 0) -and ($line.IndexOf("Items That Exist Only in").Equals(-1)))
   {
      $addFile = $line.Remove(0,$tfsFolder.Length).Insert(0,$svnFolder);
      $addFile;
      svn add $addFile;
   }
}
$file.close()

#SVN commit.
svn commit -m"commit" $svnFolder;





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值