搜尋此網誌

2016-12-01

SSIS 指令碼元件載入 dll

How to load an Assembly in a SSIS script task that isn’t in the GAC

VS 2015 實測
    public override void PreExecute()
    {
        base.PreExecute();
        AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    }

    public ScriptMain()
    {
        // 放在這裡不會跑
        //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
    }

    public Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
    {
        if (args.Name.Contains("DataEncrypt"))
        {
            var path = Variables.AssemblyPath; // 使用變數
            return Assembly.LoadFile(System.IO.Path.Combine(path, "DataEncrypt.dll"));
        }
        return null;
    }
Referencing a custom assembly inside a Script Task
Could not load file or assembly

沒有留言: