When you do test runs with the Test Explorer in Visual Studio, you can select to use either a x86 or a x64 test runner. Now, if you select to create an AnyCPU target for that component, it will not matter which one you choose, but if you select a target x86 or x64, the selected test runner has to match the selected target. Otherwise no tests will be visible in the Test Explorer.
You do this selection from the Test menu, Test Settings/Default Processor Architecture, and select appropriately x86 or x64.
Now, this is good for Visual Studio, but when you try to execute your tests in TFS (or VSTS), using the default vNext build template with the Visual Studio Test activity, no tests shows up, even if it looks like you have specified it to run using the correct build platform (x86 or x64)
If you look closer, you see that it is only the reporting that is set, not the execution, and there is NO place for setting it.
The way to solve this is to include a runsettings file, with the appropriate setting, and check it in with your source. Now, including a runsettings file may come with some other issues, like how is it supposed to look, values to set and so on. To make this easier, use a ready made template:
1) I have an item template at the Visual Studio Gallery with three different templates for runsettings. Install this and you will see 3 new items when you do a Add new item to your solution. On the VSG site there are also links to more information on these templates.
2) We need to modify the item a bit, so if you don’t require code coverage, and you don’t want to delete a lot of stuff that might get in your way, use the simplest one which is the Parallel one.
Select Add new item from the context menu on the Solution node in the solution explorer:
I named the file target.runsettings, and it looks like this OOB:
<?xml version="1.0" encoding="utf-8"?> <RunSettings> <RunConfiguration> <!-- 0 = As many processes as possible, limited by number of cores on machine, 1 = Sequential (1 process), 2-> Given number of processes up to limit by number of cores on machine--> <MaxCpuCount>0</MaxCpuCount> </RunConfiguration> </RunSettings>
Now, just add the setting for the execution engine to this one, and set the parallel to 1, if you want to have it run sequentially – which should be the default for server builds. It should then look like this, given you run in x64 (otherwise set it to x86)
<?xml version="1.0" encoding="utf-8"?> <RunSettings> <RunConfiguration> <!-- [x86] | x64 --> <TargetPlatform>x64</TargetPlatform> <!-- 0 = As many processes as possible, limited by number of cores on machine, 1 = Sequential (1 process), 2-> Given number of processes up to limit by number of cores on machine--> <MaxCpuCount>1</MaxCpuCount> </RunConfiguration> </RunSettings>
Now go back to your Build Definition and add the runsettings file there under Execution Options:
Note that you can give the path both as a server path – which works well with TFS Old VC, or as a relative path from your defined root, defined either by your source mappings or from the root of your git repository.
When you upgrade your Visual Studio, the item templates may disappear. They are still there, but to get them visible again you must delete your MEF cache. For executables you get a loading error, but for item templates – they just go missing: Easy way to fix that: See https://hermit.no/how-to-fix-visual-studio-loading-errors-using-ifix/