5

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.FileNotFoundException: 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)

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

1 Comment

that's the wrong direction - I want an item copied from a location not to.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.