@@ -273,18 +273,37 @@ public override void Run(BuildContext context)
273273
274274 var files = context . GetFiles ( new GlobPattern ( $ "{ nativeAssetsPath . FullPath } /**/*") ) ;
275275
276- // For Python, we need to preserve directory structure
276+ // For Python, we need to flatten the directory structure
277277 if ( projectItem . DotNetNativeName == "Python" )
278278 {
279279 foreach ( var file in files )
280280 {
281281 var relativePath = file . FullPath . Substring ( nativeAssetsPath . FullPath . Length + 1 ) ;
282- var targetFile = System . IO . Path . Combine ( targetDirectory . FullPath , relativePath ) ;
283- var targetFileDir = System . IO . Path . GetDirectoryName ( targetFile ) ;
284- Directory . CreateDirectory ( targetFileDir ) ;
285- context . CopyFile ( file , targetFile ) ;
282+ var fileName = System . IO . Path . GetFileName ( file . FullPath ) ;
283+ var fileExtension = System . IO . Path . GetExtension ( fileName ) . ToLowerInvariant ( ) ;
284+
285+ // Check if file is in lib/ subdirectory
286+ var isInLibDir = relativePath . StartsWith ( "lib" + System . IO . Path . DirectorySeparatorChar ) ||
287+ relativePath . StartsWith ( "lib/" ) ;
288+
289+ // Flatten: move .so/.dylib files from lib/ to root, keep python3.x/ structure
290+ if ( isInLibDir && ( fileExtension == ".so" || fileExtension == ".dylib" ) )
291+ {
292+ // Move shared libraries to root directory
293+ var targetFile = System . IO . Path . Combine ( targetDirectory . FullPath , fileName ) ;
294+ context . CopyFile ( file , targetFile ) ;
295+ context . Log . Information ( $ "Flattened: { relativePath } -> { fileName } ") ;
296+ }
297+ else
298+ {
299+ // Keep directory structure for Python standard library (python3.x/)
300+ var targetFile = System . IO . Path . Combine ( targetDirectory . FullPath , relativePath ) ;
301+ var targetFileDir = System . IO . Path . GetDirectoryName ( targetFile ) ;
302+ Directory . CreateDirectory ( targetFileDir ) ;
303+ context . CopyFile ( file , targetFile ) ;
304+ }
286305 }
287- context . Log . Information ( $ "Copied Python runtime with directory structure preserved to '{ targetDirectory . FullPath } '") ;
306+ context . Log . Information ( $ "Copied Python runtime with flattened structure to '{ targetDirectory . FullPath } '") ;
288307 }
289308 else
290309 {
0 commit comments