text_2025-12-19_16-01-04.txt

import json
import os
import shutil

# Config
DEPS_FILE = 'SkyAgentProvider.deps.json'
TARGET_FRAMEWORK = '.NETCoreApp,Version=v8.0' # Matches the key in your json

def main():
    if not os.path.exists(DEPS_FILE):
        print(f"Error: {DEPS_FILE} not found.")
        return

    print(f"Reading {DEPS_FILE}...")
    with open(DEPS_FILE, 'r') as f:
        data = json.load(f)

    # 1. Get the list of libraries (packages) and their base paths
    libraries = data.get('libraries', {})
    
    # 2. Get the specific file targets for your .NET version
    targets = data['targets'].get(TARGET_FRAMEWORK, {})

    for package_id, package_data in targets.items():
        # Skip the main project itself (SkyAgentProvider) since you handled it,
        # or it doesn't follow the package structure.
        lib_info = libraries.get(package_id)
        if not lib_info or lib_info.get('type') != 'package':
            continue

        # The base path for this package (e.g., "grpc.core/2.37.0")
        package_base_path = lib_info.get('path')
        if not package_base_path:
            continue

        # Helper to move files
        def move_assets(asset_dict):
            if not asset_dict: return
            
            for relative_path in asset_dict.keys():
                # relative_path example: "lib/netstandard2.0/Grpc.Core.dll"
                filename = os.path.basename(relative_path)
                
                # Check if we have this file in our root (flat list)
                if not os.path.exists(filename):
                    # It might have already been moved
                    continue

                # Construct the full destination path
                # e.g. ./grpc.core/2.37.0/lib/netstandard2.0/Grpc.Core.dll
                dest_full_path = os.path.join(package_base_path, relative_path)
                
                # Create directories
                os.makedirs(os.path.dirname(dest_full_path), exist_ok=True)
                
                # Move the file
                print(f"Moving {filename} -> {dest_full_path}")
                shutil.move(filename, dest_full_path)

        # 3. Move Managed DLLs (under 'runtime')
        move_assets(package_data.get('runtime'))

        # 4. Move Native Assets (under 'runtimeTargets')
        # This is critical for Grpc.Core (libgrpc_csharp_ext.x64.so)
        move_assets(package_data.get('runtimeTargets'))
        
        # 5. Move Resource/Satellite assemblies (under 'resources')
        move_assets(package_data.get('resources'))

    print("Reorganization complete.")

if __name__ == "__main__":
    main()
Back to List