Set P4 Server environment variables using P4CONFIG
P4CONFIG is an environment variable that you can use to
point to a file that stores other
P4 Server
environment variables. The current working directory and its parents are
searched for the file. If the file exists, then the variable settings
within the file are used.
P4CONFIG makes it easy to switch
P4 Server
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
P4 Server
settings change to the settings in the configuration files automatically
as you move from directories in one workspace to another.
To use P4CONFIG to switch settings between client
workspaces on
P4 for Visual Studio, you must create
separate Visual Studio shortcuts for each workspace, setting the
Start in property as the workspace directory (which is also
the directory where the configuration file resides). If you launch Visual
Studio using a shortcut defined this way,
P4 for Visual Studio
will read the
P4 Server
settings from the configuration file in that workspace’s directory. This
is required because Visual Studio otherwise uses its own directory as the
current working directory.
To use P4CONFIG with
P4 for Visual Studio:
- Create a configuration file that contains the P4 Server environment variable settings you want, and put it in the workspace directory for the relevant Visual Studio solution.
- Using
p4, the P4 Server Command Line Client, unset theP4CLIENT,P4PORT, andP4USERenvironment variables and setP4CONFIGto the configuration file name. - Using P4 for Visual Studio, go to Tools > Options > Source Control > P4 - Connections and select Connect to the server using my P4 environment settings.
-
Create a Windows desktop shortcut for Visual Studio that is dedicated to the workspace with which you want to use the configuration file.
- Right-click on the desktop and select New > Shortcut.
- Enter the location of the Visual Studio executable and click Next.
- Enter a shortcut name and click Finish.
- In the shortcut properties, under Start in, enter the workspace directory where the configuration file is located, and click OK.
Repeat for each workspace for which you want a different configuration file.
- Whenever you want to work in that workspace using the configuration file settings, use the shortcut to launch Visual Studio.
To learn more about P4CONFIG and
P4 Server
environment variables, see the
P4 CLI Reference
and
Set P4 for Visual Studio preferences.