简体   繁体   English

如何为要在TFS中检入代码的文件提供路径?

[英]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. 我需要检入此代码以及TFS中的文件,以便其他人获取最新版本时,他们都能得到。

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

For TFS check-in, I gave following path but it failed 对于TFS签入,我给出了以下路径,但失败了

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? 如何在我的代码中指定文件路径,以便签入后当团队中的其他人使用最新版本时,代码将指向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 . 将文件添加到单元测试项目的根目录,然后设置Copy to Output Directory: Copy always For example add test.txt . 例如,添加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. 在单元测试中使用[DeploymentItem]属性指示将使用哪个文件。 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. 您的TFS路径string myFilePath= "$MyProjectServer\\SomeFolder\\samplefile.extension"格式错误。

The correct format for an itemspec is: itemspec的正确格式为:

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

Note the addition of the slash after the $ and the change of backslashes to forward slashes throughout. 请注意,在$后面添加了斜杠,并且在整个过程中将反斜杠更改为正斜杠。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何调试推送到我的TFS构建服务器的代码? - How do I debug code pushed to my TFS build server? 在针对已编码的ui的调试中运行代码时,如何获取文件的相对路径 - How do i get a relative path of a file when running my code in debug for coded ui 如何模拟在 python 中为特定路径打开的文件? - How do I mock a file open for a specific path in python? 在iOS上运行单元测试时,如何排除代码路径? - How do I exclude a code path when running a unit test on iOS? 如何为每个测试提供自己的TestResults文件夹? - How do I give each test its own TestResults folder? 如何在Moq中设置此值以为我提供null或对象? - How do I setup this in Moq to give me null or an object? 是否可以找出由 TFS 上的选定个人签入的变更集的单元测试代码覆盖率? - Is it possible to find out unit test code coverage for changesets checked in by select individuals on TFS? 如何对视图路径进行单元测试? - How do I unit test the view path? 如何访问TFS API或TFS报告中的TestCategory属性? - How can I access The TestCategory attribute in the TFS API or TFS Report? 如何在TFS 2010的Build-Deploy-Test构建中运行许多单元测试? - How do I run many unit tests in Build-Deploy-Test build in TFS 2010?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM