What is the relative path root of DeploymentItemAttribute?

前端 未结 3 1490
清歌不尽
清歌不尽 2021-02-05 13:42

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

3条回答
  •  一个人的身影
    2021-02-05 13:53

    So I'm gonna add my experience.

    So if you're using .testrunconfig file, that will trump (override) what I'm saying below.

    I figured there were a few options.

    Relative to the current .csproj

    Relative to the .sln

    Relative to the current .cs file

    I finally got my build system working by using the "relative to the current .cs file" approach.

    In my example, I needed a Xsd from a different project copied over for my UnitTest. But the type of file does not matter.

    Example:

    c:\myfolder\MyXsdProject\XSDs\MyCoolXsd.xsd

    c:\myfolder\MyCsharpUnitTestProject\MySubFolder1\MySubFolder2\MyUnitTestClass.cs

    namespace MyCsharpUnitTestProject.MySubFolder1.MySubFolder2
    {
    
        [TestClass]
        [DeploymentItem(@"..\..\..\MyXsdProject\XSDs\MyCoolXsd.xsd")]
    
        public class MyUnitTestClass
        {
        }
    }
    

提交回复
热议问题