msbuild fails in Teamcity - visual-studio

I might be missing something really simple here. I'm trying to build a solution in Teamcity using msbuild but it always keeps failing with the below error.
'msbuild' is not recognized as an internal or external command,
operable program or batch file.
I have VS2017 installed and when I run the solution locally through command line on the same Teamcity agent, it works perfectly with the following comments.
Microsoft (R) Build Engine version 15.4.8.50001 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
But for some reason it always fails on teamcity. I'm at a loss as to what am I missing here. Any pointers are greatly appreciated.
Following is the command that I'm using to compile the solution
msbuild hello.sln /t:Rebuild

msbuild fails in Teamcity
Agree with stijn. According to the error log, it seems MSBuild not in the default path, so it could not be found.
To resolve this issue, you should make sure you have installed the Visual Studio 2017 or Microsoft Build Tools on the teamcity agent and need to properly configure your build runner, especially MSBuild version.
Besides, you can also try to create environment variable "MSBuild" and set it to the path of MSBuild.exe in your teamcity agent.
The default path of MSBuild for Visual Studio 2017 is:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin
If above not help you, please share us your configuration about Build Runner.

Related

Visual Studio Build Not Deploying Upon Build

I am trying to do a Visual Studio Build on TFS 2017. So far, it seems to do the build, but will not do the standard Publish/Deploy I am used to on my local file system, with the Precompiled WCF app, etc. This is what I have so far attached as images, and the PublishProfile I have switched to in desperation. They have VS 2017 installed on the build server, and have updated the MS Build to the latest version. Please help! :)
Visual Studio Build
VM Deploy XML
Check the build log to see whether the deployment executed.
Run the MSBuild command locally on the build agent machine to see whether it works.
Try the following arguments:
/p:SkipInvalidConfigurations=true /p:DeployOnBuild=true /p:WebPublishMethod=FileSystem /p:publishUrl="$(build.artifactstagingdirectory)\\" /p:DeployDefaultTarget=WebPublish

merge conflict using msbuild sonarquberunner

As a part of code quality we run svn update followed by msbuild.exe "project.sln" /t:Build /m:1 /clp:ErrorsOnly" and thereafter msbuild sonarqube runner. Few times I receive error mentioned below and upon investigating code checkout folder finds a merge conflict. As am only using svn update what would be the cause of same to be noted that on revert project gets executed fine and there are no conflicts in svn repo
ERROR LOG
Microsoft (R) Build Engine version 14.0.24720.0
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4381,5): error MSB3541: Files has invalid value "<<<<<<< .mine". Illegal characters in path. [D:\SNRProjs\Scheduler.Business.csproj]
Solution in comments by Freddy - SonarSource Team worked for me. Use of new Sonarqube Scanner for MSBUILD required.

VS 2013 and MSBuild

I've recently upgraded to Visual Studio 2013, which has caused back to back problems when building externally using MSBuild (API or Executable with command line args)
Issue #1
When building with MSBuild it doesn't generate Fake assemblies which are required for our Unit Tests, this leads to build failures. A simple build in visual studio fixes this temporarily, until a new fake assembly needs to be generated.
Issue #2
When running code analysis this complains with the following:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(284,5):
error MSB4127: The "CodeAnalysis" task could not be instantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\.\FxCopTask.dll".
Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.CodeAnalysis' to type 'Microsoft.Build.Framework.ITask'.
I only have Visual Studio 2013 installed on my machine, apparently installing an older version could fix the issue, but it's not something which I can do. (VS 2013 Ships with its own MSBuild 12.0 which is located in a different directory to the previous MSBuild).
I'm unsure why Visual Studio is behaving any differently to MSBuild, i'm simply pointing to the solution file like so...
msbuild.exe "path\solution.sln" /property:Configuration=Debug
So, Visual Studio 2013 comes with a new version of MSBuild i.e. MSBuild 12.0. Once installed, it changes the path so that the new version is used by default.
Looks like your solution compiles with visual studio 2012, you can either specify the full path to msbuild.exe such as
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild "path\solution.sln" /property:Configuration=Debug
or set the visual studio 2012 environment variables by running the following before executing msbuild
"%VS110COMNTOOLS%"\vsvars32.bat // VS2012 environment variables
EDIT: Using MSbuild 12.0 assemblies "C:\Program Files (x86)\MSBuild\12.0\Bin\" fixes the issue with the code Analysis bug.

MsTest fails when running unit tests as part of CI using TFS 2008

My configuration:
VS2010 solution
TFS 2008
Build server - TFS 2008
Build server also has VS2008 Team Suite and VS2010 ultimate installed
TFS 2008 builds my VS2010 solution properly. But when it comes time to run the unit tests I get the following MsTest error.
Using "TestToolsTask" task from
assembly "D:\Program Files\Microsoft
Visual Studio
9.0\Common7\IDE\PrivateAssemblies\Microsoft.VisualStudio.QualityTools.MSBuildTasks.dll".
Task "TestToolsTask" Command:
d:\Program Files\Microsoft Visual
Studio 10.0\Common7\IDE\MSTest.exe
/nologo
/searchpathroot:"D:\Builds\App\Source\86\Binaries"
/resultsfileroot:"D:\Builds\App\Source\86\TestResults"
/testcontainer:"D:\Builds\App\Source\86\Binaries\\Tests.dll"
/publish:"http://tfsServer:8080/"
/publishbuild:"vstfs:///Build/Build/26029"
/teamproject:"Proposal" The
"TestToolsTask" task is using
"MSTest.exe" from "d:\Program
Files\Microsoft Visual Studio
10.0\Common7\IDE\MSTest.exe". No platform specified for publish
operation. For switch syntax, type
"MSTest /help"
MSBUILD : warning MSB6006: "MSTest.exe" exited with code 1.
[D:\Builds\App\Source\86\BuildType\TFSBuild.proj]
The previous error was converted to a
warning because the task was called
with ContinueOnError=true. Build
continuing because "ContinueOnError"
on the task "TestToolsTask" is set to
"true". Done executing task
"TestToolsTask" -- FAILED.
I am not sure what is causing MsTest to fail.
Things tried:
- Provided write access to the build folder to the service account that builds the source on the build machine
You can execute a VS2010 build from within TFS2008's MSBuild, but it looks as if it's using Visual Studio 9.0 TestToolsTask (2008) to try to run a Visual Studio 10.0 (2010) test project (MSTest.exe). I'd try tweaking MSBuild to run the TestToolsTask from the "Microsoft Visual Studio 10.0" folder rather than "9.0", so that the entire process is using the same version of the tools. You can override the tools paths in your tfsbuild.proj file's Properties to ensure the correct version of Visual Studio is used to build with - something similar may apply to the test tools.
Alternatively, it's running the VS2010 test tools correctly, but still trying to use a command line that is specific to 2008 - check the settings and see if you can tweak the command line (you may need to override the MS targets files that is running the build if it's a 2008 version). For example in TFS 2010, a lot of command lines changed from using a simple "server:MyServer" to something like "collection:http://MyServer:8080/tfs/MyCollection". You may therefore have to alter the command line to gain full compatibility with the 2010 version of the tool that is now running, even if it still ultimately points at a 2008 server.
My third suggestion (which isn't necessarily very helpful) is to just upgrade to TFS2010 - it's typically a painless install, vastly better than 2008, and will eliminate any difficulties caused by using a hybrid 2008/2010 setup. (If it helps, I was reluctant to upgrade to 2010 because the 2005->2008 upgrade was 8 days of sheer hell. But in comparison the core of the upgrade to 2010 only took a few hours and "just worked" - the install/upgrade process is much improved)
Jason had the correct idea that lead me down to the correct solution.
In my case, I had to update the "Microsoft.TeamFoundation.Build.targets" to point to "Microsoft.TeamFoundation.Build.ProcessComponents.dll" (VS2010 dll) instead of "Microsoft.VisualStudio.QualityTools.MSBuildTasks.dll" (VS2008 dll)
I also had to make sure that the PlatformToBuild was specified in the TfsBuild.proj file.
Once these 2 steps were done, UnitTests were being run as part of the CI build using TFS2008 and a VS2010 solution.
I have blogged about the solution in detail here: http://blog.aggregatedintelligence.com/2011/03/vs2010-tfs-2008-and-unit-tests.html

How to launch correct version of Msbuild

When I type...
Msbuild<Enter>
...at the command prompt, I get...
Microsoft (R) Build Engine Version 2.0.50727.4927
[Microsoft .NET Framework, Version 2.0.50727.4927]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
This is all very well and good except that when I run this against a Visual Studio 2010 .sln file, the error message indicates:
MyProject.sln(2): Solution file error MSB5014: File format version is not recognized. MSBuild can only read solution files between versions 7.0 and 9.0, inclusive.
0 Warning(s)
1 Error(s)
It would appear that the version of MSBuild that is being called, is not capable of understanding my solution file.
I figured that I would check out my path and see where MSBuild is being picked up from. However, it seems that no part of my path points at a location where MSBuild is to be found.
How is the command line finding the copy of MSBuild that it is using and how can I change this version so that the latest version is used?
I found this question as my PATH variable did not contain a reference to MSBuild.exe. In case anyone else is having this issue, my resolution was to explictly register the environment variables for Visual Studio tools from the command prompt:
"%VS100COMNTOOLS%"\\vsvars32.bat // VS2010 environment variables
"%VS110COMNTOOLS%"\\vsvars32.bat // VS2012 environment variables
"%VS120COMNTOOLS%"\\vsvars32.bat // VS2013 environment variables
MSBuild.exe is now registered in PATH
where msbuild
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
C:\Windows\Microsoft.NET\Framework\v3.5\MSBuild.exe
It must be somewhere in the PATH environment. Use 'where msbuild' to determine where it is loading msbuild from.
Use the Visual Studio Command Prompt (2010) shortcut to initialize the path and other environment variables for VS 2010 and MSBuild 4.0.
Change your environment variables.
Find/set your MSBuild path variable to be C:\Windows\Microsoft.NET\Framework\v4.0.30319
Obiviously the above path will depend on your installation location, but it will be close if not exact.
For building a C# 6 project, this worked for me in a batch file
if exist "%ProgramFiles(x86)%\MSBuild\14.0\bin" set MSBUILDLOCATION=%ProgramFiles(x86)%\MSBuild\14.0\bin
if exist "%ProgramFiles%\MSBuild\14.0\bin" set MSBUILDLOCATION=%ProgramFiles%\MSBuild\14.0\bin
"%MSBUILDLOCATION%\msbuild.exe" "path\to\my\project.csproj"
You can easily change the version number (14.0) or add lines with more version numbers (12.0 and 4.0 for example) if you wanted to support a range of versions.

Resources