MSBuild in Visual Studio 2017: Cannot set path within Command Prompt - msbuild

I'm trying to have MSBuild for Visual Studio 2017 run in my PATH on Windows 10. I recently completed this task on another machine that was using Visual Studio 2015 no problem using this command:
"%comspec% /k""C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\VsMSBuildCmd.bat""
I noticed that for Visual Studio 2017, VsMSBuildCmd.bat is within C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools
So I tried running the %comspec% command above with this folder but it's not working.
Any help would be greatly appreciated!

I was able to get MSBuild up and running even after I typed the comspec statement above with the error appearing my command prompt. I'm not really sure if that is a Windows 10 bug.

Related

Invalid static method invocation syntax: "[MSBuild]::IsRunningFromVisualStudio()"

After upgrading to Visual Studio 2017 15.5 none of my project will load correctly. All are marked unavailable.
I'm getting the following error for every project:
error : Invalid static method invocation syntax: "[MSBuild]::IsRunningFromVisualStudio()". Method '[MSBuild]::IsRunningFromVisualStudio' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(a, b)). C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
Reloading project produces this error prompt:
Adding new projects produce this error prompt:
1. Close all running instances of Visual Studio 2017
2. Launch (as Administrator) "Developer Command Prompt for VS 2017"
3. Type the following commands (replace Professional with your edition, either Enterprise or Community, or adjust the path accordingly):
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Framework.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Engine.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Conversion.Core.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Tasks.Core.dll"
gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll"
4. Restart Visual Studio 2017
The solution, provided by henkmollema in this thread: https://github.com/Microsoft/msbuild/issues/2775 was to start the visual studio installer from the start menu and run a repair.
It seems from the responses to this issue on github that it is often caused by having an older version of MSBuild in the GAC. This will then be used in preference to the bundled version that ships with the updated version of VS.
The solution is to remove the old version of Microsoft.Build from the gac.
Find the gac'd versions:
gacutil /l | findstr Microsoft.Build
Look for any of version 15.x.x.x and then remove them:
gacutil /u "Microsoft.Build, Version=15.{version_found}"
Restart Visual Studio
It may also be necessary to remove the related assemblies Microsoft.Build.Utilities.Core, Microsoft.Build.Framework and Microsoft.Build.Tasks.Core of that version.
After installing the latest Visual Studio Version via the Updater, I received the same error messages.
The issue was resolved, at least in my case, by rebooting after installing the Visual Studio update.
Besides the assemblies mentioned in Yuriy Oleynik's answer, I found I need to add an additional assembly (see the last command below) in gac (I'm using VS 2019):
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Conversion.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Engine.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Framework.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Tasks.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\Microsoft.Build.Utilities.Core.dll"
gacutil.exe -i "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\amd64\System.Collections.Immutable.dll"
I've come accross this problem in vs2019 with Framework Core 3.1. The problem was two fold.
First of all i've updated my VS2019 to the last version, the project was loading, but I got compilation errors.
I've opened C:\Windows\Microsoft.NET\assembly\GAC_MSIL and removed all microsoft.buid.* except Microsoft.Build.Utilities.Core, Microsoft.Build.Utilities.v4.0 and Microsoft.Build.Utilities.v4.0.resources
And all worked
I had this problem with Visual Studio 2017 on a Windows 7 PC on a corporate network. I tried to fix the issue in the following ways:
restarting the computer/Visual Studio several times (as mentioned by an answer here).
upgrading to the newest version of Visual Studio found in "Extensions and Updates"
Using the "Repair" option in the installer.
Uninstalling it completely by uninstalling the "Visual Studio Installer" (Control Panel → Add remove programs), and then re-installing it.
I noticed that on a colleague's computer, which never had VS2017 installed, when I installed VS2017 Community Edition version 15.5, there was no issue.
At this point, I have to admit defeat. The only simple solution is to replace the line in the file:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets
There is a line near the end of the file:
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'=='' and '$([MSBuild]::IsRunningFromVisualStudio())'=='true'">$(MSBuildToolsPath32)\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>
just replace the $([MSBuild]::IsRunningFromVisualStudio()) with true:
<NuGetRestoreTargets Condition="'$(NuGetRestoreTargets)'=='' and 'true'=='true'">$(MSBuildToolsPath32)\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.targets</NuGetRestoreTargets>
however this only allows the projects to load up - you cannot use it to build the project.
I am going to ask for my machine to be re-imaged so I can just download and install Visual Studio from scratch.
(I hope Microsoft come up with a fix soon.)

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

Where can I find WcfTestClient.exe (part of Visual Studio)

The MSDN docs state that I can find the WCF Test Client in:
C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
but it seems like a lot of stuff is missing from there, including WcfTestClient.exe.
What do I need to install?
C:\Program Files (x86)\Microsoft Visual Studio (Your Version Here)\Common7\IDE
VS 2022 Professional:
C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\WcfTestClient.exe
VS 2022 Community:
C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\WcfTestClient.exe
VS 2022 Enterprise:
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\WcfTestClient.exe
VS 2019 Professional:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\WcfTestClient.exe
VS 2019 Community:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\WcfTestClient.exe
VS 2019 Enterprise:
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\WcfTestClient.exe
VS 2017 Community:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\WcfTestClient.exe
VS 2017 Professional:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\WcfTestClient.exe
VS 2017 Enterprise:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\WcfTestClient.exe
VS 2015:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\WcfTestClient.exe
VS 2013:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\WcfTestClient.exe
VS 2012:
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\WcfTestClient.exe
The prerequisite to have WcfTestClient is to have Windows Communication Foundation component installed. If WcfTestClient is missing, install it by modifying Visual Studio:
Control Panel > Apps & Features > Visual Studio (your version)
In Visual Studio Installer, click on Modify, choose Individual components tab and then select (see below screenshot):
☑ Windows Communication Foundation
Click on Modify and voilà, application will be on your disk.
If you want to use WcfTestClient with no Visual Studio, see answer(s) on: How can the Wcf Test Client be used without Visual Studio?
In addition, one can add this to the Visual Studio Tools menu.
Tools => External Tools.
And then in the Command box enter the path for WcfTestClient.exe.
In my case
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\WcfTestClient.exe
FYI - I could not find WcfTestClient.exe under any of the listed file paths. It turns out it needed to be installed by Visual Studio Installer. When you launch the installer and modify your version of VS, make sure Windows Communication Foundation is checked under Optional. It may seem obvious, but it wasn't to me and therefore might not be obvious to everyone else.
You won't find the component if it hasn't been installed.
In Visual Studio 2019 go to:
Tools > Get Tools and Features > Select the Individual Components tab > Type wcf in the search box and install it.
This installs the component, and you should be able to load it from the command prompt or other methods suggested in the answer.
If you use "Developer Command Prompt" you can just type WcfTestClient to start it or type where wcftestclient to find the location.
For Visual studio 2013, Windows 8...
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\WcfTestClient.exe
New Direction on VS 2017 (x64 systems)
"C:\Program Files (x86)\Microsoft Visual Studio\2017\*your lic type*\Common7\IDE\WcfTestClient.exe"
Mine was here:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE"
For 64 bit OS, its here (If .Net 4.5) : C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE

How to build a VS2015 solution that has a VS2010 configuration using MSBuild?

I want to build a Visual Studio 2015 C++ solution from the command line using MSBuild. The complication is that I want to build a particular configuration of the solution, which uses the Visual Studio 2010 toolset (necessary because I am linking to a 3rd party library).
I have used MSBuild successfully in the past, but am unsure of which versions of MSBuild and vcvarsall.bat to use in this case. Currently I am running:
"\Program Files (x86)\Microsoft Visual Studio 10.0\VC\vcvarsall.bat"
"\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" mysolution2015.sln /p:Configuration="2010_Config" /p:useenv=true
but that gives error:
LINK : fatal error LNK1117: syntax error in option 'manifest:embed'
Any help would be appreciated.
You should be using the vcvarsall.bat from VS2015 ("\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat")
The chosen configuration will select the appropriate toolset (assuming you have both VS2015 and VS2010 installed).
You can then simply use msbuild has it will have been added to the path...