简体   繁体   中英

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

I am writing a test code (I'm just a beginner) where I need to give a file name located in my local box. I need to check-in this code as well as the file in TFS, so that when other people take latest version, they get both.

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

For TFS check-in, I gave following path but it failed

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

Now my question is:

  • How can I specify the file path in my Code, so that after check-in when other people in my team take the latest version, the code will point to right file location in TFS?

Here's how you can proceed:

  1. Add a file to the root of your unit test project and set Copy to Output Directory: Copy always . For example add test.txt . Because the file is part of the project structure it will be added under source control as all the other files.
  2. Use the [DeploymentItem] attribute in your unit test to indicate which file will be used. You also have the possibility to organize the test files into sub-folders.

     [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"); } 

Your TFS path string myFilePath= "$MyProjectServer\\SomeFolder\\samplefile.extension" is in the wrong format.

The correct format for an itemspec is:

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

Note the addition of the slash after the $ and the change of backslashes to forward slashes throughout.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM