visual-studio Visual Studio 测试项目 - 在部署时不复制文件夹
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/730822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Test Project - Does not copy folder on deployment
提问by DeeStackOverflow
Here is the problem:
1. Create a TestProject in your Visual Studio solution.
2. Open the .testrunconfig file and under the 'deployment' menu item, select the 'Enable Deployment' checkbox.
3. Now click on 'Add Directory...' button and add a folder which has some files in it.
4. Run the test project (use a dummy test).
问题如下:
1. 在您的 Visual Studio 解决方案中创建一个 TestProject。
2. 打开 .testrunconfig 文件,在“部署”菜单项下,选中“启用部署”复选框。
3. 现在单击“添加目录...”按钮并添加一个包含一些文件的文件夹。
4. 运行测试项目(使用虚拟测试)。
Ok, now go check the TestResults folder: You will see that all the files got directly copied (to the top level)- the folder itself is not copied (with the files under them). This messes up my paths during testing. Can anybody tell how to get the folder copied instead of just the files underneath ?
好的,现在去检查 TestResults 文件夹:您将看到所有文件都被直接复制(到顶层)- 文件夹本身没有被复制(带有它们下面的文件)。这在测试期间弄乱了我的路径。任何人都可以告诉如何复制文件夹而不仅仅是下面的文件吗?
Thanks.
谢谢。
回答by Stefan Steinegger
Use the [DeploymentItem]attribute on the test classes that use it. You can specify a directory:
[DeploymentItem]在使用它的测试类上使用该属性。您可以指定一个目录:
[TestClass]
[DeploymentItem("blahblah\myDirectory", "myDirectory")]
public class MyTest
{
}
Note:
笔记:
- DeploymentItem is very slow when starting the tests. It seems to copy 2 files per second.
- You can specify the attribute on a test base class. But it does not always work if you have more than one test project.
- You can probably specify it on a TestClass that has a method marked with
[AssemblyInitialize]. Then you have only to provide it once. Not sure, you have to try. - The source directory is relative to the solution location. This is hardly documented.
- 开始测试时,DeploymentItem 非常慢。它似乎每秒复制 2 个文件。
- 您可以在测试基类上指定属性。但如果您有多个测试项目,它并不总是有效。
- 您可能可以在具有标记为的方法的 TestClass 上指定它
[AssemblyInitialize]。然后您只需提供一次。不确定,你必须尝试。 - 源目录相对于解决方案位置。这几乎没有记录。
回答by Jaikishan Jalan
Open the .testsettings file in notepad. Now, you should see that for every folder to copy
在记事本中打开 .testsettings 文件。现在,您应该看到每个要复制的文件夹
<DeploymentItem filename="FolderName\" />
Change this to
将此更改为
<DeploymentItem filename="FolderName\" outputDirectory="FolderName\" />
回答by Joey Guerra
I just had this problem too today. I solved it by adding a folder called "deployment_files" in the project that contained the required folder. Then I put the required folder into the "deployment_files" folder. THEN, I opened the LocalTestRun.testrunconfig file under the "Solution Items" folder in the Solution Explorer. Went to the "Deployment" panel in the testrunconfig property window. Added the "deployment_files" directory to the deployment and voila. The folder within that was copied to the test results Out folder.
我今天也刚遇到这个问题。我通过在包含所需文件夹的项目中添加一个名为“deployment_files”的文件夹来解决它。然后我将所需的文件夹放入“deployment_files”文件夹中。然后,我打开了解决方案资源管理器中“解决方案项目”文件夹下的 LocalTestRun.testrunconfig 文件。转到 testrunconfig 属性窗口中的“部署”面板。将“deployment_files”目录添加到部署中,瞧。其中的文件夹已复制到测试结果 Out 文件夹。
回答by Joey Guerra
The other option you have is to create another folder beneath the original folder, and then that folder will be deployed to the out directory. For example you can have this structure:
您的另一个选择是在原始文件夹下创建另一个文件夹,然后该文件夹将部署到 out 目录。例如,您可以具有以下结构:
TestFolder/
测试文件夹/
TestFolder/TestDeployment/
测试文件夹/测试部署/
And then in the testrunconfig you still select the TestFolder folder and the TestDeployment folder will be deployed to the out directory.
然后在 testrunconfig 中,您仍然选择 TestFolder 文件夹,TestDeployment 文件夹将部署到 out 目录。

