Reliable locate mstest.exe from msbuild - msbuild

there are some questions about this around here, but none has a valid (for me) answer. The question is:
Is there a way to determine the location of mstest.exe from within a msbuild project, without hardcoding either the path or using the $(VSxxComnTools) or $(VSINSTALLDIR) variables?
Reason for the latter is, because this needs to run on a build server (non-TFS but Bamboo or TeamCity) that only has the VS Test Agents installed and not a full VS.
Additional Info: Of course, this must also work on every other machine that has msbuild, the c# compiler and mstest installed, because everybody should be able to check out the project from github, call the msbuild and everything should run just smoothly.

You could use
$(MSBuildProgramFiles32)\Microsoft Visual Studio 11.0\Common7\Ide
This assumes you are working with the same version ie 2012 of the skus on all your assets. Ofcourse you can easily create fallbacks to other versions in your project itself.
Refer Use 32bit "Program Files" directory in msbuild.

It's not elegant, but a reliable way to find the latest MSTest.exe installed on a host is
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe</MSTestPath>
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 13.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 13.0\Common7\IDE\MSTest.exe</MSTestPath>
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 12.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 12.0\Common7\IDE\MSTest.exe</MSTestPath>
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 11.0\Common7\IDE\MSTest.exe</MSTestPath>
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 10.0\Common7\IDE\MSTest.exe</MSTestPath>
<MSTestPath Condition="'$(MSTestPath)'=='' And Exists('$(MSBuildProgramFiles32)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe')">$(MSBuildProgramFiles32)\Microsoft Visual Studio 9.0\Common7\IDE\MSTest.exe</MSTestPath>

You could add an machine environment variable that points to it and reference that in msbuild? So if you added the var MSTEST_HOME you could use $(MSTEST_HOME) in msbuild?

Related

Not able to restore nuget packages/Manage nuget packages not working in visual studio 2017

I tried to open a .Net Core solution which was working fine in 2015. Recently they added some .Net Core projects to the solution and asked us to upgrade to Visual Studio 2017 to be able to run them. We installed Visual Studio 2017 and tried to open the solution, but I am not able to build it. I get the following errors when I right-click and try to select "Manage Nuget packages".
I tried to open the PackageManager console from Tools: even this is not working
I also performed the "repair Visual Studio" process too.
Finally i resolved it by deleting my nuget.config both at project level and also in %appdata%/roaming/nuget .I think the issue is because of broken config file due to change from visual 2015 to visual studio 2017 .Not sure about the exact issue though

msbuild fails to compile vsto project

We recently installed a new development environment (Windows 10) from scratch with Visual Studio 2017 but we cannot manage to make msbuild compile a Microsoft Office Addin for Word (vsto).
Within the Visual Studio installer we made sure to include the required components for Office Development.
It throws the following error (german translated to english)
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" was not found. Also, tried to find "OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" [...]
However, the project builds fine within Visual Studio.
On the old system, everything works fine, and i cannot remember having to configure anything at all.
You need to install Office build tools when installing Build Tools for Visual Studio 2017
In my case, I managed to get around the issue by copying the folder
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio
from the development environment (the old environment in your case) to
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio
on the build environment (the new environment in your case). I would have thought that one should be able to simply get the relevant targets from the Build Tools for Visual Studio 2017 but that appears not to be the case.
After reinstalling everything it works now.
I guess back then when we set up this machine, the build tools setup was bugged or something.
Now we could install everything we needed for the buildtools using the visual studio installer and it works like a charm.
Okay, so I've worked through this one now. The problem was caused by me using Windows\Microsoft.NET\Framework64\v4...\Msbuild.exe.
It looks as though running msbuild from this location results in it not being able to implicitly locate many of the assemblies and build utilities required to build a VSTO project.
I resolved the problem by switching to using C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe

How to use Visual Studio 2017 with TFS Visual Studio Build Step

I am running TFS 2015 and are using the Visual Studio Build Step. On the developemnt machines I moved to use Visual Studio 2017 so I also want to use Visual Studio 2017 for the TFS builds.
I installed Visual Studio 2017 on the build server and restarted the build agent. However Visual Studio 2017 does not show up in the capabilities of the agent and it also does not show in the list of Visual Studio versions in the build step.
I know I can choose "latest" from the list of Visual Studio version in the build step, but this will still use VS 2015 as the agent does not know that it has VS 2017.
How can I make sure that the Visual Studio Build Step in TFS2015 uses Visual Studio 2017?
You can use MSBuild task instead of Visual Studio Build Step, then specify the location of MSBuild 15.0:
In TFS 2015 the build steps and forward compatibility is only updated when TFS is updated. If you are using TFS 2015.3 already then you will need to move to TFS 2017 to use this out of the box.
The build step ultimately calls out to devenv.exe and the drop down changes the path. You can call out manually to VS 2017...

TFS 2015 visual studio build task does not support VS 2017

We have a build definition in TFS 2015 that have worked fine with Visual Studio 2015 projects and solutions. We have now decided to upgrade to Visual Studio 2017 and thus we would like to target Visual Studio 2017 in the Visual Studio build task. We have installed Visual Studio 2017 on the build agent. Unfortunately the only options available int the Visual Studio build task are 2012, 2013, 2015 and Latest. We have tried latest but it does not find Visual Studio 2017 on the build agent. It won't work with the msbuild task either.
I have a similiar issue and resolved by installing VS2017 in my build agent server and configuring MSBuild to point to my MSBuild 15.0 folder:
Add MSBuild to your build steps
On the Advanced options, expand and fill the 'Path to MSBuild' like the image below:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
VS2017 RTM is released recently while TFS2015 was released before. That's why there is no VS2017 option in VS Build Task in TFS2015 Server. If you upgrade your server to the latest TFS2017, you would see "Visual Studio "15" (preview)" option listed in VS Build Task which is the version for VS2017 preview. And in the feature, the option will be updated to VS2017 which is the same as VSTS.
we are facing a similar issue and it is not possible for us to update ourselves as it is maintained on a company level where we cannot take that much influence.
However our team wanted to switch to VS2017 and make use of the C# 7 features. That's why we tried it as well with replacing the build steps from Visual Studio Build to MSBuild. Sadly this did not work as expected (we got some errors during the build).
As our main objective is to use the C# 7 features we looked for a way how to still achieve that at the time with Visual Studio 2015 remaining on the Build Server. We ended up using the nuget package Microsoft.Net.Compilers that, when used in a project, will use that compiler instead of the installed one.
More on this can be found in this Thread.
It seems the updates to the build tools are installed via the command line of the VS2017 installer.
See the docs for details.
Just adding another thing: if you're using custom build template make sure to edit it and modify the ToolPath attribute value to:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin

WebSocket4Net - The software is missing from your system. You may also have to configure it after installation

I've been trying to use Apache Cordova in Visual Studio 2015 CTP, but I'm getting error: "WebSocket4Net, The software is missing from your system. You may also have to configure it after installation.". I've tried:
Reinstall Visual Studio 2015 (and deleted previous version - 2013). In the setup I've marked Cordova tools.
I found some suggestion to download WebSocket4Net(0.9).Binaries.zip from CodePlex and copy it to specified folder. However, the file WebSocket4Net.dll I've already there in the folder c:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\WebClient\Diagnostics\ToolWindows and looks it doesn't matter.
Environment: Windows 7 Professional
Any idea what can be done yet to fix this problem?
If you're installing Visual Studio 2015 copy it to:
C:\Program Files (x86)\Microsoft Visual Studio
12.0\Common7\IDE\CommonExtensions\Microsoft\WebClient\Diagnostics\ToolWindows.
Microsoft Visual Studio 12.0