简体   繁体   中英

Invalid use of DeploymentItem - the specified output directory is not relative

I'm trying to use [DeploymentItem] to copy a file to a folder before my test runs:

[TestMethod]
[DeploymentItem("foo.config", @"C:\Program Files (x86)\My Folder\")]
public void MyTest() {
    ....
}

However, when I try to run the test I got this error:

Result Message: UTA041: Invalid use of DeploymentItem attribute on method MyTest: Invalid deployment item: the specified output directory 'C:\\Program Files (x86)\\My Folder\\' is not relative.

Why do I have this error? According to this article , the second argument to [DeploymentItem] can be absolute:

targetFolder is optional. It is the directory into which the source file or directory contents will be copied. The path can be absolute, or relative to the deployment directory. The default value is ".", the deployment directory.

In foo.config 's Properties, the Copy to Output Directory has been set to Copy if newer . If I leave out that second argument of [DeploymentItem] , the file is copied just fine into the test folder.

The problem might be with the content of this article your provided. According to the DeploymentItemAttribute documentation , the targetPath has to be relative.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM