2

I tried using stylecop, but it is quite strict with lot of rules. I do not want to customize it by disabling certain rules. I want to document that I am using 'Microsoft managed recommended rules', which I used while coding in VS 2017.

I want to incorporate the same rules in Git build process TFS-2015. Should I do code standard analysis during build definition? If not, how else?

Any help would be greatly appreciated!

kostix
  • 51,517
  • 14
  • 93
  • 176
Anjali Iyengar
  • 320
  • 4
  • 16
  • Welcome to SO, I could not find a clear question, can you modify your post and define a question to solve? Please read> [How to Ask](https://stackoverflow.com/help/how-to-ask) –  Dec 07 '17 at 19:46
  • @DavidG. i want to apply 'Microsoft managed recommended rules' to the master branch. so, if i build it with wrong coding standards, it should throw build error. or is it possible to do the code analysis in branch policies where we set number of reviews and merge strategies? – Anjali Iyengar Dec 07 '17 at 19:50

1 Answers1

1

It's not able to do the code analysis in branch policies where you set number of reviews and merge strategies. Unless the reviews manually check the code and fail the review according to Microsoft managed recommended rules.

If you want to apply Microsoft managed recommended rules to your code. Simply add /p:RunCodeAnalaysis=true to the MsBuild commandline additional arguments.

For stylecop there is also a related build task, if you want use this, you could add it in your build pipeline.

Finally just enable the Build validation in your master branch policy. Set a policy requiring changes in a pull request to build successfully with the protected branch before the pull request can be completed.

enter image description here

PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62
  • Thanks! I haven't implemented it yet. I will post if I face any issues. Thank you again. – Anjali Iyengar Dec 12 '17 at 11:07
  • It worked! Now, it is just throwing the warning. Is there a way to make it mandatory, and fail the build process if the coding standards are not followed in TFS 2015? – Anjali Iyengar Dec 15 '17 at 13:48
  • 1
    @AnjaliIyengar Sorry there is no way to make it mandatory for now. To fail the build,one way is “treat warning as error” for specific build definitions, In the build definition specify /p:TreatWarningsAsErrors=True in the MSBuild argument field.This will override any setting from the csproj files. Another way you could be able to return warnings and errors from your powershell script using logging commands. With using `task.logissue type=error` you could fail the build task and then fail the build. – PatrickLu-MSFT Dec 15 '17 at 16:29