C# 在 ssis 脚本组件中添加第三方 dll 引用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11611165/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Add third party dll reference in ssis script component
提问by HashCoder
I have added third party reference (Json newtonsoft) dll in my script component (using edit script option), but when i run the package, I am getting an error
我在脚本组件中添加了第三方引用 (Json newtonsoft) dll(使用编辑脚本选项),但是当我运行包时,出现错误
Could not load file or assembly 'Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
无法加载文件或程序集“Newtonsoft.Json,版本=4.5.0.0,Culture=neutral,PublicKeyToken=30ad4fe6b2a6aeed”或其依赖项之一。该系统找不到指定的文件。
Any suggestions?
有什么建议?
I will not be able to add the dll in GAC.
我将无法在 GAC 中添加 dll。
I am using SQL Server 2008.
我正在使用 SQL Server 2008。
采纳答案by billinkc
By "Running," I assume running from agent/command-line is failing? It should work from within BIDS/SSDT. The short answer is the DLL must be registered with the GAC or you can download the source code and add that project into the script task and then reference said project.
通过“运行”,我假设从代理/命令行运行失败?它应该在 BIDS/SSDT 内工作。简短的回答是 DLL 必须向 GAC 注册,或者您可以下载源代码并将该项目添加到脚本任务中,然后引用该项目。
Looking at the project, it should be a strongly signed DLL (based on presences of Dynamic.snk) and thus capable of being added to the GAC. Oh, but you state you will not be ableto add it into the GAC, implying it's a permission not a capability issue.
查看该项目,它应该是一个强签名的 DLL(基于Dynamic.snk 的存在),因此能够添加到 GAC。哦,但是您声明您将无法将其添加到 GAC 中,这意味着这是权限问题而不是能力问题。
If that's the case, either compile the project in with the source or surround it with a web service wrapper and then reference the service.
如果是这种情况,要么使用源代码编译项目,要么使用 Web 服务包装器将其包围,然后引用该服务。
I also saw this answer, seems you can try loading the references dynamically.
我也看到了这个答案,看来您可以尝试动态加载引用。
回答by Mudassir Hasan
You can using Reflection to load dll at runtime from file system without needing to install in GAC . This is helpful if permission to install in GAC is not availaible .
您可以使用反射在运行时从文件系统加载 dll,而无需在 GAC 中安装。如果在 GAC 中安装的权限不可用,这将很有帮助。
//Add a Static Constructor which is guaranteed to be called exactly once
// “before the first instance is created or any static members are referenced.”,
// so therefore before the dependent assemblies are loaded.
static ScriptMain()
{
AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);
}
//Provide path to dll stored in folder on file system
static System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
string path = @"D:\DLL\";
return System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(path, "Newtonsoft.dll"));
}
Ofcourse you need to also Add Reference to dll in script task .
当然,您还需要在脚本任务中添加对 dll 的引用。

