How a project max path and solution name length is calculated

You’ve may have noticed that sometimes your project name is too long where other times it is accepted in the New Project Dialog.  As explained by Paul on the Visual Studio General Forums

The OS limit is 260 characters (MAX_PATH).  However, the computation is:

  Path length + 1 (separator) +
   Solution name length + 1 (separator) +
   Project name length + 1 (separator) +
   Project name length +
   80 (Reserved space)

The project name length is added twice: Once for the folder name and once for the file that holds your project itself (.vbproj, .csproj etc.). The 80 additional reserved characters are for the files that you place in the project. Most new project templates create several sub-folders for intermediate files that help with like intellisense and debugging. While we may not use the full 80 characters, it is a sensible limit.

Using Paul’s calculation above, let’s create a Max-Length project / solution named
ThisSolutionIsThirtyFiveCharacters  (35 characters long)
at location
C:\Documents and Settings\saraf\My Documents\Visual Studio 2005\Projects  (73 characters long)

Doing the math, we get
73 + 1 +
35 + 1 +
35 + 1 +
35 +
= 261

So, VS will accept creating a solution / project ThisSolutionIsThirtyFiveCharacters at C:\Documents and Settings\saraf\My Documents\Visual Studio 2005\Projects. 

Comments (6)
  1. Gabe says:

    MAX_PATH is only an OS limit in Win9x. In XP the maximum length of a path is the 32767 char limit imposed by the counted string structure. I believe each component of the path may be limited to 255 characters, though.

  2. PatriotB says:

    The maximum path length accepted by most file functions in kernel32.dll can be extended to 32767 by prepending the path with \? and using the Unicode version of the function (e.g. CreateFileW). Unfortunately, other parts of the OS (e.g. shell APIs) are hard-coded to MAX_PATH.

    260 characters seems like enough, but I’m amazed at some of the long paths that are out there. I have Windows Desktop Search installed, and it uses a complex folder structure that includes a path that is 151 characters long: C:Documents and SettingsusernameLocal SettingsApplication DataMicrosoftDesktop SearchApplicationsRSAppProjectsMyIndexBuildIxBuildPropInfo. Just a few more levels, a longer user name, and I’d be maxing out.

  3. Norman Diamond says:

    > Doing the math, we get […] = 261

    > So, VS will accept creating

    261 is greater than 260. Are you missing a "not"?

    Regarding comments by 2 others, pathnames in parameters to some Unicode APIs can be extended to a maximum length of 32767 Unicode codepoints, but so what? 260 and thereabouts aren’t only the limit to the number of bytes in pathnames to some ANSI APIs. 260 and thereabouts are also limits to the number of Unicode characters in a pathname that can be stored in places such as an NTFS volume. If you want to store a longer pathname you have to do something like mounting an ext3 volume, or storing it on some other server over a network, etc.

    There are also some smaller limits that I can’t figure out. For example some web pages (including some MSDN pages) can’t be saved to the local hard disk because of the length of some pathnames involved, but sometimes the lengths don’t even reach 260. Some files can’t be moved to the recycle bin (an ordinary deletion operation) because of some limit that’s a lot lower than 260, but they can be deleted outright without recycling. I think the latter limit has affected some files that were created in Visual Studio projects.

  4. anon says:

    What about using symbolic links, à la Unix?

  5. anon says:

    …or mapped drives as we do here in our automated build process.

  6. Maximum file path length – Windows and TFS

Comments are closed.

Skip to main content