【问题标题】:Reference a .net 3.5 assembly in a Script Task in SSIS 2005?在 SSIS 2005 的脚本任务中引用 .net 3.5 程序集?
【发布时间】:2011-01-05 03:49:00
【问题描述】:

我已经使用一个非常基本的示例(如下所述)来实现这一点,我想看看其他 SOers 是否有经验做我正在尝试的事情......在 SSIS 2005 的脚本任务中使用 3.5 框架程序集.

除了我在 Visual Studio 2008 中针对 3.5 框架之外,我基本上遵循了找到 here... 的页面。

  1. 编写/编译您的代码(针对 3.5 框架)只是一些简单的 Linq,以便我使用大于 2.0 的框架功能

    using System;  
    using System.Collections.Generic;  
    using System.Text;  
    using System.Linq;    
    
    namespace Ext
    {
       public class Extend
       {
           public string GetValue () 
           {
              /* 
                 Test Linq to "prove" that we're not running against the   
                 2.0 framework.
                 I know this code could be improved, but bear with me...  
                 it's throwaway code just to test the concept
                */
              string [] teststring = new string [3];
              teststring[0] = "named Extend";
              string returnString = String.Empty;
              var s = teststring.Where(x => x.ToString() == "named Extend");
              foreach (var x in s)
              {
                returnString = x.ToString();
              }
              return "Extending Script Task through a custom library " + returnString;
          }
       }  
    }
    
  2. 给它一个强名称键
  3. 使用 gacutil 将程序集添加到 GAC
  4. 已将程序集复制到 C:\Windows\Microsoft.NET\Framework\v2.0.50727 文件夹...dev
    机器正在运行 Windows 7
  5. 创建了脚本任务并添加了对程序集的引用
  6. 在脚本任务中

    Dim x As New Extend()
    MsgBox(x.GetValue.ToString())  
    

它工作正常,因为当我运行 SSIS 项目时,我会返回一个带有文本的消息框
"通过名为 Extend 的自定义库扩展脚本任务"

所以...我的问题是,当我尝试做更复杂的事情时,SSIS 项目/脚本任务是否仍然有效...尤其是当我调用使用 LinqToEntities 的(尚未编写的)程序集时?

我必须将文件复制到 Framework 2.0 文件夹并将其添加到 GAC 对我来说似乎很奇怪......但也许这只是一个奇怪的 SSIS 要求......我知道我不能在脚本任务,除非该程序集位于 Framework 2.0 文件夹中...

【问题讨论】:

    标签: .net-3.5 .net-2.0 ssis


    【解决方案1】:

    为安全起见,您可以尝试更改编译框架。

    在 C# 中

    Project Explorer > Properties > Target Framework 下拉菜单

    How do I find the .NET framework version used in an SSIS 2008 R2 package?

    在 VB 中

    菜单 > 项目 > 项目属性,
    单击编译选项卡,然后单击高级编译选项并更改目标框架下拉列表

    http://www.demiliani.com/blog/archive/2007/08/24/6430.aspx

    【讨论】:

      【解决方案2】:

      哇,我知道这个答案来晚了。但我认为它不会产生任何问题,因为 SSIS 会在运行时从 GAC 加载程序集,只要你的机器上有 .net framework 2.0 和 3.5,代码就可以在运行时工作。

      framework 2.0 中的文件仅用于开发 ide 和预编译脚本任务/组件。在运行时,重要的是版本是否存在于 GAC 中。

      如果你没有预编译你的任务,那么你将需要两个地方的dll,framework 2.0文件夹和GAC,因为SSIS会先编译脚本任务(所以它需要framework 2.0文件夹中的引用)然后运行任务(参考将从 GAC 加载)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-03-21
        • 2010-11-14
        • 1970-01-01
        • 2011-11-11
        • 1970-01-01
        • 1970-01-01
        • 2018-05-03
        • 1970-01-01
        相关资源
        最近更新 更多