Introduction to Source Control
Total Page:16
File Type:pdf, Size:1020Kb
Introduction to Source Control --- Overview Whether your software project is large or small, it is highly recommended that you use source control as early as possible in the lifecycle of your project. Even if you’re working alone on a small project, you can use source control to improve your personal productivity and recover from difficult problems. In fact, there is a lot of benefit from using source control from the beginning of your team project, including the ability to easily revert to previous versions of the codebase. If you work with a team or on complex projects, you should almost certainly work in a shared, version-controlled file system so that you can improve collaboration and transparency. You can also take advantage of integrated automated builds, project planning and tracking, and other Application Lifecycle Management capabilities if you use Visual Studio Online or Team Foundation Server. In this scenario, you’re a developer at a software company. Your company builds a fairly simple WPF application, but has the need for regular changes. Since there are multiple developers who need access to the codebase, access is gated by using the source control provided with Visual Studio Online. Objectives In this hands-on lab, you will learn how to: - Set up a team project using Visual Studio Online - Add a solution to source control - Manage and document the codebase over time - Search, branch, and merge the codebase - Take advantage of source control features of Visual Studio Online Prerequisites The following is required to complete this hands-on lab: - Microsoft Visual Studio 2013 (with Update 2 RC applied) - A Visual Studio Online account Notes Estimated time to complete this lab: 60 minutes. Note: You can log into the virtual machine with user name “User” and password “P2ssw0rd”. Note: This lab may make references to code and other assets that are needed to complete the exercises. You can find these assets on the desktop in a folder named TechEd 2014. Within that folder, you will find additional folders that match the name of the lab you are working on. Exercise 1: Setting up your project and environment In this exercise, you’ll go through the process of setting up a new team project using Visual Studio Online and configuring your development environment to use it. Task 1: Creating a Visual Studio Online team project In this task, you’ll create a Visual Studio Online team project. This project will ultimately house the code for your company’s product, which will be accessed by the other developers and team members at your company. 1. When you created your Visual Studio Online account, you set up a domain at visualstudio.com. Navigate to that domain and log in. The URL will be something like https://MYSITE.visualstudio.com. 2. Under the Recent projects & teams panel, click the New link. 3. In the Create new team project dialog, type “Source control” as the Project name and click Create project. It may take a few minutes for your project to be created. Note that you can use any name you like for this project, although the screenshots will not match. Note: This lab uses the default Process template and Version control options. Depending on the nature of your project, you may opt to use one of the other options. For version control, Visual Studio Online also fully supports the Git model. While there are some differences between the way the default Team Foundation Version Control and Git work, the fundamentals of source control are largely the same, and virtually everything covered in this lab applies to both. 4. After the project has been created, click Navigate to project. 5. On the project’s landing page there are plenty of options for what to do next. The first thing you should do is create a backlog item to create the initial project. Click Create new | Product Backlog Item to create your first backlog item for this project. 6. In the New Product Backlog Item dialog, type “Create initial project” and click Save. On a real project you’d want to fill out more of these fields and assign it to someone, but for the purposes of this lab you can keep it simple. 7. After the item is saved, it will update the ID near the dialog title. Make note of this ID because you will use it later to associate the work item with a check in. Press Esc to close the browser dialog. Task 2: Configuring Visual Studio to work with your project In this task, you’ll configure Visual Studio to work with your project. These steps will need to be performed for each machine you want to develop on. 1. Launch Visual Studio 2013. 2. In Team Explorer - Home, click the Connect to Team Projects button. 3. Next, click Select Team Projects…. 4. In the Connect to Team Foundation Server dialog, click Servers…. 5. In the Add/Remove Team Foundation Server dialog, click Add…. 6. In the Add Team Foundation Server dialog, type your visualstudio.com domain as the Name or URL of Team Foundation Server and click OK. If asked to sign in, use the same Microsoft account you used to create the Visual Studio Online account. 7. In the Add/Remove Team Foundation Server dialog, click Close. 8. In the Connect to Team Foundation Server dialog, check the Source control project and click Connect. Visual Studio will now connect to your project and perform some basic configuration to allow access to source code, work items, and other useful project assets. 9. In Team Explorer, there are now several options for interacting with the newly created project. Click the Home button followed by Source Control Explorer to see the source code. For a new project, the source code repository is empty, with the exception of some default build process templates. You’ll also notice that the text for the project is grey, which indicates that you do not have the latest version. However, before you can get the latest version (or add files), you’ll need to map a local folder. 10. In Source Control Explorer, right-click the root collection node (which should be [yoursite].visualstudio.com\DefaultCollection) and select Advanced | Map to Local Folder…. 11. In the Map dialog, select a local folder where you’d like all your source to be downloaded to. Note that this is a folder you can interact with outside Visual Studio, and those changes will be treated the same as any. Click Map to complete the mapping. 12. After mapping, Visual Studio will provide the option to download the latest version of all files within the mapped project. Click No to skip this process for now. 13. Right-click the Source control project and select Get Latest Version. This will be the way you get the latest version of most projects and files. If you navigate to the folder you mapped earlier using Windows Explorer, you should see that a Source control project folder has been added to it. Within that folder is a single BuildProcessTemplates folder with some XAML files. Task 3: Adding a solution to source control In this task, you’ll use Visual Studio to create a new project and add its solution to source control. After the project is in source control, other team members will be able to download it, track it, and submit changes. 1. From the main menu, select File | New | Project…. 2. In the New Project dialog, select the Visual C# | Windows category and the WPF Application template. Leave the default “WpfApplication1” project name and set the Location to the path of your project folder for the Source control project. Click OK to create the project. Note that there is an option to add the project to source control immediately, but you won’t do that here. 3. Once the project is created, you can add its solution to source control. In Solution Explorer, right- click the solution node and select Add Solution to Source Control…. 4. In the Choose Source Control dialog, select the Team Foundation Version Control option and then click OK. 5. In the Add Solution WpfApplication1 to Source Control window, use the default options to add to the Source control project in a folder named WpfApplication1. Click OK to continue. 6. When a solution is under source control, Visual Studio will indicate the status of files by adding a glyph, such as the plus signs that indicate which files have been added, but not yet checked in. 7. Right-click the solution node and select Check In…. This will bring up the Team Explorer on its Pending Changes page. Note that you could have simply navigated to this view using Visual Studio, although the Solution Explorer method has the benefit of automatically including the files within the scope of the right-click. 8. In Team Explorer, you can see all the files to be included with this check in under the Included Changes section. Right now there are fourteen, which is the entire solution. You could decide to exclude some of these if you desired, although that would potentially break the project for someone else who downloads it later. After performing a check in, the included files become known as a changeset. Changesets are a common way for searching through project history. For example, if the current check in is designed to update files and fix a bug, you would want it to be easy for someone to understand everything that was changed as part of the process to address that bug. 9.