Using PowerShell and TFS.exe to Update and Remove Files from Projects

I am using PowerShell to modify a series of configuration files within a solution. The solution is managed by TFS 2010.

The solution has many projects and the config files are all xml files. The easy part - if I just need to modify the file, I check it out with the checkout command, and then save the file when done. Things are good. I go to Visual Studio and see the changed files are updated with pending changes as I would expect

The part I am having difficulty with is when I have a config file that is no longer needed and can be deleted. Using the delete command will actually mark the file for pending deletion, but it does not modify the project file that contains the deleted file.

When I delete the file via Visual Studio, it automatically checks and modifies the project file for me. I am not getting the same result when removing the command line.

It is not easy for me to do this manually as I am destroying over 1000 files.

Any help would be greatly appreciated!

Thank.

+3


source to share


2 answers


There are two components at work here. When you work inside VS, the project system handles all the file commands (adds, deletes, edits, etc.) and then invokes the actual change in TFS in the TFS object model. The project system is also responsible for removing the reference from the project file. TFS OM doesn't know if a file is part of a project or not when it is run outside of Visual Studio.

If you have a list of xml files that you need to delete, it is better to write a script that reads them and removes them from the project file (after waiting for the project file to be edited, of course).



-Taylor, TFS Version Control Development Guide

+2


source


Thanks everyone for your answers. After much digging, trial and error, I figured it out. It was much easier than I did it.

Long story short, I used DTE and ran my script from VS using the PowerShell console. It happened something like this:

$mySolution = $dte.Solution
$projectItem = $mySolution.FindProjectItem($fileToRemove)

if ( $projectItem -ne $null )
{                    
    $projectItem.Remove()                    
}

      



Executing the Remove () command on a ProjectItem checks the corresponding project and changes it accordingly.

Again, thanks again for taking all of you to look at my question and answer. Hope this helps someone else someday!

+1


source







All Articles