TFS 共享文件

问题描述 投票:0回答:1

我们正在使用 TFS 2017(更新 3),其中有一系列我们去年从 VSS 迁移的旧 VB6 项目。在 VSS 中,他们使用某种链接在多个项目文件之间共享某些文件。这样做是为了,如果他们更改了一个项目中的文件,这些更改将被复制到所有项目中的同一文件中。根据使用情况,这对于 .NET 项目来说不是问题,因为这些都只是在共享库项目中。

今天,其中一位开发人员引起我的注意,更改其中一个项目中的文件并没有更改共享版本(这是预期的)。似乎不再支持这种类型的链接(从 TFS2010 开始)。我们实际上无法更改所有这些项目文件(整个设置非常繁琐),所以除了告诉大家当他们进行更改时必须更改所有这些文件之外,我还能在这里做些什么吗?

文件夹结构如下所示,对 SharedFileX 任何副本的任何更改都将复制到该文件的所有副本,无论位置如何。

-MainFolder
    -VBEXE
        -ProjectFolder1
            -SharedFile1
        -ProjectFolder2
            -SharedFile2
        -ProjectFolder3
            -SharedFile1
            -SharedFile2
    -VBSharedClasses
        -SharedFile1
        -SharedFile2
tfs tfs-2017
1个回答
0
投票

文件夹结构如下所示,对 SharedFileX 任何副本的任何更改都将复制到该文件的所有副本,无论位置如何。

要自动将更改复制到所有同名文件(无论位置如何),您需要:

  1. 监控
    SharedFile
    命名文件的变化并触发管道。
  2. 找到更改后的文件路径及其名称。
  3. 使用循环将文件复制到其他同名文件。
  4. 将更改推回您的 DevOps 存储库。

文件夹结构:

下面是一个在我的项目中工作的示例 yaml 管道:

trigger:
  paths:
    include:
    - 'MainFolder/**/SharedFile*'

pool:
  vmImage: 'windows-latest'

steps:
- checkout: self
  persistCredentials: true        # keep the credential to push back the change to repo afterwards
  fetchDepth: 0                # fetch the history so that can get the changed files.

- powershell: |
      ## get the changed files
      $files=$(git diff-tree --no-commit-id --name-only -r $(Build.SourceVersion))
      $temp=$files -split ' '
      $count=$temp.Length
      echo "Total changed $count files"
     
      For ($i=0; $i -lt $temp.Length; $i++)
      {
        $file=$temp[$i]
        # filter SharedFile named file
        if ($file -like "*SharedFile*") {
         echo "this is file: $file"

         # Get the full path to the source file
         $sourceFile = Join-Path "$(Build.SourcesDirectory)" $file

         # Find all files in the repository that have the same name as the source file
         $targetFiles = Get-ChildItem -Path "$(Build.SourcesDirectory)" -Filter $(Split-Path $file -Leaf) -Recurse

         foreach ($targetFile in $targetFiles) {
          # Check if the source file is the same as the target file
          if ($sourceFile -ne $targetFile.FullName) {
              # Copy the source file to the target file, overwriting it
              echo $targetFile
              Copy-Item -Path $sourceFile -Destination $targetFile.FullName -Force
          }
        }
       }
      }

- script: |
    git config --global user.email "[email protected]"
    git config --global user.name "test Name"
    git add .
    git commit -m "Update shared files"
    git push origin HEAD:main
  displayName: 'Commit and push changes'

一旦我更改任何 SharedFileX 文件,它会将更改复制到所有其他文件。

我使用构建服务帐户来推迟更改,确保该帐户具有对存储库的贡献权限。

更改复制到所有同名文件:

© www.soinside.com 2019 - 2024. All rights reserved.