Connecting to Perforce services

Connections enable you to access the shared Perforce service to submit and obtain access to files under Perforce control. You use the Open Connection dialog both to define connections and to open them in P4VS.

Defining a new Perforce service connection

To define a new Perforce service connection in Visual Studio:

  1. Open the Open Connection dialog. You can open this dialog the following ways:

    • Add a new project in Visual Studio in the New Project dialog.

      The Open Connection dialog appears unless you’ve set the connection settings in Tools > Options > Source Control to default to the last Perforce connection or to connection settings defined in your environment variables.

    • Open a solution or project under Perforce source control in Visual Studio.

      The Open Connection dialog appears unless you’ve set the connection settings in Tools > Options > Source Control to default to the last Perforce connection or to connection settings defined in your environment variables.

    • Go to File > Open Connection to a Perforce Depot in Visual Studio.
  2. Enter the service name and port number for this connection using service_host:port_number.

    If your Perforce service is enabled for SSL (Secure Sockets Layer) encryption, use the following syntax: ssl:service_host:port_number

    Important

    If you attempt to connect to an SSL-enabled Perforce service and you see a warning about an untrusted SSL connection or altered SSL fingerprint, contact your Perforce administrator before completing the connection.

  3. In the User field, enter your user name.

    • To browse for a particular user, click the Browse…​ button and select the user from that list.
    • To create a user, click the New…​ button and fill in the appropriate information.
  4. (Optional) In the Workspace field, specify the name of your client workspace.

    • To browse for a particular client workspace, click the Browse…​ button and select the workspace from that list.
    • To create a client workspace, click the New…​ button.
    • In the New Workspace dialog, enter a workspace name and click OK.
    • In the Workspace dialog, entered the required information.

    For more information on setting up client workspaces, see Managing workspace specifications.

  5. Click OK.

    P4VS connects to the specified Perforce service.

Setting Perforce connection settings using environment variables

You can set Windows environment variables for Perforce connection settings, which makes the settings available to P4VS and other Perforce client applications (for example, P4EXP, the Perforce plug-in for Windows Explorer). Set Perforce connection settings as environment variables and configure your connection preferences in Tools > Options > Source Control to default to the environment variables.

Another approach is to create a configuration file that stores your Perforce environment variables. You can then point to the configuration file using the environment variable P4CONFIG. P4VS searches the current working directory and its parents for the file. If the file exists, then P4VS uses the variable settings within the file. P4CONFIG makes it easy to switch Perforce settings when switching between different solutions or projects. If you place a configuration file in each of your client workspaces and set P4CONFIG to point to that file, your Perforce settings change to the settings in the configuration files automatically as you move from directories in one workspace to another.

For more information about how to use P4CONFIG with P4VS, see Setting Perforce environment variables using P4CONFIG.

For more information about Perforce environment variables, see the P4 Command Reference and Setting Perforce preferences.

Opening a defined Perforce service connection

To open a Perforce service connection that you have already used, select the connection from the drop-down list in the Open Connection dialog. You can also configure P4VS to automatically open the connection that you used most recently when you open a project. See Setting Perforce preferences.