Excluding Files from Perforce

Your workspace may include files that you do not want to add to the Perforce repository, such as files used or generated by automated build processes.

You can use Visual Studio to exclude a file from a solution by context-clicking the file in Solution Explorer and selecting Exclude from Project in the context menu. If the file is under Perforce control, P4VS prompts you to mark the file for delete, and after submitting the changelist that includes the deletions, the file is removed from both the project and the Perforce repository.

You can also use Ignore Lists in P4VS to specify files or filetypes that you want to keep in your project but do not want to add to the Perforce repository. An Ignore List is a file in your local workspace directory that contains a list of file names or file types to ignore. For example, you can create an Ignore List called .p4ignore in your project folder that contains the following:

*.swp
*~
tmp/*
.p4ignore.txt

(Note that the Ignore List file itself is included in the list.)

You can add an Ignore List file at any level of the solution hierarchy in your workspace. If you set your P4IGNORE environment variable to the file name of the Ignore List file, P4VS will not mark the listed files and filetypes for add, nor will it prompt you to do so.

Ignore Lists only affect commands that search for and add new files. If you have already marked a file for add, P4VS will no longer ignore it, even if it or its filetype appear in an Ignore List.

You can add Ignore Lists at any folder level in your workspace (or solution). P4VS applies the rules in the Ignore List at the deepest folder level relative to the file being checked, along with the rules in any Ignore Lists found in parent folders (although you can use the ! character to override higher-level rules.)

The syntax for ignore rules is not the same as Perforce syntax. Instead, it is similar to that used by other versioning systems:

For example:

foo.txt Ignore files called "foo.txt"
*.exe Ignore all executables
!bar.exe Exclude bar.exe from being ignored

While you can set your local P4IGNORE environment variable and add Ignore Lists manually, P4VS provides preferences and context menu options to simplify the process of adding and editing Ignore Lists.

Setting Ignore List preferences

Go to Tools>Options>Source Control>Perforce - Ignoring Files to set Ignore List preferences, including the Ignore List file name. The file name you enter in your preferences is set by P4VS as the local P4IGNORE environment variable and used for all of your Ignore Lists. For more information about setting Ignore List preferences, see Setting Perforce preferences.

Adding a file to an Ignore List

To add a file to an Ignore List in Solution Explorer, context-click the file and select Manage Files>Add to Ignore List. P4VS adds the file to the Ignore List in the current folder. If there is no Ignore List file in the current folder, P4VS creates one.

In Visual Studio 2012, P4VS denotes an ignored file with a gray circle glyph next to the file icon. In Visual Studio 2008 and 2010, P4VS denotes an ignored file by removing the blue question mark glyph: .

Removing a file from an Ignore List

To remove a file from an Ignore List in Solution Explorer, context-click the file and select Manage Files>Remove from Ignore List. P4VS adds an exclusionary (!) line for the file in the Ignore List in the current folder, which overrides any Ignore Lists in parent folders.

Editing Ignore Lists

To edit an Ignore List in Solution Explorer, context-click any file in the same folder and select Manage Files>Edit Ignore List. P4VS opens the Ignore List file for edit. If there is no Ignore List file in the current folder, P4VS creates one. Use Edit Ignore List when you want to add file types using wildcard expressions.



Copyright Perforce Software 2003-2014. All Rights Reserved.