Compiler Warnings - Can I indicate I want the build to fail?  
Author Message
Dylan Smith





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

Is there a way to indicate that I wish the team build to fail if any compiler warnings are encountered

Visual Studio Team System12  
 
 
Swaha Miller





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

I don't know of a way of doing it in Team Build, but you could set higher warning levels on your projects and have warnings treated as errors.

Swaha


 
 
Dylan Smith





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

Yes, I was aware of this option. Although I don't think that will be a desirable alternative for us. I want my developers to still be able to compile and run their applications even if they have warnings in their code...so long as they fix them up before they try to check-in their changes.

If there was something I could do at the solution level it could work. I have my Team Build pointed to a different .sln file than the developers use in their day-to-day work (but the .proj files are the same).


 
 
Dylan Smith





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

Can anybody in the know chime in on this Is this possible to do at the Team Build or solution level Even if the answer is No, it would just be nice to know for sure.
 
 
Aaron Hallberg - MSFT





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

I think this is pretty straightforward - just put the following line into your TfsBuild.rsp files for each relevant build type:

/p:WarningsAsErrors=true

Just a quick warning though - without some sort of gated checkin process in place, this is very likely to cause build breaks on a pretty regular basis, since builds will succeed on developers machines but fail under Team Build.

-Aaron



 
 
Dylan Smith





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

I tried this and I got the build error:

vbc(0,0): error BC2014: the value 'true' is invalid for option 'warnaserror'

My TFSBuild.rsp file looks like this:

# This is a response file for MSBuild

# Add custom MSBuild command line options in this file

/p:WarningsAsErrors=true

Am I doing something wrong here


 
 
Jason Pricket - MSFT





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

I think Aaron meant to use the following line

/p:TreatWarningsAsErrors=true

The WarningsAsErrors property allows you to pass in a list of warning numbers to treat as errors. Check out the following link for the CSC Task.

http://msdn2.microsoft.com/en-us/library/s5c8athz.aspx

Hope that helps, Jason


 
 
Dylan Smith





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

Thanks for the clarification Jason. Unfortunately I still cannot get this to work. I changed my TfsBuild.rsp file to this:

# This is a response file for MSBuild

# Add custom MSBuild command line options in this file

/p:TreatWarningsAsErrors=true

When I checked it it and executed the Team Build the build showed 2 warnings but still successfully completed.

The warnings are Code Analysis warnings if that makes any difference. The Mixed PlatformsDebug.txt file contains this:

Solution: ShopFloorTeamBuild.sln, Project: BusinessModel.vbproj, Code analysis errors and warnings
D:\Team Build\Order Entry\BuildDir\OrderEntry\CI Build\Sources\BusinessModel\Sales\SalesOrderDetail.vb(116,0): warning : CA1801 : Microsoft.Usage : Parameter 'value' of SalesOrderDetail.set_DiscountedUnitPrice(Double):Void is never used. Remove the parameter or use it in the method body.
D:\Team Build\Order Entry\BuildDir\OrderEntry\CI Build\Sources\BusinessModel\Sales\SalesOrderDetail.vb(126,0): warning : CA1801 : Microsoft.Usage : Parameter 'value' of SalesOrderDetail.set_ExtendedPrice(Double):Void is never used. Remove the parameter or use it in the method body.

Here is a portion of the Build log that appears as though the command-line arg is being set properly (if you look in the middle there after it specifies the references it has /warnaserror+) :

Target CoreResGen:
Processing resource file "My Project\Resources.resx" into "obj\Debug\Resources.resources".
Target CoreCompile:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System,System.Collections,System.Collections.Generic,System.Data,System.Diagnostics /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optionstrict+ /doc:obj\Debug\BusinessModel.xml /define:"CODE_ANALYSIS=-1,CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,_MyType=\"Windows\",PLATFORM=\"AnyCPU\"" /reference:"C:\Program Files\Common Files\Business Objects\2.7\Managed\CrystalDecisions.CrystalReports.Engine.dll",C:\WINDOWS\assembly\GAC\CrystalDecisions.Enterprise.Framework\10.2.3600.0__692fbea5521e1304\CrystalDecisions.Enterprise.Framework.dll,C:\WINDOWS\assembly\GAC\CrystalDecisions.Enterprise.InfoStore\10.2.3600.0__692fbea5521e1304\CrystalDecisions.Enterprise.InfoStore.dll,"C:\Program Files\Common Files\Business Objects\2.7\Managed\CrystalDecisions.ReportSource.dll","C:\Program Files\Common Files\Business Objects\2.7\Managed\CrystalDecisions.Shared.dll",C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.DirectoryServices.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.Services.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /debug+ /debug:full /keyfile:SFCKeyfile.snk /out:obj\Debug\BusinessModel.dll /resource:obj\Debug\Resources.resources /resource:obj\Debug\WorkOrderSequencesReport.rpt /target:library /warnaserror+ Accounting\Account.vb Accounting\Subledger.vb Accounting\TransactionReason.vb Accounting\TransactionType.vb BusinessLayerProxy.vb BusinessLayerReference.vb BusinessLayerService.vb BusinessObjectBase.vb General\BOMAndSequenceBase.vb General\CoilPart.vb General\Family.vb General\InventoryClassCode.vb General\SubFamily.vb General\UnitsOfMeasure.vb Reports\ReportManager.vb Reports\WorkOrderSequencesReport.vb DataHolders.vb General\Coil.vb General\Location.vb General\NotificationObject.vb General\PartCost.vb General\PartSiteInfo.vb IBusinessLayer.vb Labor\FreeTime.vb Labor\HolidaySummary.vb Labor\LaborActivityType.vb Labor\LaborRates.vb Labor\OvertimeReasons.vb Labor\PayrollSummary.vb PermissionsInfo.vb ProductionSchedule\AvailableToPromiseOrder.vb ProductionSchedule\Inspection.vb ProductionSchedule\MachineDowntime.vb ProductionSchedule\QuantityCompletedLog.vb ProductionSchedule\QuantityPickedLog.vb ProductionSchedule\QuantityScrappedLog.vb ProductionSchedule\SchedulerLogSummary.vb ProductionSchedule\SchedulerSummary.vb ProductionSchedule\ScrapReason.vb General\Sequence.vb ProductionSchedule\WorkOrderNote.vb ProductionSchedule\WorkOrderSerial.vb ProductionSchedule\SharedSetup.vb ProductionSchedule\SubContractSchedule.vb ProductionSchedule\WorkOrder.vb ProductionSchedule\WorkOrderBillOfMaterial.vb ProductionSchedule\WorkOrderSequence.vb Purchasing\SuggestedPurchaseOrder.vb RowVersion.vb Forecast\ForecastOrder.vb General\AuthenticationInfo.vb General\BillOfMaterial.vb General\Department.vb General\Division.vb General\DrawingVersion.vb General\Employee.vb General\BaseOrder.vb General\Notification.vb General\Part.vb General\PartDrawing.vb General\Qualification.vb General\Site.vb General\WorkCenter.vb Labor\AttendanceInfo.vb Labor\LaborAdjustment.vb Labor\LaborCode.vb Labor\LaborDetail.vb Labor\ManpowerSchedule.vb Labor\OvertimeApproval.vb Labor\Shift.vb Labor\ShiftBreak.vb "My Project\AssemblyInfo.vb" "My Project\Application.Designer.vb" "My Project\Resources.Designer.vb" "My Project\Settings.Designer.vb" ProductionSchedule\MaterialSchedule.vb ProductionSchedule\JobOrder.vb Purchasing\PurchaseOrder.vb Purchasing\PurchaseOrderDetail.vb Purchasing\Supplier.vb Sales\AddressType.vb Sales\ContactInfo.vb Sales\Currency.vb Sales\Customer.vb Sales\CustomerAddress.vb Sales\FreightTerm.vb Sales\PaymentTerm.vb Sales\SalesArea.vb Sales\SalesOrder.vb Sales\SalesOrderDetail.vb Sales\TransportMethod.vb Serialize2XMLHelper.vb WesteelConfigReader.vb
Target _CopyAppConfigFile:

It looks like the Code Analysis is run as a separate task than the compile though, so it doesn't appear this applies to Code Analysis. Is there anyway to make Code Analysis warnings cause the build to fail


 
 
warrens





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

You could go down the route of creating a separate build configuration which treats warnings as errors, enables Code Analysis, etc.... Have your Team Build use that build configuration by default. Your developers can then develop in standard "Debug" configuration, and test their work on the more stringent build configuration before submitting changes.


 
 
Jason Pricket - MSFT





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

You are right about the code analysis being a separate step. Unfortunately, I don't think there is a way to treat those warnings as errors without enabling it in the Project properties. Which would enable it all the time, not just during Team Build.

FYI, to treat Code Analysis warnings as errors... Open the properties window for you project and select the Code Analysis tab. There each rule should have a check box for treat warnings as errors.

warrens had a good suggestion on using the configurations. You could turn on Treat Warnings as Errors for your Team Build configuration and let the developers use the standard Debug configuration.

Thanks, Jason


 
 
Aaron Hallberg - MSFT





PostPosted: Team Foundation Server - Build Automation, Compiler Warnings - Can I indicate I want the build to fail? Top

One more thought - as long as you are worried about code analysis warnings for MSBuild compatible project types (C#, VB, etc.) you should be able to conditionally set the "code analysis warnings as errors" property. The trick would just be to get it set one way for Team Build builds (with the various warnings treated as errors) and another for "regular" builds (with the various warnings just as warnings). I would recommend using Visual Studio to set up the configuration one way and then the other way, and looking at the differences in notepad - they should be with the CodeAnalysisRules property, I believe. Then, you should be able to use the following conditions to set things up for your two cases:

"Regular" Build: Condition=" '$(TeamBuildConstants)' != '_TEAM_BUILD_' "

Team Build Build: Condition=" '$(TeamBuildConstants)' == '_TEAM_BUILD_' "

(In Team Build 1.0, the TeamBuildConstants property is set to _TEAM_BUILD_ during the CoreCompile target, which is when your projects get compiled by MSBuild)

-Aaron