2016-06-24 101 views
0

作爲我的nuget包的一部分,我有一個install.ps1 powershell腳本,我正在使用該腳本向包中的工具添加參考文件(幾個文本文檔)夾。ProjectItems.AddFromFile將文件添加到掛起更改中

一切都很好,除非在TFS解決方案中引用這些文件時,它們會被添加到團隊資源管理器掛起的更改中。我如何從待處理的更改中刪除它們(或阻止它們出現)?我不希望這些簽入TFS,因爲軟件包文件夾不應該在那裏。

這裏是我的install.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 
    } 
} 
+0

可能重複[如何從TFS源代碼管理中排除特定文件](http://stackoverflow.com/questions/1369442/how-can-i-exclude-a-specific-file-from -tfs-source-control) – Eris

+0

@Eris,我不相信這是一個重複的問題,因爲你的參考並沒有解釋如何做到這一點是Powershell。 –

回答

0

我終於想通了如何使用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 
    } 
} 
0

如果您在使用本地工作區(TFS 2012+),您可以使用.tfignore文件以排除本地文件夾和文件出現在掛起的更改頁在Team Explorer中。

通過將名爲.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

+0

那麼你是否建議我在PowerShell腳本中創建/修改這個文件?有沒有幫助對象呢?不得不手動更新文本文件(並且只有當我的忽略行不在那裏時)聽起來像是一項非常艱鉅的任務。 –

+0

無需在powershell腳本中創建/修改此文件,您可以直接在.tfignore文件中指定規則。關於如何創建和使用.tfignore文件,你可以參考:https://www.visualstudio.com/docs/tfvc/add-files-server#create-and-use-a-tfignore-file –

+0

這並不是'儘管如此。我不想讓開發人員手動創建/修改.tfignore文件。這就像要求使用Entity Framework包的開發人員手動添加所需的app.config更改。我寧願自動化它,所以他們不必擔心文件被檢查。 –

相關問題