Stylecop Checkin Policy VS2012, TFS2010 - tfs

We have StyleCop as part of the project and every time we compile, Stylecop is checking the code. But we already have 100K+ lines of code and it only grows every day. So rebuild of the solution is taking longer and longer than 20 seconds already. I think that the worst part of it is Stylecop.
So we are thinking of the way to remove StyleCop from compilation process, but have it as check-in policy for TFS. I have found 2 projects: SourceAnalysysPolicy and StyleCopPolicy. But neither seem to support VS2012 and numerous posts online suggest they do not work in VS2012.
I can slap StyleCop as a step into our build server (TeamCity), but then we'll have a lot of false failed builds - not really a solution.
I was hoping to have to force all check-ins in TFS to be gated check-ins and run stylecop there via MSBuild script: if no violations - actually check-in and pass control over to TeamCity. If there are violations - warn the developer and not check-in. But I've no idea if that is possible in TFS2010 and how to implement it.
Any other ideas?

I know it's an older post but I just released a check-in policy for Visual Studio 2013. I don't know if you already using VS2013 but take a look at this extension. If you want VS2012 support, you can add an issue. If there are enough votes I will add support for it.
https://stylecopcheckinpolicy.codeplex.com/

As a solution to this problem, we have Stylecop sitting on the build server and checking the rules on every check-in. We initially did have a lot of failed builds because of the stylecop rules, but after a while everybody learned all the rules and got used it. And last 2 months we had no failed builds because of Stylecop. So it all the matter of discipline.

Related

TFS 2015 - How do I ensure daily forward and reverse integrations?

My development team is using TFS for source control. My current plan is to have a new shared branch created each sprint for the developers to use for all their tasks.
What is the best way to ensure that the developers are performing forward and reverse integration every day for that branch? In other words, how do I make sure they are constantly getting the latest code set from the sprint branch and checking their code in as well?
There is no such VS extension can force developers to get code from TFS and check in frequently and continuously.
If which you want is to "get the latest " and avoid TFS force you/colleagues to resolve conflicts before checking in.
However, TFS redefined what "Get Latest" does. In TFS terms, Get Latest means get the latest version of the files, but ignore the ones that the server thinks is already in your workspace. Moreover, doing a get latest is good practice, but not mandatory. There is no such settings.
There has been some similar questions in SO and got an amazing answer, below links for your reference:
Is performing a Get Latest mandatory before checking in in TFS so you do not overwrite/lose code?
Why doesn't TFS get latest get the latest?
As a workaround, if you really need this feature in your team, you could set up a reminder such as meeting reminder in outlook 4:00PM to remind your colleagues, they should merge their work in the branch at the end of day. Just couldn't force them to do this.
This is a people problem, not a tooling problem. There's no way the tool can force their behavior when it comes to committing their code or merging branches. It's just part of workflow discipline, which will come with time.

TFS nuget packages not being restored

I have a small solution containing three Visual Studio projects. I'm working in Visual Studio 2015 using TFS 2015.
I have implemented a gated check in, but for some reason the solution will not build on the TFS server. I'm referencing only 1 nuget package - Entity Framework. I am not checking my package folder into TFS, but my packages.config files are being included.
I have previously set up a different project on the same server using the same build definition and it works fine.
In order to restore packages prior to build, you will need to run the following command as part of your build process.
nuget.exe restore path\to\solution.sln
One way to do that is to add another project that is responsible for building your solutions and making sure that the packages get restored prior to your solutions being built.
Following write-up walks you through getting that set up: nuget docs
I managed to get it working, but I tripped into the fix and don't know what exactly solved the problem. This is the first time I've really had to handle TFS builds.
I know I only had one build definition defined and it was intended for a different solution - of which this code was also a part. I think when I was checking in this solution it was actually trying to build the other.
Apparently, I can't have my nuget packages set up different ways for code that is in two different solutions. Anyway, that's my best guess.

Configure TFS 2012 to Build All Solutions Under Directory

To prevent unexpected build breaks and test failures, We have been using gated check ins. This works very well for our core solutions, and has helped improve our quality.
As part of our overall architecture, we have a certain section of our code with many micro-services, each of which is a new solution. New solutions are added to this part of the code base regularly. These are important parts of the system, and I need to make sure they get compiled as part of a gated check in without the chance for developer error.
Is there a way to configure TFS to find ALL solutions under a certain path and include them in a gated check in build?
Thanks
Not without modifying the build process template, which is almost never a good idea. The new build system in TFS2015 does allow that, however.
TFS 2015 vNext builds allow wild cards to search for all solutions. I haven't had success getting this to work with Visual Studio build steps, which you would need, but it works well with NuGet Installer and other build steps. We will not see gated builds in vNext builds until we get update 2 see TFS feature timeline

TFS Gated Checkins that are Rejected are Showing up in Build Status for Everyone

We set up TFS 2013 recently and tried to set up gated check-in. In our experiment, it correctly failed the build and rejected the bad check-in. However, both the build notification tray icon and the build tab on the TFS web access show the failure, and it is this way for all users. This will make everyone think "the" build is broken when it's just one person's "gate." It will skew metrics, too.
A) Why would this be the default behavior? It seems very counter-productive and counter-intuitive. [Or maybe this isn't the default behavior and our setup is hosed?]
B) Is there a configuration for the build tab where a rejected gated check-in/build is visible only to the person who broke it?
C) How can we make the build notifier tool ignore gated failures?
a) This is a public build. Why should it be failing. If the gated build is failing it shows a lack of care by the developers. Are they checking in any old thing? Are they running their unit tests first? It really sounds like you have a quality issue there.
That is why the gated-builds are still public builds.
b) no - Anyone can however send a Private build to the build server if they think that there may be an issue that they can't catch locally..
c) Each user can uncheck the monitoring of the gated build. I would however suggest that they should concentrate on not failing the build however rather than sweeping it under the carpet...
A filed build, even a gated one, should be the exception and not the rule...
MrHinsh answered my question from a largely philosophical standpoint, and that led me to this article:
[http://adamstephensen.com/2012/11/01/gated-checkins-mask-dysfunction/]
I agree in principle with the article. However, because we are attacking agile processes in baby steps, we still want this extra safety check for the time being.
Below isn't the exact solution we wanted, but it is a hybrid of the approach in the article and my original question. It doesn't force gated check-ins, but it allows them to be done, giving risky check-ins a safety net. Code quality beyond build-ability will be addressed with other mechanisms outside the scope of this question.
The compromise solution is that "vanilla" changes would be checked in normally (after local testing, of course), and then the CI build would kick in. Fixing broken builds would be high priority to be addressed immediately.
But anything out of the ordinary (configuration changes, referencing new/different external dependencies, or just anything a developer is unsure of) would use a private gated check-in, but not on the main build, because we don't want everyone to be tricked into thinking the build is broken upon rejections. This build definition is a clone of the main build definition, but with the addition that upon successful check-in, it chains a build of the main build definition using this:
[How to chain TFS builds?
While the main build is redundant in most cases (race conditions may apply), it solves the immediate need.

How can I control the order of builds in TFS 2010 when common library is checked in?

I have a TFS 2010 with some projects and a common library used in 5 of them. We use VS 2013 and we have Rolling Builds enabled in most if not all build definitions. When the common library is checked in, all of the projects referencing it are recompiled - but the order is poor, the most commonly used project is compiled as the last one. Is there a way to change that so it gets compiled first?
This question hints at a lot of problems and possible solutions. The simplest answer is probably to just add more build servers to run all the builds in parallel.
Otherwise you need to consider turning off rolling builds and writing your own build scheduler. That or other strategies such as building the DLL once and checking it in as source to the other builds or running the build on a branch that is outside of the other 5 builds and merging the source into those builds when they want to pick up the change.
If you are otherwise happy with how things are now and don't want to do a lot of work to solve the problem.... then just scale out your build farm with additional agents.
There's a "Priority in queue" on the build definition, but it sounds like you might want to change your solution's > Project Dependencies' > Build Order?

Resources