Why does my TeamCity build fail, eventhough MSBuild has no errors? - visual-studio

TeamCity is set up to build a Visual Studio solution, which can be build locally by a number of developers. However, when TeamCity runs the build, it will always fail the build, even though MSBuild outputs no errors:
[08:49:02][Step 1/1] Process exited with code 1
[08:49:02][Step 1/1] MSBuild output
[08:49:02][MSBuild output]
[08:49:02][MSBuild output] 183 Warning(s)
[08:49:02][MSBuild output] 0 Error(s)
[08:49:02][MSBuild output]
[08:49:02][MSBuild output] Time Elapsed 00:01:10.65
[08:49:03][Step 1/1] Step Build solution (Visual Studio (sln)) failed
For comparison, these are the last lines of build output in a local Visual Studio:
54>
54>Build succeeded.
54>
54>Time Elapsed 00:00:11.37
========== Rebuild All: 46 succeeded, 0 failed, 18 skipped ==========
The curious thing is, I cannot find a line which says "Process exited with code 1" locally. I have turned of all pre/post build events for each project. I've looked for possible culprits throughout the build log from TeamCity, but I cannot find any clue related to why it exits with code 1.
Interestingly, the build does produce the necessary artifacts, which are valid!
Why is my build exiting with code 1?
EDIT in response to comments:
Same version of msbuild
running msbuild on the server in command line, generate a build.log file with the same results "x warnings, 0 errors". echo %errorlevel% returns 0.
there is no settings to "Treat warnings as errors"
I'll try to post to complete output, but i need to anonymize it first.

I can think of 3 issues:
It looks like TeamCity fails the build step if warnings are encountered - can you check that is not the case?
As others have commented, please try to do an ms build from the command line. Have a look at the exact command line argumes Team city is invoking msbuild with.
There are settings in the projects themselves to "treat warning as errors" but then msbuild would obey those rules. Did you customize your build ? For more info see this.

Related

C# console app always rebuilds, but I've already traced diagnostic build output

I've looked at more pages than I can count about how to solve the "I didn't change anything, so why is VS rebuilding my project" problem. And they were helpful for resolving a number of issues with "copy always" flags, and custom build steps that always run. But I'm left with one that won't go away. It passes all the up-to-date fast dependency checks, but continues to start the build anyway. I've traced through all the MSBuild output at the diagnostic level, but I think the "normal" (not minimal) level is sufficient to point in the right direction. Here's the output:
1>------ Build started: Project: OnePawDataSerializer, Configuration: Debug x64 ------
1>Build started 12/20/2019 5:04:37 PM.
1>GenerateTargetFrameworkMonikerAttribute:
1>Skipping target "GenerateTargetFrameworkMonikerAttribute" because all output files are up-to-date with respect to the input files.
1>CoreCompile:
1>Skipping target "CoreCompile" because all output files are up-to-date with respect to the input files.
1>_CopyFilesMarkedCopyLocal:
1> Touching "D:\Volpe\NuCS-HiEx\NuCS-Repo\Applications\FAB4DA\OnePawDataSerializer\obj\x64\Debug\OnePawDataSerializer.csproj.CopyComplete".
1>_CopyAppConfigFile:
1>Skipping target "_CopyAppConfigFile" because all output files are up-to-date with respect to the input files.
1>CopyFilesToOutputDirectory:
1> OnePawDataSerializer-> D:\Volpe\NuCS-HiEx\NuCS-Repo\Applications\FAB4DA\bin\Debug64\OnePawDataSerializer.exe
1>
1>Build succeeded.
1> 0 Warning(s)
1> 0 Error(s)
1>
1>Time Elapsed 00:00:00.20
========== Build: 1 succeeded, 0 failed, 15 up-to-date, 0 skipped ==========
At this level of output verbosity it doesn't show all the stuff that looks like this:
1>------ Up-To-Date check: Project: CommonDataModelUtilities, Configuration: Debug x64 ------
1>All outputs are up-to-date.
1>Time Elapsed 19 ms
But they all indicate that everything is up to date. In the "normal"-level output, it shows a couple of internal targets being skipped, but then seems to need to execute one called "_CopyFilesMarkedCopyLocal", which doesn't seem to actually copy anything, but does appear to create a file with the name of the project file appended by ".CopyComplete". This appears to be the only instance of the build actually "doing" something tangible, so I'm inclined to suspect that this has something to do with why I'm not seeing this:
========== Build: 0 succeeded, 0 failed, 16 up-to-date, 0 skipped ==========
when I build. But I can't figure out why it's doing it. Any thoughts?
This appears to be the only instance of the build actually "doing"
something tangible, so I'm inclined to suspect that this has something
to do with why I'm not seeing this: ========== Build: 0 succeeded, 0
failed, 16 up-to-date, 0 skipped ========== when I build. But I can't
figure out why it's doing it. Any thoughts?
MSBuild uses incremental compilation, which only compiles files that have been modified, and skips building for files that have not changed. So when build your project again without any changes, it will like this as you wish:
========== Build: 0 succeeded, 0 failed, 16 up-to-date, 0 skipped ==========
This is the normal behavior generated by MSBuild.
But if you build your project again without changing any project files and build always execute, l am afraid that the issue is caused by some project files' settings(set Copy to Output Directory to Copy Always). (Or you can see the files in the xxx.csproj file and then you will find some files add the node <CopyToOutputDirectory>Always</CopyToOutputDirectory>)
According to the build log info from your picture, the targets _CopyFilesMarkedCopyLocal and CopyFilesToOutputDirectory are responsible for copying project resources which you specify as the picture shows to the output path. And when you set the file to Copy Always, MSBuild will always consider this operation to be up to date, so it will always execute.
Note: Build is the process by which msbuild executes a bunch of target targets which contains the compile target. If the files are already compiled and they are not changed, the target will skip. Besides, if some projects are not changed, MSBuild will skip compiling them and regard them as up - to - date.
To prove it l have do a test:
1) I set the project file called JavaScript1.js to Copy Always as the picture shows above.
2) Then when I build the project multiple times, it always turns that the build executes successfully.
In addition, if you want this behavior, you could set Copy to Output Directory to Do not copy. Or if you want to output these files, you can set to Copy if newer.
Update1
If cannot see this abnormal behavior directly, l think you can set MSBuild project build output verbosity to Diagnostic.This mode will display every detailed info about build process.
And l have observed that the build log only shows two targets which are
running _CopyFilesMarkedCopyLocal and CopyFilesToOutputDirectory.
So please check the target CopyFilesToOutputDirectory, _CopyFilesMarkedCopyLocal, Copy task in the Diagnostic build log by the search box and you can search any detailed info about this.
And in my side, l can see this info in the first line of build output which is explain why my project always rebuild:
Project 'ConsoleApp1' is not up to date. Project item 'C:\Users\Admin\source\repos\ConsoleApp32\ConsoleApp32\JavaScript1.js' has 'Copy to Output Directory' attribute set to 'Copy always'.
Hope it could help you.

Visual Studio online build failing with 0 warnings and 0 errors

I am just setting up a basic build with a very bare bones WebApi App, and I am getting a failed build, but without any errors or warnings... how can i figure out what is going wrong?
Project "d:\a\1\s\My.Project.Api.sln" (1) is building "d:\a\1\s\My.Project.Api\My.Project.Api.csproj" (2) on node 1 (default targets).
_CleanRecordFileWrites:
Creating directory "obj\Release\".
Done Building Project "d:\a\1\s\My.Project.Api\My.Project.Api.csproj" (default targets) -- FAILED.
Done Building Project "d:\a\1\s\My.Project.Api.sln" (default targets) -- FAILED.
Build FAILED.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.15
##[error]Process 'msbuild.exe' exited with code '1'.
Even any way I can get a useful log or error message would be great!
Edit:
I added /v:diag for the build arguments for verbose logging, but it really isn't seeming to help.
Before Visual Studio build task, you should use nuget restore to download packages your project is referring.
So please add a Nuget task before Visual Studio build task. Detail setting for NuGet task as below:
Command: restore
Path to solution, packages.config, or project.json: **/*.sln or select relative path for My.Project.Api.sln
Feeds to use: Feeds in my NuGet.config
In your build definition, there is a variable called system.debug which is set to false. Change this to true at the template or at the time of triggering and you will get the debug lines written by the build tasks. Inspect the debug lines and you might find the issue.

Build fails in vs2015 with no errors

I have an ASP.NET core 1.0 project I created in Visual Studio 2015 (update 3). If I try to build the project within VS I get the following in my output window and there are no errors in the Error List:
1>------ Build started: Project: QuickStartIdentiyServer4, Configuration: Debug Any CPU ------
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
However, if I build the project using the dotnet CLI command (dotnet build) it builds and runs just fine.
UPDATE:
Apparently, .net core does not work properly when running Visual Studio as Admin. You would think everything should work as Admin, I guess not... go figure.
There are simply too many reasons why this type of thing might happen. The easiest way to diagnose the problem is to change the build output verbosity under options to verbose. This might help put you on the trail:
With regards to this type of thing happening with .Net Core and ASP Core. I have noticed that the project.json dependencies json fragment is a bit buggy especially if you start renaming projects and changing their file system location.
If you see in the diagnostic below you know there is some dangling reference issue:
Done building target "_GetDependencyFragmentFiles" in project "<<?YOUR_CORE_PROJECT?>>.xproj" -- FAILED
May be you are not seeing build errors. Go to Error List window and change 'Show Issues generated' box from 'Build + Intellisense' to 'Build Only' and try to build again.
See if this helps.

Making TeamCity FxCop build step cause a build fail if a rule is violated

I have two build steps in my build configuration: Visual Studio (sln) build runner, followed by an FxCop build runner. I'm using TeamCity 6.0.1 and FxCop 10.0.
Out of the box, the FxCop runner in TeamCity seems to only report on rule violations, and produces a report on a Code Inspection tab. I want to ensure that if any violation occurs that the build step fails and thus causes an entire build failure.
Is there a way to accomplish this?
Please set the Errors limit property in your FxCop build step configuration to 0. This should break the build if there is at least one analysis error.
Furthermore, there is a similar Warnings limit property. If you don't want to allow any rule violation at warning level, insert in this field also the value 0. If you want to allow rule violations where the rule attribute BreaksBuild == False, leave this property empty.
I've tried that using TeamCity 6.0 (build 15772) and FxCop 10.0.
[14:39:22]: [Step 2/2] Importing inspection results
[14:39:22]: [Step 2/2] Errors limit reached: found 8 errors, limit 0
[14:39:22]: [Step 2/2] ##teamcity[buildStatus status='FAILURE' text='Errors: 8, warnings: 1']
In the version 7.0 EAP it is special "Build fail condition" in Build Configuration=>Build Failure conditions=>Add build failure condirion, e.g. "Fail build if number of inspection errors is more than 30"

How do I parse the output of msdeploy and fail a TeamCity build if there are errors?

I'm using msdeploy.exe run from TeamCity for deploying ASP.Net projects to staging servers but if suffers severely from always returning a 0 status on exit, even when it raises several errors. This means that a bad deploy does not fail and all looks OK.
So I need to parse the output and have that raise an error, is there an easy way to do this? Alternatively, is there a hard way to do this?
You can see from the TeamCity build log below what is going on (errors, but carries on due to 0 exit status).
[17:32:31]: Skip copying Global.asax to obj\Debug\Package\PackageTmp\Global.asax, File obj\Debug\Package\PackageTmp\Global.asax is up to date
[17:32:31]: C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1845,5): error : Copying file Web.Debug.config to obj\Debug\Package\PackageTmp\Web.Debug.config failed. Could not find file 'Web.Debug.config'. [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: Done Building Project "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package target(s)) -- FAILED.
[17:32:31]: Build FAILED.
[17:32:31]: "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package target) (1) ->
[17:32:31]: (ValidateGlobalPackageSetting target) ->
[17:32:31]: C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(817,5): error : '..\Package\WebApp.zip' exists as a file. You can't package as an archive directory to be the same path as an existing file. Please delete the file before packaging. Alternative,you can call msbuild with /t:CleanWebsitesPackage target to remove it. [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: "C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj" (Package target) (1) ->
[17:32:31]: (CopyAllFilesToSingleFolderForPackage target) ->
[17:32:31]: C:\Program Files\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1845,5): error : Copying file Web.Debug.config to obj\Debug\Package\PackageTmp\Web.Debug.config failed. Could not find file 'Web.Debug.config'. [C:\BuildAgent\work\f3548ee02a6397b9\webapp\WebApp.csproj]
[17:32:31]: 0 Warning(s)
[17:32:31]: 2 Error(s)
[17:32:31]: Time Elapsed 00:00:00.87
[17:32:31]: C:\BuildAgent\work\f3548ee02a6397b9>"C:\Program Files\IIS\Microsoft Web Deploy"\msdeploy.exe -verb:sync -source:Package=Package\WebApp.zip -dest:auto -setParam:"IIS Web Application Name"=MyWebName
[17:32:32]: Info: Updating setAcl (MyWebName).
[17:32:32]: Info: Updating setAcl (MyWebName).
[17:32:32]: Info: Updating setAcl (MyWebName/App_Data).
[17:32:32]: Total changes: 3 (0 added, 0 deleted, 3 updated, 0 parameters changed, 0 bytes copied)
[17:32:32]: Process exited with code 0
[17:32:32]: Build finished
TeamCity 7 has a Build Failures feature:
Edit Settings on your build configuration
Go to the Build Failure Conditions tab (number 4)
Click 'Add build failure condition'
Select the 'Fail build on specific text in build log' type
I used the string "EXEC : error count:" to catch MSDeploy errors, it works well
The Test button opens a handy dialog where you can test your failure condition on a previous build log that you know should have failed
Save
In my configuration I'm invoking msdeploy.exe directly from MSBuild, I think that's why my error text is different to yours.
Pretty cool, loving JetBrains for this.
Here is an approach I used to catpure build failures from MSDeploy when I ran a Nant script for deployment remotely. It is not an identical scenerio but should give you a concept to go from. Basically you can run this from a shell you need a scripting language like powershell to capture the output and than post processes the plain text coming back from msdeploy. I rasied this issue with the MSDeploy team and let them know this was a pain to deal with.
http://www.lostechies.com/blogs/hex/archive/2009/12/29/update-on-using-msdeploy-for-remote-deployments.aspx
In TeamCity 9 go to the build configuration and click on the Failure Conditions. Check the checkbox "an error message is logged by build runner". This will fail your build if an error happens during deployment.

Resources