2

I have an SSIS (2012) package which has 16 (c#) script tasks so far and there will be more. I am frustrated at having to basically copy code in for each component. I have a .cs file which I add to each script task but as this is copied into the dtsx if I update the 'common' code I have to modify every other component which has contains it.
I have tried to create an external assembly so I can put it into the GAC and avoid this stupidity but I cannot get it to work - the problem seems to be that my common code requires a reference to the InheritedVariableDispenser to work. I have tried adding references to Microsoft.SqlServer.Dts.Runtime in the external assembly in order to handle this but as I say, this fails.
A partial solution would be to create a customised script task with my common routines pre-loaded but this doesn't seem possible either.
My last alternative option is to write a program which acts directly upon the dtsx file and modifies the xml to update all the section which incorporate the common code. While this appeals to the hacker in me it does some like a little too much work and a bit 'iffy' - it would only solve the update problem while still not allowing re-use in another package.
If anybody knows how to re-use code which references SSIS objects I would be most interested!

4

1 回答 1

0

您的通用代码是否真的需要访问整个VariableDispenser对象,还是只需要访问变量?

如果您只需要变量本身,那么我建议将公共代码放在外部程序集中。使用脚本组件来消费通用代码功能;例如:

var foo = new MyLogic();
Dts.Variables["TransmogrifyResult"].Value = foo.Transmogrify(Dts.Variables["AnInput"].Value, Dts.Variables["AnotherInput"].Value);

如果您绝对必须有权访问它VariableDispenser本身,则 MSDN VariableDispenser文档会警告您实际上可能需要使用IDTSVa​​riableDispenser100

于 2012-11-14T23:28:23.977 回答