I am working on running automated tests through VSTest or Visual Studio Test instead of the Test Agent inside Visual Studio Team Services and was running into an issue where I wanted the TRX files in the published build artifacts at the end of the build.
The problem was once the VSTest application exits, it deletes the TRX file because it published the results already to the build. The reason I want the TRX files is because I am creating a TRX to MTM publisher application (Coming Soon!) to associate test cases to the automated results.
I tried running a command prompt copy command to put it in a certain location, publishing the TRX via the Copy and Publish Build Artifacts, and using the Copy Files command.
Luckily, after numerous attempts, I was able to solve my issue. It turns out, the Copy Files command runs quick enough to grab the TRX file before VSTest deletes it.
The next issue was putting the file into the correct target folder so the Publish command would pick it up. Below is the command to copy the files to the folder. The copy command did not work with
$(build.artifactstagingdirectory) so we need to add a sub-folder.
After all the other build steps complete, the publish files command can now be called on that folder.
Once everything is built, queue a new build and the TRX files should show up in the artifacts option.