locked
How save Changeset in tfs api RRS feed

  • Question

  • Hi. I want programmatically change date of changeset. I found code, which change it. But how can I save result? Can you help me?

    using (TeamFoundationServer tfs = new TeamFoundationServer(TFSServerPath, credential))
    {
    	tfs.Authenticate();
    
    	////here you specify the exact time period you need to get the change set (from Date,to Date)
    	VersionSpec fromDateVersion = new DateVersionSpec(DateTime.Now.AddMonths(-5));
    	VersionSpec toDateVersion = new DateVersionSpec(DateTime.Now);
    
    	VersionControlServer versionControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer));
    
    	TeamProject[] tps = versionControl.GetAllTeamProjects(true);//if you want to get all team projects in collection
      
    	foreach (TeamProject tp in tps)
    	{
    		// using versionControl API you can query histroy for changes set 
    		IEnumerable changesets = versionControl.QueryHistory(string.Concat("$/", tp.Name), VersionSpec.Latest, 0, RecursionType.Full, null, fromDateVersion, toDateVersion, int.MaxValue, true, true);
    
    		foreach (Changeset changeset in changesets)
    		{
    			foreach (Change change in changeset.Changes)
    			{
    				string fileName = change.Item.ServerItem;
    				string numberOfChangeset = change.Item.ChangesetId.ToString();
    				string DateOfCheckIn = change.Item.CheckinDate.ToString();
    				Console.WriteLine("Number of changeset: {0}",numberOfChangeset);
    				
    			}
    			
    			changeset.CreationDate = DateTime.Now.AddYears(-2);
    			
    			//How save changeset?
    			
    			break;
    		}	  
    	   
    	}
    }

    Tuesday, March 1, 2016 9:36 AM

Answers

  • Hi Max,

    If you still want to modify the create date, you could modify the record in database directly but it is not recommended (dbo_tbl_ChangeSet).

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 17, 2016 8:53 AM
    Moderator

All replies

  • Tuesday, March 1, 2016 3:40 PM
  • I doubt there is a way to do that.  A source control system should not allow changing the date of a changeset.  That would be a loss of integrity.  Or did you mean something else?

    Regards.

    Tuesday, March 1, 2016 10:45 PM
  • The Changeset class seems to have an Update method. But whether you can update the creation date I don't know. I will have to say that I am not sure that I would like to see that happen...


    Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

    Tuesday, March 1, 2016 10:47 PM
  • Hi Max Karyonov,

    Thanks for your post.

    Please try the following code:

    changeset.Update();

    Reference:

    Changeset.Update Method


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 2, 2016 2:52 AM
    Moderator
  • Hi.

    changeset.Update();  Didn't change time.

    Wednesday, March 2, 2016 8:56 AM
  • Hi,

    Since the time cannot be updated, have you tried to update other fields (like filename)? If other fields can be changed, only the "creationdate" cannot be changed, it means the "creationdate" is not editable.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 3, 2016 1:56 AM
    Moderator
  • Another field I can update, but I need only creation date.

    Why tfs api have this method, but it not applicable?

    Tuesday, March 15, 2016 9:00 AM
  • Hi Max,

    Assume we could change the create date, how others check changes information?  This isn’t make sense.

    The create date can’t be changed. We could modify the comment of ChangeSet and the Update method is used to update the comment.

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, March 16, 2016 8:21 AM
    Moderator
  • Hi Max,

    If you still want to modify the create date, you could modify the record in database directly but it is not recommended (dbo_tbl_ChangeSet).

    Regards

    Starain


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, March 17, 2016 8:53 AM
    Moderator
  • Changing the date on a changeset just sounds wrong.  Perhaps if you posted what goal you are trying to achieve or what problem you are trying to work around, someone could suggest a better way to get there without potentially violating the TFS database integrity.

    Regards.

    Thursday, March 17, 2016 1:28 PM