"The specified path, file name, or both are too long" When publish from Visual Studio

This is one of those posts that I wanted to write mostly to remind myself in the future when this error occurs again. I was trying to publish a site to IIS from Visual Studio 2015 and got this error:

The specified path, file name, or both are too long.

After digging through a few threads on the topic I finally find the simplest fix on where else, but SO:


Here it is in a nutshell:

Add this to your publish profile to modify the temporary directory for package/publish:


it goes inside the <PropertyGroup> tag. You can then republish and it should all work.

That's it.