我已经使用一个非常基本的示例(下面概述)来实现这一点,我想看看其他 SOers 是否有执行我正在尝试的操作的经验...在 SSIS 2005 的脚本任务中使用 3.5 框架程序集。
我'我们基本上遵循了此处找到的页面。 ..除了我在 Visual Studio 2008 中以 3.5 框架为目标。
-
编写/编译代码(以 3.5 框架为目标)只是一些简单的 Linq,以便我使用大于 2.0 的框架功能
使用系统;
使用 System.Collections.Generic;
使用系统文本;
使用 System.Linq;
命名空间扩展
{
公共课扩展
{
公共字符串 GetValue ()
{
/*
测试 Linq 以“证明”我们没有与
2.0框架。
我知道这段代码可以改进,但请耐心等待......
这是一次性代码只是为了测试这个概念
*/
string[] teststring = 新字符串[3];
teststring[0] = "命名扩展";
字符串 returnString = String.Empty;
var s = teststring.Where(x => x.ToString() == "named Extend");
foreach(var x in s)
{
returnString = x.ToString();
}
return“通过自定义库扩展脚本任务”+ returnString;
}
}
}
- 给它一个强名称密钥
- 使用 gacutil 将程序集添加到 GAC
- 已复制程序集到 C:\Windows\Microsoft.NET\Framework\v2.0.50727 文件夹...dev
计算机正在运行 Windows 7
- 创建了一个脚本任务并添加了对程序集的引用
在脚本任务中
Dim x As New Extend()
MsgBox(x.GetValue.ToString())
它工作正常,因为当我运行 SSIS 项目时,我收到一个带有文本的消息框
“通过名为 Extend 的自定义库扩展脚本任务”
所以...我的问题是,当我尝试做更复杂的事情时,SSIS 项目/脚本任务是否仍然有效...特别是当我调用我的(尚未编写的)程序集时使用 LinqToEntities?
对我来说这似乎很奇怪,我必须将文件复制到 Framework 2.0 文件夹并将其添加到 GAC...但也许这只是一个奇怪的 SSIS 要求...我知道我无法在脚本任务中添加引用除非该程序集位于 Framework 2.0 文件夹中...
I've got this to work using a very basic example(outlined below) and I want to see if other SOers have experience doing what I'm attempting...using a 3.5 framework assembly in a Script Task in SSIS 2005.
I've basically followed the page found here... except I targeted the 3.5 framework while in Visual Studio 2008.
-
Write/compile your code (targeted the 3.5 framework) Just some simple Linq so that I'm using a greater than 2.0 framework feature
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;
}
}
}
- Gave it a Strong Name key
- Added the assembly to the GAC using gacutil
- Copied the assembly to the C:\Windows\Microsoft.NET\Framework\v2.0.50727 folder...dev
machine is running Windows 7
- Created a Script Task and added a reference to the assembly
-
In the Script Task
Dim x As New Extend()
MsgBox(x.GetValue.ToString())
It works OK cuz when I run the SSIS project I get back a message box with the text
"Extending Script Task through a custom library named Extend"
So...my question is will the SSIS project/Script Task still work when I try to do more sophisticated stuff...especially when I call my (yet to be written) assembly that uses LinqToEntities?
It seems strange to me that I have to copy the file to the Framework 2.0 folder AND add it to the GAC...but maybe it's just a weird SSIS requirement...I know I can't add the reference in the Script Task unless that assembly's in the Framework 2.0 folder...
发布评论
评论(2)
哇,我知道这个答案来晚了。但我认为它不会产生任何问题,因为 SSIS 会在运行时从 GAC 加载程序集,只要机器上有 .net Framework 2.0 和 3.5,代码就会在运行时运行。
Framework 2.0中的文件仅用于开发IDE和预编译脚本任务/组件。在运行时,重要的是版本是否存在于 GAC 中。
如果您没有预编译您的任务,那么您将在两个地方需要该dll,framework 2.0文件夹和GAC,因为SSIS将首先编译脚本任务(因此它需要framework 2.0文件夹中的引用),然后运行该任务(参考将从 GAC 加载)。
wow, i know this answer is coming late. but i think it does not create any problems because SSIS will load the assembly at runtime from GAC, as long as you have .net framework 2.0 AND 3.5 on the machine, the code will work at runtime.
The file in framework 2.0 is only used for development ide and to precompile the script task/component. during runtime, all that matters is if the version exists in GAC.
If you did not precompile your tasks, then you will need the dll in two places, the framework 2.0 folder AND GAC, because SSIS will compile the script task first (so it needs the reference in framework 2.0 folder) and then run the task (reference will be loaded from GAC).
为了安全起见,你可以尝试改变编译框架。
在 C# 中
项目资源管理器 >属性>目标框架下拉列表
如何查找 SSIS 2008 R2 中使用的 .NET 框架版本包?
在VB中
菜单>项目>>项目属性,
单击“编译”选项卡,然后单击“高级编译选项”并更改“目标框架”下拉列表
http://www.demiliani.com/blog/archive/2007/08/24/6430.aspx
To be safe, you could try changing the compiling framework.
In C#
Project Explorer > Properties > Target Framework dropdown
How do I find the .NET framework version used in an SSIS 2008 R2 package?
In VB
Menu > Project > Project properties,
click on the Compile tab, then click on the Advanced Compile Options and change the Target Framework dropdown
http://www.demiliani.com/blog/archive/2007/08/24/6430.aspx