locked
Enforce compiler warnings as errors on check-in RRS feed

  • Question

  • Hi,

    I know that I can use the Code Analysis policy to enforce that VSTS code analysis rules are applied before check-in.  But is there a way to force all the C# projects in my team project to have the 'treat warnings as errors' compiler option enabled?  That way I can be sure that checked-in code doesn't have things like 'unreachable code detected'.

    Thanks in advance.
    Wednesday, September 9, 2009 10:16 AM

Answers

  • That's a setting that depends on each C# project (.csproj) and can't be set at the team project level. You can set it for your projects manually or using some sort of script, but any developer could deactivate it again.

    I think that the best option would be to rely on an automated build. Create an automated build and turn on code analysis for it. And then include the following in the TFSBuild.rsp file: /p:TreatWarningsAsErrors=true. Even you could activate the successful build checkin policy, which won't allow any checkins until the build is fixed (although that requires a lot of discipline from your team...)

    Hope it helps...

    Best regards
    Wednesday, September 9, 2009 6:56 PM

All replies

  • That's a setting that depends on each C# project (.csproj) and can't be set at the team project level. You can set it for your projects manually or using some sort of script, but any developer could deactivate it again.

    I think that the best option would be to rely on an automated build. Create an automated build and turn on code analysis for it. And then include the following in the TFSBuild.rsp file: /p:TreatWarningsAsErrors=true. Even you could activate the successful build checkin policy, which won't allow any checkins until the build is fixed (although that requires a lot of discipline from your team...)

    Hope it helps...

    Best regards
    Wednesday, September 9, 2009 6:56 PM
  • Hi,

    There is no built-in support for this, but you could implement this yourself by writing a checkin policy that evaluates all projects in current solution to make sure that they comply to your standards.

    When writing a checkin policy, you will have a reference to an EnvDTE object, from which you can travers the current solution and its projects.

    Regards
    /Jakob


    Blog: http://geekswithblogs.net/jakob Twitter: http://twitter.com/osirisjakob
    Thursday, September 10, 2009 7:15 PM
  • That's a setting that depends on each C# project (.csproj) and can't be set at the team project level. You can set it for your projects manually or using some sort of script, but any developer could deactivate it again.

    I think that the best option would be to rely on an automated build. Create an automated build and turn on code analysis for it. And then include the following in the TFSBuild.rsp file: /p:TreatWarningsAsErrors=true. Even you could activate the successful build checkin policy, which won't allow any checkins until the build is fixed (although that requires a lot of discipline from your team...)

    Hope it helps...

    Best regards
    Hola, Ayudarme con un ejemplo para poder solucionar esto.
    Wednesday, January 13, 2010 5:01 PM