MSDN > 論壇首頁 > Visual Studio Extensibility > File.CheckIn command and automated CheckIn
發問發問
 

已答覆File.CheckIn command and automated CheckIn

  • Tuesday, 23 June, 2009 11:00Matteo Garzulino 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     

    Hi all,

    I need to programmatically Check-In a file in solution explorer.

    Scenario:

    Visual Studio SDK 2008

    C#

    Visual Source Safe 6.0

    Visual Studio 2008

    VSPackage

    As i already read here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/8adae52a-46e9-4677-af1c-c6b451e720da there are some different methods to do that, for instance:

    - EnvDTE.SourceControl
    - IvSccXXX interfaces

    but they doesn't contain an explicit CheckIn() method, as well explained by Craig Skibo in above link.

    So, I'm trying Carlos Quintero' suggestion to use DTE.ExecuteCommand("File.CheckIn",...) but i get this error:

    Command "File.CheckIn" is not available.

    Here's my source code:

    EnvDTE.DTE dte = dTe as EnvDTE.DTE;  //dTe is an correctly instaciated object of EnvDTE.DTE
    
                try
    
                {
    
    //fullNameFile is my file FullName.
    
    
    
                    dte.ExecuteCommand("File.CheckIn", fullNameFile);
    
                }
    
                catch (Exception e)
    
                {
    
                    throw new Exception("Exception during CheckIn: " + e.Message);
    
                }
    
                return true;
    
    

    Is it because command File.CheckIn is not available for security?
    Is it because i put wrong arguments to the command?
    So, is there a way to CheckIn programmatically a ProjectItem by code with C# ??


    Any suggestion is welcome.

    Bye


    - Matteo Garzulino -

解答

  • Friday, 10 July, 2009 8:48Matteo Garzulino 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    Hi Rong-Chun,


    I finally get command File.CheckIn to work!

    Here what i did:

            /// <summary>
            /// Esegue il comando CheckIn di un HierarchyItem precedentemente individuato.
            /// </summary>
            /// <param name="itemToCheck">HierarchyItem di cui svolgere il check</param>
            /// <param name="mDte2">Oggetto Dte.</param>
            /// <returns>True: successo; Eccezione altrimenti.</returns>
            public static bool CheckIn(UIHierarchyItem itemToCheck, DTE2 mDte2)
            {
                Commands c = mDte2.Commands;
                itemToCheck.Select(vsUISelectionType.vsUISelectionTypeSelect);
    
                foreach (Command co in c)
                {
                    if (co.Name.Contains("File.CheckIn"))
                    {
                        System.Windows.Forms.MessageBox.Show(co.Name + " - " + co.IsAvailable + " - " + co.Guid + " - " + co.ID + " - " + co.LocalizedName);
                    }
                }
                object outOb = null;
                object i = (itemToCheck as object);
                try
                {
                    c.Raise("{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}", 11150, ref i, ref outOb);
                }
                catch (Exception) //Provo con il Check su richiesta.
                {
                    c.Raise("{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}", 21014, ref i, ref outOb);
                }
    
                return true;
    
            }
    

    First, i must get a UIHierarchyItem, Select it, then i can have the command to works using Command.Raise() method.

    Note that code above is just a draft: i try to run File.CheckInSilent command, then if it fails I try File.CheckIn.

    Note also that for both methods the first parameter is the GUID of the Command, the second one is the ID. You should use them when try to checkin using Command.Raise() method.

    This seems to work very well during "normal" conditions; instead, i've got problems during or just after Project editing (for example after i add programmatically a projectitem). But this is partially off topic so i'll open a dedicated post.

    Hope that this would be helpful.

    Thanks,

    Matteo.


    - Matteo Garzulino -
  • Thursday, 25 June, 2009 7:11Rong-Chun ZhangMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Hello Matteo,

    When I File.CheckIn command in the Command Window, it will bring up the Check In Dialog and let the user to select the file which need to checkin. But if all the files in the solution is that same as in the Visual SourecSafe database, it will throw an error say "Command 'File.CheckIn' is not available". You can try something like the following

    dte.ExecuteCommand("File.CheckIn");

    Thanks,
    Rong-Chun Zhang

    Please mark the replies as answers if they help and unmark if they don't.
    Welcome to the All-In-One Code Framework, a sample code project owned by the MSDN Forum Support team!

所有回覆

  • Thursday, 25 June, 2009 7:11Rong-Chun ZhangMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆
    Hello Matteo,

    When I File.CheckIn command in the Command Window, it will bring up the Check In Dialog and let the user to select the file which need to checkin. But if all the files in the solution is that same as in the Visual SourecSafe database, it will throw an error say "Command 'File.CheckIn' is not available". You can try something like the following

    dte.ExecuteCommand("File.CheckIn");

    Thanks,
    Rong-Chun Zhang

    Please mark the replies as answers if they help and unmark if they don't.
    Welcome to the All-In-One Code Framework, a sample code project owned by the MSDN Forum Support team!
  • Thursday, 2 July, 2009 11:42Matteo Garzulino 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     包含代碼

    Hi Rong-Chun,

    I tried to do what you suggested, but dte.ExecuteCommand() has this signature:

    _DTE.ExecuteCommand(string CommandName, string CommandArgs)
    

    so, i must call it with CommandArgs argument. I tried with String.Empty, but i've always the same problem, "Command 'File.CheckIn' is not available".

    If you have any other suggestions even differents from using DTE.ExecuteCommand(), you're welcome!

    Thanks,

    Matteo.  


    - Matteo Garzulino -
  • Friday, 3 July, 2009 12:07Rong-Chun ZhangMSFT, 版主使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi Matteo,

    I have tried the following code in a Add in project with Visual Studio 2008 SP1, and the Check In Dialog will show.

           _applicationObject.ExecuteCommand("File.CheckIn", String.Empty);

    As I said, in order to show the Check In Dialog, the following condition must be sure.

    1.The project must be added to SourceSave database.
    2. Source code file must be checked out or there are changes in source code file.

    Thanks,
    Rong-Chun Zhang


    Please mark the replies as answers if they help and unmark if they don't.
    Welcome to the All-In-One Code Framework , a sample code project owned by the MSDN Forum Support team!
  • Friday, 3 July, 2009 18:31Matteo Garzulino 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     
    Hi Rong-Chun,

    thanks again for your answer.

    I think that both conditions seems to be checked:

    1-Surely my Solution (and Project, and ProjectItems...) is under Source Safe;
    2-About file changes i've got some more doubts: for instance, if during my vspackage execution I add some files to a Project, Project is automatically checked-out (this is the standard behaviour, even with adding files from VS "Add New Item"), so i think that even this condition should be sure at least for .csproj files.

    Well, I'll try again on next monday... ;)

    Good Week End.

    Thanks,

    Matteo.
    - Matteo Garzulino -
  • Friday, 10 July, 2009 8:48Matteo Garzulino 使用者勳章使用者勳章使用者勳章使用者勳章使用者勳章
     已答覆包含代碼
    Hi Rong-Chun,


    I finally get command File.CheckIn to work!

    Here what i did:

            /// <summary>
            /// Esegue il comando CheckIn di un HierarchyItem precedentemente individuato.
            /// </summary>
            /// <param name="itemToCheck">HierarchyItem di cui svolgere il check</param>
            /// <param name="mDte2">Oggetto Dte.</param>
            /// <returns>True: successo; Eccezione altrimenti.</returns>
            public static bool CheckIn(UIHierarchyItem itemToCheck, DTE2 mDte2)
            {
                Commands c = mDte2.Commands;
                itemToCheck.Select(vsUISelectionType.vsUISelectionTypeSelect);
    
                foreach (Command co in c)
                {
                    if (co.Name.Contains("File.CheckIn"))
                    {
                        System.Windows.Forms.MessageBox.Show(co.Name + " - " + co.IsAvailable + " - " + co.Guid + " - " + co.ID + " - " + co.LocalizedName);
                    }
                }
                object outOb = null;
                object i = (itemToCheck as object);
                try
                {
                    c.Raise("{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}", 11150, ref i, ref outOb);
                }
                catch (Exception) //Provo con il Check su richiesta.
                {
                    c.Raise("{AA8EB8CD-7A51-11D0-92C3-00A0C9138C45}", 21014, ref i, ref outOb);
                }
    
                return true;
    
            }
    

    First, i must get a UIHierarchyItem, Select it, then i can have the command to works using Command.Raise() method.

    Note that code above is just a draft: i try to run File.CheckInSilent command, then if it fails I try File.CheckIn.

    Note also that for both methods the first parameter is the GUID of the Command, the second one is the ID. You should use them when try to checkin using Command.Raise() method.

    This seems to work very well during "normal" conditions; instead, i've got problems during or just after Project editing (for example after i add programmatically a projectitem). But this is partially off topic so i'll open a dedicated post.

    Hope that this would be helpful.

    Thanks,

    Matteo.


    - Matteo Garzulino -