ProjectItems.AddFromFile 将文件添加到待定更改

ProjectItems.AddFromFile Adds File to Pending Changes

作为我的 nuget 包的一部分,我有一个 install.ps1 powershell 脚本,我用它来向项目添加参考文件(几个文本文件)从包的工具文件夹。

一切正常,除了当在 TFS 解决方案中引用文件时,它们被添加到团队资源管理器待定更改中。我怎样才能将它们从挂起的更改中删除(或让它们永远不会出现)?我不想将这些签入 TFS,因为 packages 文件夹一开始就不应该存在。

这是我的安装。ps1 脚本:

param($installPath, $toolsPath, $package, $project)

#Add reference text files to the project and opens them

Get-ChildItem $toolsPath -Filter *.txt |
ForEach-Object {

    $projItem = $project.ProjectItems.AddFromFile($_.FullName)
    If ($projItem -ne $null) {
        $projItem.Properties.Item("BuildAction").Value = 0  # Set BuildAction to None
    }
}

如果您使用的是本地工作区 (TFS 2012+),则可以使用 .tfignore 文件排除本地文件夹和文件出现在团队资源管理器的“待定更改”页面中。

您可以通过将名为 .tfignore 的文本文件放在要应用规则的文件夹中来配置忽略哪些类型的文件。

.tfignore 文件规则

The following rules apply to a .tfignore file:
- \# begins a comment line
- The \* and ? wildcards are supported.
- A filespec is recursive unless prefixed by the \ character.
- ! negates a filespec (files that match the pattern are not ignored)

.tfignore 文件示例

######################################
# Ignore .cpp files in the ProjA sub-folder and all its subfolders
ProjA\*.cpp
# 
# Ignore .txt files in this folder 
\*.txt
#
# Ignore .xml files in this folder and all its sub-folders
*.xml
#
# Ignore all files in the Temp sub-folder
\Temp
#
# Do not ignore .dll files in this folder nor in any of its sub-folders
!*.dll

详情:https://www.visualstudio.com/docs/tfvc/add-files-server#customize-which-files-are-ignored-by-version-control

我终于想通了如何使用 tf.exe 来做到这一点。使用完整文件名调用 tf vc undo 将撤消这些文件的未决更改。如果该文件夹未绑定到 TFS,则不会造成任何伤害。它只是继续。

此实现确实需要安装 VS 2015(由于 IDE 文件夹的硬编码路径),所以我正在寻找一种更好的方法来获取 IDE 路径当前加载 IDE。不过现在,这解决了我当前的问题。

param($installPath, $toolsPath, $package, $project)

$idePath = "$env:VS140COMNTOOLS..\IDE"
$tfPath = "$idePath\tf.exe"

Get-ChildItem $toolsPath -Filter *.txt |
ForEach-Object {

    $projItem = $project.ProjectItems.AddFromFile($_.FullName)
    If ($projItem -ne $null) {
        $projItem.Properties.Item("BuildAction").Value = 0  # Set BuildAction to None

        $filename = $_.FullName

        & $tfPath vc undo `"$filename`" # Remove File from TFS Pending Changes, as AddFromFile can automatically add it
    }
}