开发者

MsTest: how to set the deployment item relative to either $(ProjectDir) or $(OutDir)

I want to add an deployment item to my test. As far as I understood up until now, the path is relative to the solution. I want the path to be relative to the project. Otherwise, the project can't be used in multiple solutions. How can I configure the deployment Item to be relative to a project dependent variable?

I was hoping for something like: [DeploymentItem(@"$(ProjectDir)..\..\bin\$(Configuration)")] but I don't find any documentation and it does not seem to work.


I just did a small test. Just plain wizard code and one deployment item:

[TestMethod]
[DeploymentItem("stdafx.cpp")]
void TestMethod1()
{
    Assert::Fail();
};

and the trx file shows the following line:

Warning: Test Run deployment issue: Failed to get the file for deployment item 'stdafx.cpp' specified by the test 'TestProject1.UnitTest1.TestMethod1': System.IO.FileNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'. System.IO.Fil开发者_StackOverflow中文版eNotFoundException: Could not find file 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'. File name: 'd:\Development\Projects\deploymentItemTest\stdafx.cpp'

which means that "stdafx.cpp" is searched relative to the solution directory (which is in ...\depoymentItemTest) and not the project directory (which is in ...\depolymentItemTest\TestProject1)


I know this is an old question, but my answer may help others. I was able to solve this problem with two simple steps:

  1. Create the following build event on the test project:

    xcopy /I /S /Y  "$(TargetDir)*.*" "$(SolutionDir)\bin"
    

    This will copy all the contents (including sub-directories) of the project folder to a folder "bin" relative to the solution.

  2. Add the following DeploymentItem to the test class:

    [DeploymentItem ("bin")]
    

    This will copy all the bin contentes to the test folder

This mechanism may be refined (if required) with additional filters both in the build event and the DeploymentItem


Let the test setup copy the file to Environment.CurrentDirectory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜