Upgraded from VS2019 to VS2022 and now msbuild throws "target 'Build' does not exist in the project" error - msbuild

I wrote my small F# library in Visual Studio 2019, using msbuild v16. I just upgraded to Visual Studio 2022 with msbuild v17. While my solution still builds in Visual
Studio 2022, it does not build from the command line using msbuild, like:
msbuild MyLib.sln
When I run the msbuild command I get the error:
MSB4057: The target 'Build' does not exist in the project
I can't figure out why msbuild would succeed when called by Visual Studio, but not from the command line.

Related

How can override platform tool set for msbuild from command line? How I am doing it is not working

I am pulling in open source project but it is configured to build using MS VS 2015. I am trying to override this command line option on msbuild. But is still tries to use MSVS 2015. Following is my command invocation:
msbuild path/to/solution/file/file.sln /p:ToolsVersion=15.0 /p:PlatormToolset=v141 /p:WindowsTargetPlatformVersion=10.0.19041.0 /p:Configuration=Release
I get following error:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.target
s(67,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 b
uild tools, please install v140 build tools. Alternatively, you may upgrade to the current Visual Studio tools by sele
cting the Project menu or right-click the solution, and then selecting "Retarget solution".

TFS build agent cannot find AXImp.exe

TFS build agent using MSBuild 14.0 fails with "Error MSB3091: Task failed because "AxImp.exe" was not found", while the SDK is installed and AxImp.exe is present.
The error states that it cannot find the file in the bin beneath "the location specified in the InstallationFolder value of the registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\NETFXSDK\4.6\WinSDK-NetFx40Tools-x86"
There is no "Microsoft SDKs" node at that location, however it does exist under Wow6432Node: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\NETFXSDK\4.6.2\
This node contains references to locations for both WinSDK-NetFx40Tools-x86 and WinSDK-NetFx40Tools-x64.
Is MSBuild looking in the wrong registry location?
Can I configure the build to make it locate either
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools
or
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.2 Tools\x64
to find AxImp.exe and whatever else it expects from the SDK?
Background:
Our development has so far been built on Windows 10, Visual Studio 2017, targeting .Net Framework 4.6.2. I am now trying to automate builds on Windows Server 2012 R2 Standard.
I have installed Microsoft Build Tools 2015, Microsoft .Net Framework 4.6.2 SDK, .Net Framework 4.6.2 Targeting Pack and .Net Framework 4.6.2 Targeting Pack (ENU).
Have successfully created a build agent and get an almost successful build, after chasing down a number of missing dependencies.
TFS build agent cannot find AXImp.exe
(According to the error messages, they are all common errors. we could not give the most direct correct answer for this issue, we can only give you some troubleshootings. In order to avoid losing contact in the round-trip comments, I post those troubleshootings as answer instead of comments.)
Make sure using the MSBuild task instead of Visual Studio build task in the build definition.
Using MSBuild 14.0 (C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe) rather than 4.0 (C:\Windows\Microsoft.NET\Framework\v4.0.30319) in the MSBuild task, if you build the project with Visual Studio 2015.
Check if the ToolsVersion of the Project node is 14.0 not 4.0:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Install the Visual Studio 2015 on your build server.
Manually change the above registry key to the correct location, where AXImp.exe exists.
If all above not help you, please share the configuration of MSBuild task definition, the software you have installed on the build agent and try to build the project with Visual Studio 2015 on the build server.
Hope this helps.

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

TFS 2015 Build,Tests not running in Visual Studio Test build step or vstest.console.exe

After upgrading both Team Foundation Server and Visual Studio from 2013 update 4 to 2015, i created a build in the new build system.
The build includes only two steps: One Visual Studio Build step and one Visual Studio Test step. There's only one single simple solution with a class library project and a test project.
The Build step runs fine. The Test step does nothing. It just says
Starting test execution, please wait...
but the test are not running.
When i edit the VS Test step in the build definition and set the VSTest version to "Visual Studio 2013" instead of "Visual Studio 2015", everything works fine and it outputs as expected:
Starting test execution, please wait...
Passed <nameoftest1>
Passed <nameoftest2>
Passed <nameoftest3>
Passed <nameoftest4>
etc
I found out that during that build step, the following line gets executed:
C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe "C:\pathToTestDll\TestProject.dll
So i tried to run this from commandline on my own pc, and found out that when i use vstest.console.exe from the Visual Studio 12.0 folder, everything works fine, but when i use vstest.console from the Visual Studio 14.0 folder, the tests are not running.
I also found out that when i run the command prompt as administrator, it runs all the tests with vstest.console from the Visual Studio 14.0 folder.
Has anybody also had this issue, or is there a way to run the whole build (or just the test step) with elevated rights, so i can run my tests with the VSTest Version set to Visual Studio 2015?

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...