@@ -56,5 +56,63 @@ public static DirectoryPath ExpandEnvironmentVariables(this DirectoryPath path,
5656 var result = environment . ExpandEnvironmentVariables ( path . FullPath ) ;
5757 return new DirectoryPath ( result ) ;
5858 }
59+
60+ /// <summary>
61+ /// Expands short paths (e.g. C:/Users/ABCDEF~1) to long paths (e.g. C:/Users/abcdefghij).
62+ /// <para/>
63+ /// Note that this method only works for absolute paths, as relative paths cannot be expanded without impact.
64+ /// </summary>
65+ /// <param name="path">The path to check.</param>
66+ /// <returns>The path for which, if available, the short paths are expanded to long paths.</returns>
67+ public static FilePath ExpandShortPath ( this FilePath path )
68+ {
69+ if ( ! path . IsRelative )
70+ {
71+ // Only when not relative, resolve short paths to long paths, e.g.:
72+ //
73+ // C:/Users/ABCDEF~1/AppData/Local/Temp/cake-build/addins
74+ // C:/Users/abcdefghij/AppData/Local/Temp/cake-build/addins
75+ //
76+ // The reason this is required is that tools / addins can't be located
77+ // when using short paths
78+ //
79+ // Note that a path can contain multiple ~, thus we need to check for just ~
80+ if ( path . FullPath . Contains ( '~' ) )
81+ {
82+ return new FilePath ( System . IO . Path . GetFullPath ( path . FullPath ) ) ;
83+ }
84+ }
85+
86+ return path ;
87+ }
88+
89+ /// <summary>
90+ /// Expands short paths (e.g. C:/Users/ABCDEF~1) to long paths (e.g. C:/Users/abcdefghij).
91+ /// <para/>
92+ /// Note that this method only works for absolute paths, as relative paths cannot be expanded without impact.
93+ /// </summary>
94+ /// <param name="path">The path to check.</param>
95+ /// <returns>The path for which, if available, the short paths are expanded to long paths.</returns>
96+ public static DirectoryPath ExpandShortPath ( this DirectoryPath path )
97+ {
98+ if ( ! path . IsRelative )
99+ {
100+ // Only when not relative, resolve short paths to long paths, e.g.:
101+ //
102+ // C:/Users/ABCDEF~1/AppData/Local/Temp/cake-build/addins
103+ // C:/Users/abcdefghij/AppData/Local/Temp/cake-build/addins
104+ //
105+ // The reason this is required is that tools / addins can't be located
106+ // when using short paths
107+ //
108+ // Note that a path can contain multiple ~, thus we need to check for just ~
109+ if ( path . FullPath . Contains ( '~' ) )
110+ {
111+ return new DirectoryPath ( System . IO . Path . GetFullPath ( path . FullPath ) ) ;
112+ }
113+ }
114+
115+ return path ;
116+ }
59117 }
60118}
0 commit comments