4

We are trying to have ReSharper's cleanup code run on TFS Checkin. Ideally, when you right click on the solution / project and select Source Control > Check in all the files in the "Included Changes" should run cleanup code. I've got the custom checkin policy to work to some extent, works fine if you select a single file to check in but when you select the solution or project, it tries to run cleanup code on the entire solution / project and not just the files selected in TFS Pending Changes "Include Changes".

I'm running VS 2013 with R# 8.2. My policy evaluate code:

public override PolicyFailure[] Evaluate()
{
  if (PendingCheckin.Policies.EvaluationState == PolicyEvaluationState.Unevaluated)
  {
    DTE2 dte = PendingCheckin.GetService(typeof (DTE)) as DTE2;
    foreach (EnvDTE.Document doc in dte.Documents)
    {
      doc.DTE.ExecuteCommand("ReSharper_SilentCleanupCode");
    }
  }
  return new PolicyFailure[0];
}   

I don't think this only applies to ReSharper, executing "Edit.FormatDocument" here would most likely run on all files as well.

Is there a way to run ExecuteCommand on only 1 file / document?

It seems like

PendingCheckin.GetService(typeof (DTE))

only gets files that are open in the Visual Studio editor not all the files that are in the "Include Changes" list. I can get a list of PendingChange through

PendingCheckin.PendingChanges.CheckedPendingChanges

But I don't know how to execute a command on PendingChange. Recommendations here would help

PS: I've read that the check in policy is meant to be used for checking documents only, however this workflow is what we need.

VKom
  • 41
  • 2

0 Answers0