DeploymentItem not deploying files

fhnaseer picture fhnaseer · May 28, 2013 · Viewed 25.7k times · Source

I am using MS unit testing framework for testing my C# library. I have to open a file which I'm deploying using DeploymentItem attribute. But it is not deploying file to the Test deployment directory.

In my Unit-test project, I created a folder TestFile in this folder there are multiple files, lets say a.txt, b.txt.

Now in my Unit-test class I added DeploymentItem attribute. 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?

Answer

Erik Schierboom picture Erik Schierboom · May 28, 2013

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)
  2. Check the "Enable Deployment" setting in the Local.testsettings file (see Problems with DeploymentItem attribute)

Hope this helps.