Here, items is a List<object> and each item is guaranteed to be an asset in the database. However, in any case where a non-default shader is listed as the item to export, or the item includes a non-default shader as a dependency (such as a material that uses it), I get this error message:
I.e. instead of the IncludeDependencies options I use Default, I still get the error. My unity version is 4.3.4f1 and my Environment is Window 7 (Japanese). The odd thing is, if I do the export manually, through the menu Assets->Export Package, it works fine.
In case any one comes along with this problem in the future, I figured it out.
In the second parameter, I use items[0].name. In the case of most objects, this is fine because it contains the name of the object excluding any subdirectories it’s in. However, in the case of shaders, it contains the display name of the shader, as you select it from the list when making a material. This is NOT the same as the name of the asset in the project.
For example, I made a shader called VarBrush.shader, which is listed in the menus as Outlined/VarBrush. The problem is, its .name property is “Outlined/VarBrush”. When exporting, Unity chokes on trying to put a slash in the filename (it won’t create nonexsting directories from a specified file path). This is why the error is in copying it from Unity’s temporary packaging directory into my specified filename.
My solution:
string namesan = items[0].name.Replace('\\', '_').Replace('/','_');
//Sanitize slashes in name
AssetDatabase.ExportPackage(AssetDatabase.GetAssetPath(items[0]),
"C:\\path\\" + namesan + ".unitypackage",
ExportPackageOptions.IncludeDependencies);