简体   繁体   English

DeploymentItem不部署文件

[英]DeploymentItem not deploying files

I am using MS unit testing framework for testing my C# library. 我正在使用MS unit testing framework来测试我的C#库。 I have to open a file which I'm deploying using DeploymentItem attribute . 我必须使用DeploymentItem attribute打开我正在部署的文件。 But it is not deploying file to the Test deployment directory. 但它没有将文件部署到Test部署目录。

In my Unit-test project, I created a folder TestFile in this folder there are multiple files, lets say a.txt, b.txt. 在我的Unit-test项目中,我在这个文件夹中创建了一个文件夹TestFile ,有多个文件,比方说a.txt,b.txt。

Now in my Unit-test class I added DeploymentItem attribute. 现在在我的Unit-test类中,我添加了DeploymentItem属性。 But file is not being copied. 但文件没有被复制。

Here is my code. 这是我的代码。

[TestClass]
[DeploymentItem("TestFile")]
public class CustomLibraryTest
{
    public TestContext TestContext { get; set; }

    [TestMethod]
    [DeploymentItem(@"TestFiles\a.txt")]  // THis should deploy a.txt to test deployment directory
    {
        var path = TestContext.TestDeploymentDir + "a.txt";
        // Now when I debug this unit-test, and open path in explorer,
        // a.txt is not present in "TestResults\Deploy_fhafeez 2013-05-28 13_02_37\Out" folder
    }
}

What I am doing wrong? 我做错了什么?

I have found two possible solutions in this thread : 我在这个帖子中找到了两个可能的解决方案:

  1. Set the "Copy To Output Folder" property of your deployment files to "Copy Always" (see Problems with DeploymentItem attribute ) 将部署文件的“复制到输出文件夹”属性设置为“始终复制”(请参阅DeploymentItem属性的问题
  2. Check the "Enable Deployment" setting in the Local.testsettings file (see Problems with DeploymentItem attribute ) 检查Local.testsettings文件中的“启用部署”设置(请参阅DeploymentItem属性的问题

Hope this helps. 希望这可以帮助。

For future references, from what I have noticed using VS 2015 - the path you specify in the deployment item attribute must be relative to the build output (debug folder). 对于将来的引用,从我注意到使用VS 2015 - 您在部署项属性中指定的路径必须相对于构建输出(调试文件夹)。 If your folder structure is "UnitTesting\\TestData\\Test.xml" the DeploymentItem must be DeploymentItem("..\\..\\TestData\\Test.xml") In this case, the TestData folder need not be included in the UnitTesting project. 如果您的文件夹结构是“UnitTesting \\ TestData \\ Test.xml”,则DeploymentItem必须是DeploymentItem(“.. \\ .. \\ TestData \\ Test.xml”)在这种情况下,TestData文件夹不需要包含在UnitTesting项目中。

I had a set of tests where the copy was working for some tests but not the latest, even though the DeploymentItem attribute was set exactly the same way. 我有一组测试,其中副本用于某些测试但不是最新的,即使DeploymentItem属性设置完全相同。 After exhausting everything else, I did a "Clean solution" on the solution and reran and it started copying correctly. 在完成其他所有操作后,我在解决方案上做了一个“清洁解决方案”并重新启动并开始正确复制。 YMMV 因人而异

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

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