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:
Here's how you can proceed:
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. 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.