none
Build - New File - Check-In

    Question

  • Hi All,

    I have a Build Process Template with a Custom Activity which creates a few new files and adds them to the Binaries Folder.

    Is it possible to add/Check-In these new files to a specific location in TFS?

    Thanks in advance.

    Ben

    Monday, September 30, 2013 9:44 AM

Answers

  • Hi Gabby,

    Please follow the Checkin Checkout sample explained in this post for changing assembly version number. You can implement a similar thing to achieve what you want. But make sure to not to trigger CI build when you check in through the build to avoid endless loop.

    http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx

    How to add a new file explained here

    http://blogs.msdn.com/b/buckh/archive/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer.aspx

    Hope this helps.

    Cheers!

    Chaminda

    • Marked as answer by BenGabb Wednesday, October 02, 2013 4:07 PM
    Monday, September 30, 2013 11:03 AM
  • For anyone who comes across this and needs an answer, here it is.

    Follow Chaminda's Link here - http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx

    to create the activity and use the following code to copy/checking the file.

    	// Define an activity input argument of type string
            public InArgument<string> SourceFile { get; set; }
            public InArgument<string> DestinationFile { get; set; }
            public InArgument<Workspace> WorkSpace { get; set; }
    
            // If your activity returns a value, derive from CodeActivity<TResult>
            // and return the value from the Execute method.
            protected override void Execute(CodeActivityContext context)
            {
                try
                {
                    // Obtain the runtime value of the Text input argument
                    string source = context.GetValue(this.SourceFile);
                    string destination = context.GetValue(this.DestinationFile);
                    Workspace workspace = context.GetValue(this.WorkSpace);
    
                    // If the file exists, replace it and mark it as edited.
                    if (File.Exists(destination))
                    {
                        File.SetAttributes(destination, FileAttributes.Normal);
                        File.Delete(destination);
                        File.Copy(source, destination, true);
                        workspace.PendEdit(destination);
                    }
                    else
                    {
                        // else just add it.
                        File.Copy(source, destination, true);
                        workspace.PendAdd(destination);
                    }
                    // Checkin Changes
                    workspace.CheckIn(workspace.GetPendingChanges(), "New File Checking");
                }
                catch(Exception e)
                {
    
                }
            }

    the DestinationFile needs to be set the the mapped local directory.

    Cheers

    Ben



    Wednesday, October 02, 2013 4:01 PM

All replies

  • Hi Gabby,

    Please follow the Checkin Checkout sample explained in this post for changing assembly version number. You can implement a similar thing to achieve what you want. But make sure to not to trigger CI build when you check in through the build to avoid endless loop.

    http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx

    How to add a new file explained here

    http://blogs.msdn.com/b/buckh/archive/2012/03/10/team-foundation-version-control-client-api-example-for-tfs-2010-and-newer.aspx

    Hope this helps.

    Cheers!

    Chaminda

    • Marked as answer by BenGabb Wednesday, October 02, 2013 4:07 PM
    Monday, September 30, 2013 11:03 AM
  • Hi Ben,  

    Thanks for your post.

    And you can add the InvokeProcess activities in your build process template to execute the tf add, tf checkin command to check-in that new files into TFS.


    John Qiao [MSFT]
    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, October 01, 2013 2:07 AM
    Moderator
  • For anyone who comes across this and needs an answer, here it is.

    Follow Chaminda's Link here - http://www.ewaldhofman.nl/post/2010/05/13/Customize-Team-Build-2010-e28093-Part-5-Increase-AssemblyVersion.aspx

    to create the activity and use the following code to copy/checking the file.

    	// Define an activity input argument of type string
            public InArgument<string> SourceFile { get; set; }
            public InArgument<string> DestinationFile { get; set; }
            public InArgument<Workspace> WorkSpace { get; set; }
    
            // If your activity returns a value, derive from CodeActivity<TResult>
            // and return the value from the Execute method.
            protected override void Execute(CodeActivityContext context)
            {
                try
                {
                    // Obtain the runtime value of the Text input argument
                    string source = context.GetValue(this.SourceFile);
                    string destination = context.GetValue(this.DestinationFile);
                    Workspace workspace = context.GetValue(this.WorkSpace);
    
                    // If the file exists, replace it and mark it as edited.
                    if (File.Exists(destination))
                    {
                        File.SetAttributes(destination, FileAttributes.Normal);
                        File.Delete(destination);
                        File.Copy(source, destination, true);
                        workspace.PendEdit(destination);
                    }
                    else
                    {
                        // else just add it.
                        File.Copy(source, destination, true);
                        workspace.PendAdd(destination);
                    }
                    // Checkin Changes
                    workspace.CheckIn(workspace.GetPendingChanges(), "New File Checking");
                }
                catch(Exception e)
                {
    
                }
            }

    the DestinationFile needs to be set the the mapped local directory.

    Cheers

    Ben



    Wednesday, October 02, 2013 4:01 PM