簡體   English   中英

如何為要在TFS中檢入代碼的文件提供路徑?

[英]How do I give file path for code to be checked in at TFS?

我正在編寫一個測試代碼(我只是一個初學者),需要在本地框中指定文件名。 我需要檢入此代碼以及TFS中的文件,以便其他人獲取最新版本時,他們都能得到。

//At my local box
string myFilePath= "D:\BACKUP\samplefile.extension";

對於TFS簽入,我給出了以下路徑,但失敗了

string myFilePath= "$MyProjectServer\SomeFolder\samplefile.extension";

現在我的問題是:

  • 如何在我的代碼中指定文件路徑,以便簽入后當團隊中的其他人使用最新版本時,代碼將指向TFS中正確的文件位置?

您可以按照以下步驟進行操作:

  1. 將文件添加到單元測試項目的根目錄,然后設置Copy to Output Directory: Copy always 例如,添加test.txt 由於該文件是項目結構的一部分,因此它將像其他所有文件一樣在源代碼控制下添加。
  2. 在單元測試中使用[DeploymentItem]屬性指示將使用哪個文件。 您還可以將測試文件組織到子文件夾中。

     [TestMethod] [DeploymentItem("test.txt")] public void Index() { // use relative path to read the file var actual = File.ReadAllText("test.txt"); Assert.AreEqual(actual, "some content"); } 

您的TFS路徑string myFilePath= "$MyProjectServer\\SomeFolder\\samplefile.extension"格式錯誤。

itemspec的正確格式為:

string myFilePath= "$/MyProjectServer/SomeFolder/samplefile.extension";

請注意,在$后面添加了斜杠,並且在整個過程中將反斜杠更改為正斜杠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM