What is the relative path root of DeploymentItemAttribute?

Anthony Mastrean picture Anthony Mastrean · Nov 30, 2009 · Viewed 9.2k times · Source

Using MSTest, what is the relative path root of the DeploymentItemAttribute.

Answer

Anthony Mastrean picture Anthony Mastrean · Nov 30, 2009

Per the MSDN page...

Relative paths are relative to the RelativePathRoot setting found in the .testrunconfig file.

That setting is, by default, the Solution directory. So, if you have this project structure

SecretProject\
    ComponentA\
    ComponentA.Test\
        Resources\
            required.xml
        ComponentA.Test.csproj
        Tests.cs
    SecretProject.sln

And you want to deploy required.xml, you're going to create a DeploymentItemAttribute like this

[TestClass]
public class Tests
{
    [TestMethod]
    [DeploymentItem("ComponentA.Test\Resources\required.xml")]
    public void Test() 
    {

    }
}

It seems the file properties need to be set to 'Content' and 'Copy always' or 'Copy if newer'. There are advanced examples on this MSDN page.