0

As part of my nuget package, I have an install.ps1 powershell script that I am using to add a reference file to the project (a couple text documents) from the package's tools folder.

Everything is working great, except that when the files are referenced in a TFS solution, they are added to the Team Explorer Pending Changes. How can I remove them from pending changes (or keep them from ever showing up)? I don't want these checked into TFS, since the packages folder shouldn't be there in the first place.

Here's my install.ps1 script:

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
    }
}
Nathan A
  • 11,059
  • 4
  • 47
  • 63
  • Possible duplicate of [How can I exclude a specific file from TFS source control](http://stackoverflow.com/questions/1369442/how-can-i-exclude-a-specific-file-from-tfs-source-control) – Eris Jun 25 '16 at 17:07
  • @Eris, I do not believe this is a duplicate question as your reference does not explain how to do this is Powershell. – Nathan A Jun 27 '16 at 14:09

2 Answers2

0

If you're using local workspaces (TFS 2012+) you can use the .tfignore file to exclude local folders and files from appearing in the Pending Changes page in Team Explorer.

You can configure which kinds of files are ignored by placing text file called .tfignore in the folder where you want rules to apply.

.tfignore file rules

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 file example

######################################
# 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

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

Cece Dong - MSFT
  • 29,631
  • 1
  • 24
  • 39
  • So are you suggesting that I create/modify this file in my powershell script? Is there any helper object for doing that? Having to manually update a text file (and only if my ignore lines aren't already there) sounds like a pretty daunting task. – Nathan A Jun 27 '16 at 14:07
  • No need to create/modify this file in powershell script, you can specify the rules in the .tfignore file directly. Regarding how to create and use .tfignore file, you can refer to: https://www.visualstudio.com/docs/tfvc/add-files-server#create-and-use-a-tfignore-file – Cece Dong - MSFT Jun 28 '16 at 05:17
  • That doesn't work though. I don't want to have developers have to create/modify a .tfignore file manually. That would be like requiring developers that are using the Entity Framework package to add the required app.config changes manually. I'd rather automate it so they don't have to worry about files getting checked. – Nathan A Jun 28 '16 at 17:55
0

I finally figured out how to do it using tf.exe. Calling tf vc undo with the full filename will undo pending changes for those files. And if the folder isn't tied to TFS, no harm done. It just continues on.

This implementation does require VS 2015 to be installed (due to the hardcodes path to the IDE folder), so I'm looking for a better way to obtain the IDE path of the currently loaded IDE. For now though, this solves my current issue.

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
    }
}
Nathan A
  • 11,059
  • 4
  • 47
  • 63