Chapter 4
Microsoft Visual Studio .NET
This chapter describes how to perform Perforce source code control tasks in the Visual Studio .NET environment. It assumes the Perforce SCC Plug-in is installed and that your client machine can communicate with the Perforce server. For details about configuring settings, see "Configuring IDEs with plug-ins" on page 12.
This screen illustrations in this chapter shows Visual C++, but the same dialogs are displayed regardless of which Visual Studio IDE you use.
Note
|
The version control dialogs displayed for check in, check out, and undo checkout include comment fields, but these comment fields are not stored by the Perforce SCC Plug-in. To avoid displaying the check in dialog, choose Check-in Now.
|
Configuring Visual Studio .NET with Perforce
When you configure VS .NET with the Perforce SCC Plug-in, the settings are specific to the project you are working on, so no overall Perforce configuration is required for Visual Studio. The Perforce SCC Plug-in retains project settings from session to session and it is not necessary to re-enter them.
When you create a project you intend to manage with Perforce, specify a location that resides within the Perforce client root folder of the client you intend to use as illustrated in the following figure.
Basic SCM tasks
This section tells you how to perform the following tasks.
- If you are adding a solution that contains a large number of projects, you can avoid specifying settings manually for every project by choosing the Options > Connection tab setting Bind to the workspace that matches your Perforce environment settings and setting P4CLIENT and P4PORT to the desired server and workspace.
Also note that the Exclude from source control option is intended for files that, by nature, do not belong under source code control (such as build outputs).
Adding a project to the depot
Make sure your Visual Studio .NET projects reside within your Perforce client workspace.
To add a Visual Studio .NET project to your depot, perform the following steps:
- In the Solution Explorer, right-click the project and choose Source Control>Add Solution to Source Control. If you enabled the Show the Perforce Connections option on the Preferences > Connection tab, the Open Connection dialog is displayed. .
- On the Open Connection dialog, enter the required settings as follows:
- Server: the name of the host computer running the Perforce server in which you want to store the project.
- Port: the port number on which the specified Perforce Server accepts commands.
- User: the Perforce user name you want associated with the SCM operations you perform on the project. To choose from a list of users defined for the specified server, click Browse.
- Password: the user's password, if any.
- Client: the Perforce client specification want associated with the SCM operations you perform on the project. To choose from a list of client specifications defined for the specified server, click Browse.
- Click OK. Project files are displayed in the Pending Checkins pane. (Using another Perforce client, you can verify that the files are open for add.)
- In the Solution Explorer, right-click the solution and choose Check In.
- The Check In dialog, listing files, is displayed.
- Click Check In... The Pending Changelist dialog is displayed.
- Enter a description in the Description field and click Submit. Your files are added to the depot. (Using Perforce, you can verify that the default changelist has been submitted and the files are now in the depot.)
Checked-in files are displayed with a lock icon. If you attempt to edit a file that is not checked out, a check-out dialog is displayed.
Checking files out
To check out files:
- In the Solution Explorer pane, right-click the desired file (or the project, if you want to check out all its files) and choose Check Out... The Check Out dialog is displayed.
- Click OK. In the Solution Explorer pane, files are displayed with a check mark, as shown in the following figure.
The checked-out files are listed in the Pending Checkins pane. Using another Perforce client, you can verify that the files are open for edit.
If you branch a project using Perforce, the Visual Studio bindings must be corrected to correspond to the project's new location. To correct bindings for a branched solution, you must perform the following steps the first time you check out the branched project.
To check out a newly-branched project (first time only):
- Choose File> Source Control > Open from Source Control.... The Open Connection dialog is displayed.
- Specify connection settings for the server that contains the project you want to check out and click OK. The Open Project dialog is displayed.
- Browse to the branched project you want to open and double-click its .sln file.
- If the newly-branched files are present in your workspace, Visual Studio displays the following dialog:
- Click Overwrite. Visual Studio displays the Open Solution dialog.
- Double-click the .sln file. Visual Studio displays the following dialog.
- Click Solution's bindings. Visual Studio displays the following dialog.
- Click OK.
The project now contains correct binding information.
Retrieving files from the depot
To get the most recent revision of a file from the depot, right-click the file in the Solution Explorer pane and choose Get Latest Version.
To retrieve revisions prior to the head (latest) revision, you can sync from the Revision History dialog or perform the following steps:
- In the Solution Explorer pane, click the file.
- Choose File > Source Control > History. The Revision History dialog is displayed, listing the revisions in the depot.
- Right-click the desired revision and choose Sync Revision.
Note
|
If you retrieve a file that you already have checked out, for example, to obtain changes checked in by another user, Perforce requires you to resolve the file, to ensure that you don't inadvertently overwrite other users' changes.
|
To sync all files for a project that resides in the depot:
- Choose File > Source Control > Open from Source Control... The Open Connection dialog is displayed.
- Enter the settings that specify the server where the project is stored and the client workspace and user with which you want to check the project files out, and click OK. The Perforce Open Project dialog is displayed.
- Browse to the .sln file for the project you want to sync and click OK. The project files are synced to your workspace.
Checking files in
After editing checked-out files, you must check them into the depot. Your edited files become the head revision in the depot. (If your changes conflict with changes previously submitted by another user, the check-in fails and the differences must be resolved using Perforce.).
To check in files, perform the following steps:
- In the Solution Explorer pane, right-click the file and choose Check In... The Check In dialog is displayed.
- Click Check In. The Pending Changelist dialog is displayed.
- Enter a description of your changes and click Submit.
In the Solution Explorer pane, the check marks are replaced by locks, indicating that the submitted files were checked in.
Note
|
To produce meaningful change history, check in related files together. For example, if you changed two different files to fix a bug, check them both in at the same time. The files are submitted in the same changelist.
|
Resolving file conflicts
If you encounter conflicts when checking in files, (for example, from multiple users working on the same files,) you must resolve the conflicts before you can submit the files. For example, if you and another user have changed the same file and the other user checked in changes before you, when you attempt to check in your changes, Perforce notifies you that resolution is required by displaying the following message in the Pending Changelist dialog:
To resolve file conflicts:
- Click Sync and select the files to be resolved. The button text changes to Resolve.
- Click Resolve and choose All Files... The Resolve Files dialog is displayed, describing the extent of the file differences and listing the following options:
- Enter a description of your changes and click Submit. Your changes are checked in.
Diffing files
To diff a file you are editing with the head revision in the depot, right-click the file and choose Compare Versions....
To diff two revisions of a file, perform the following steps:
- In the Solution Explorer pane, right-click the file and choose File > History. The Revision History dialog is displayed, listing the revisions in the depot.
- To diff two revisions drag one revision to the other.
P4Diff is launched, displaying file differences.
Reverting files
To discard changes you've made to a checked-out file and reload the head revision from the depot:
- In the Solution Explorer pane, right-click the file and choose Undo Check Out... The Undo Check Out dialog is displayed, listing the files to be reverted.
- Check the files you want to revert and click Undo Checkout.
In the Solution Explorer pane, the reverted files are displayed with a lock icon, indicating that they are no longer checked out. The head revision is copied from the depot to your workspace, overwriting any changes you made to the workspace file.
You can also revert unchanged files from the Pending Changelist dialog.
Which files do I put in the depot?
Visual Studio .NET adds all appropriate files when the project is first added to source control, so, in general, don't change the contents of the changelist that is created when you choose Add to Source Control.
Put .sln files in the depot. Do not put the .suo files in the depot. The .suo files are managed by Visual Studio .NET separately for each client computer.
Miscellaneous tasks
To view the Perforce commands issued by the plug-in, choose View>Other Windows>Output and display the Source Control pane.
Please send comments and questions about this manual to
manual@perforce.com.
Copyright 2001-2004 Perforce Software. All rights reserved.
Last updated: 08/19/04