Welcome to MSDN Blogs Sign in | Join | Help

Sara Ford's Weblog

My adventures embracing open source on CodePlex and at Microsoft

News

    • Did you know... All author proceeds go directly to sending Hurricane Katrina survivors to college.

      Microsoft Visual Studio Tips book

      Recent Entries

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 +
80
= 261

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

Happy Visual Studio’ing!

Tags:
References
Suggest a Tip!

Posted: Thursday, December 15, 2005 10:16 AM by saraford

Comments

Gabe said:

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.
# December 15, 2005 2:24 PM

PatriotB said:

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 Settings\username\Local Settings\Application Data\Microsoft\Desktop Search\Applications\RSApp\Projects\MyIndex\Build\IxBuild\PropInfo. Just a few more levels, a longer user name, and I'd be maxing out.
# December 15, 2005 4:20 PM

Norman Diamond said:

> 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.
# December 15, 2005 10:09 PM

anon said:


What about using symbolic links, à la Unix?
# January 16, 2006 2:06 PM

anon said:



...or mapped drives as we do here in our automated build process.
# January 16, 2006 2:07 PM

blog.TroyFarrell.com said:

Maximum file path length - Windows and TFS

# August 3, 2008 12:35 PM
New Comments to this post are disabled
Page view tracker