2

I have a custom TFS checkin policy that is used for some of the project in the company. Some of the projects are huge and running the policy for them takes about 10 seconds or so. It is OK to spend 10 seconds every time when someone checks in, because it is going to prevent from problems being created that may take hours. So policy really helps. The issue I am having is, VS is firing the policy not just for checkins, it is firing it from checkouts and saving the checked out file. That is really annoying for everyone. And now I see that developers are disabling the policy to avoid VS freezing.

Anyone knows why would Visual Studio run the policy during the checkout and save?

I don't think VS has any settings that could prevent from running other than checkin, but is there are way in code that I can identify whether the action is Checkin, checkout or save so that I could write my logic accordingly?

Zoe
  • 27,060
  • 21
  • 118
  • 148
Doniyor Niazov
  • 1,270
  • 1
  • 10
  • 19

1 Answers1

1

Generally Check-in policy only works when check in pending changes. So please double check if the issue is really caused by the custom check-in policy.

For the check-in policy, you can disable it when check out files to edit, then enable it when you want to check in the pending changes.

To enable a check-in policy

  1. On the Team menu, click Team Project Settings, and then click Source Control.
  2. In the Source Control Settings dialog box, click the Check-in Policy tab.
  3. In the policy type list, select the policy type you want to enable, and click Enable.
  4. Click OK.

To disable a check-in policy

  1. On the Team menu, click Team Project Settings, and then click Source Control.
  2. In the Source Control Settings dialog box, click the Check-in Policy tab.
  3. In the policy type list, select the policy type you want to delete, and click Disable.
  4. Click OK.

See Enable and Disable Check-In Policies for details.


UPDATE:

Please refer to this article to check How Does Check-in Policy Work? :

Before you check-in, TFS evaluates pending changes in your working directory.

So it will spend time on evaluating the pending changes, it's the expected behavior.

No any other settings in VS for custom policy except the ones mentioned in this this link: https://learn.microsoft.com/en-us/vsts/tfvc/set-enforce-quality-gates?view=tfs-2017#in-this-section

Andy Li-MSFT
  • 28,712
  • 2
  • 33
  • 55
  • I don't think disabling the policy during the checkout and enable it back when checkin in is such a good idea.For example: In our company they are more than 20 developers and that would be really time consuming. – Dilshod Apr 05 '18 at 09:04
  • @Dilshod Yes, the reply is based on your original requirement. As I mentioned in above answer, you should first check if the issue is really caused by the custom check-in policy. Generally the check-in policy does not restrict check-out actions. If it's really cased be the policy, then you need to check the codes for your custom policy to debug that. Otherwise no any effective ways to achieve your requirements. – Andy Li-MSFT Apr 06 '18 at 01:40
  • If I understood the question correctly, custom policy is working during the checkout and saving the edited file. There is no problem with the implementation of the policy itself. It is just VS is initiating the policy in odd times. I am wondering if VS has some settings where you can change in order to not to initiate the policy during checkout and saving the file, or somehow get in the policy itself what the current action is(like checkin, checkout, save) and quit if it's not checkin. – Dilshod Apr 06 '18 at 01:59
  • @Dilshod Please refer to this article to check [How Does Check-in Policy Work?](https://blog.devart.com/creating-tfs-custom-check-in-policy-part-1.html) : `Before you check-in, TFS evaluates pending changes in your working directory`. So it will spend time on doing that, it's the expected behavior. No any other settings in VS for custom policy except the ones mentioned in this this link :https://learn.microsoft.com/ja-jp/vsts/tfvc/set-enforce-quality-gates?view=tfs-2017#in-this-section – Andy Li-MSFT Apr 06 '18 at 02:22
  • This is how I am debugging this. I have a code to generate a log when a policy is working. So I cleared all the logs and trying to checkout file for edit and the policy is working. Also the same thing when saving the edited file. I can't find any info on those links you sent me. – Dilshod Apr 06 '18 at 02:47
  • @Dilshod Unfortunately no any settings to restrict the check-out/check-in actions as you said in VS for the check-in policy. Generally it will slow down a little if you enabled the policy, as it will spend time on evaluating the pending changes... – Andy Li-MSFT Apr 06 '18 at 03:13
  • I am still not getting why would visual studio initiate the policy during checkout or on save? Do you know the answer for that? – Dilshod Apr 06 '18 at 04:56
  • @Dilshod No any other reasons, it's based on the check-in policy mechanism, it's by design. The only thing I can think of is that maybe the actions is designed/set in the source code of the custom check-in policy. So you can write your own check-in policy if possible. – Andy Li-MSFT Apr 06 '18 at 05:06