in Unity 5, how can I get/set an asset's AssetBundle assignment via scripting?

I’m trying to use the new 5.x way of doing things in creating assetbundles, as per http://docs.unity3d.com/Manual/BuildingAssetBundles5x.html
and
http://docs.unity3d.com/Manual/scriptsinassetbundles.html

I’m running into difficulties with including script dll assemblies in these bundles. The assemblies themselves work fine. I’m only having a problem including them in assetbundles.

If I simply use the editor to set an AssetBundle name, then call BuildPipeline.BuildAssetBundles(“path”), I get an error saying that DLL files are “unrecognized”, and cannot be included.

To deal with this problem, I’ve created logic to rename the DLL files as BYTES files (using System.IO.File.Move()). This is where the unresolved problem comes in… when I rename the file via script, the AssetBundle that I’d previously designated in the editor is reset to ‘None’, so when I subsequently call BuildAssetBundles(), these DLLs (now renamed as BYTES files) are not getting included in any of the bundles that are being created.

How can I use C# scripting to get/set/preserve the AssetBundle assignment as set in the editor? I didn’t see any API functions that I’d hoped for such as maybe AssetDatabase.AddFileToAssetBundle(), or some such. Did I miss something?

Thanks in advance!


PS - In case it helps, here is the code I’m using to rename the DLLs and (trying unsuccessfully to) create the bundles:

using UnityEngine;
using UnityEditor;
using System.IO;

public class CreateAssetBundles
{
    [MenuItem("Assets/Build AssetBundles")]
    static void BuildAllAssetBundles()
    {
        RenameAllPluginsDllToBytes();
        Debug.Log("Exporting all assetbundles...");
        BuildPipeline.BuildAssetBundles("AssetBundles");
        RenameAllPluginsBytesToDll();
    }

    [MenuItem("Assets/Rename all Plugins DLLs to 'bytes'")]
    static void RenameAllPluginsDllToBytes()
    {
        Debug.Log("Renaming all '*.dll' files in Assets/Plugins to '.bytes' extension.");
        string pluginsFolderName = Application.dataPath + "/Plugins";
        var dirInfo = new DirectoryInfo(pluginsFolderName);
        var allFileInfos = dirInfo.GetFiles("*.dll", SearchOption.AllDirectories);
        foreach (var fileInfo in allFileInfos)
        {
            if (Path.GetExtension(@fileInfo.FullName) != ".dll")
            {
                Debug.LogWarning("Ignoring: '" + @fileInfo.FullName + "'");
                continue;
            }

            string newfilename = Path.ChangeExtension(@fileInfo.FullName, ".bytes");
            //Debug.Log("Renaming '" + @fileInfo.FullName + "' to '" + @newfilename + "'");
            File.Move(@fileInfo.FullName, @newfilename);
            AssetDatabase.Refresh();
        }
    }

    [MenuItem("Assets/Rename all Plugins BYTES to 'dll'")]
    static void RenameAllPluginsBytesToDll()
    {
        Debug.Log("Renaming all '*.bytes' files in Assets/Plugins to '.dll' extension.");
        string pluginsFolderName = Application.dataPath + "/Plugins";
        var dirInfo = new DirectoryInfo(pluginsFolderName);
        var allFileInfos = dirInfo.GetFiles("*.bytes", SearchOption.AllDirectories);
        foreach (var fileInfo in allFileInfos)
        {
            string newfilename = Path.ChangeExtension(@fileInfo.FullName, ".dll");
            //Debug.Log("Renaming '" + @fileInfo.FullName + "' to '" + @newfilename + "'");
            File.Move(@fileInfo.FullName, @newfilename);
            AssetDatabase.Refresh();
        }
    }
}

I’ve discovered the answer to my own question. I did miss some things in the API, so it is possible to get/set the assetbundle information from script.

Here is some example code, if anyone else is interested.

        foreach (var assetGuid in AssetDatabase.FindAssets(""))
        {
            string assetPath = AssetDatabase.GUIDToAssetPath(assetGuid);
            string bundleName = AssetImporter.GetAtPath(assetPath).assetBundleName;
            if (string.IsNullOrEmpty(bundleName))
            {
                continue;
            }
            Debug.Log("Found asset: (GUID:<color=#00ffffff>" + assetGuid + "</color>) " + assetPath + ", AssetBundle: " + bundleName);
        }