为什么 BIML ScriptTask 会失败,直到我在 VS 中打开脚本并保存包

Why does the BIML ScriptTask fail until I open the script in VS and save the package

我有这个 BIML 脚本,它创建了一个主包和子包。子包中有一个 ScriptTask,它将父包变量的值映射到子包变量。当我在 SSIS(Visual Studio 2015,目标 Sql Server 2014)中生成包时,它们生成良好。如果我 运行 主包,子包失败并出现此错误:

DTS Script Task has encountered an exception in user code:
Project name:  ST_GetJobLogIdHere
Exception has been thrown by the target of an invocation.

at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
at Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTATaskScriptingEngine.ExecuteScript()

当我在child中打开ScriptTask,然后再次关闭它时,包是脏的,所以我保存了它。之后,运行安装包正常工作。

这是 BIML 脚本:

<Biml xmlns="http://schemas.varigence.com/biml.xsd">

    <ScriptProjects>
        <ScriptTaskProject ProjectCoreName="ST_GetJobLogId" Name="ST_GetJobLogIdScript" VstaMajorVersion="0">
            <ReadOnlyVariables>
                <Variable Namespace="User" VariableName="vMasterJobLogId" DataType="Int32" />
            </ReadOnlyVariables>
            <ReadWriteVariables>
                <Variable Namespace="User" VariableName="vJobLogId" DataType="Int32" />
            </ReadWriteVariables>
            <AssemblyReferences>
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS" />
                <AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask" />
                <AssemblyReference AssemblyPath="System" />
                <AssemblyReference AssemblyPath="System.Data" />
                <AssemblyReference AssemblyPath="System.Windows.Forms" />
                <AssemblyReference AssemblyPath="System.Xml" />
            </AssemblyReferences>
            <Files>
                <File Path="AssemblyInfo.cs" BuildAction="Compile">
                    using System.Reflection;

                    [assembly: AssemblyTitle("ST_GetJobLogId")]
                    [assembly: AssemblyDescription("")]
                    [assembly: AssemblyConfiguration("")]
                    [assembly: AssemblyCompany("")]
                    [assembly: AssemblyProduct("ST_GetJobLogId")]
                    [assembly: AssemblyCopyright("Copyright @ BMI 2017")]
                    [assembly: AssemblyTrademark("")]
                    [assembly: AssemblyCulture("")]
                    [assembly: AssemblyVersion("1.0.*")]
                </File>
                <File Path="ScriptMain.cs" BuildAction="Compile">
                    using Microsoft.SqlServer.Dts.Runtime;

                    namespace ST_GetJobLogId
                    {
                        [Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPoint]
                        public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
                        {
                            public void Main()
                            {
                                int jobLogId = (int)Dts.Variables["User::vMasterJobLogId"].Value;
                                if (jobLogId != 0)
                                    Dts.Variables["User::vJobLogId"].Value = jobLogId;
                                Dts.TaskResult = (int)ScriptResults.Success;
                            }
                            enum ScriptResults
                            {
                                Success = DTSExecResult.Success,
                                Failure = DTSExecResult.Failure
                            };
                        }
                    }
                </File>
            </Files>
        </ScriptTaskProject>
    </ScriptProjects>

    <Packages>
        <Package Name="Master" ProtectionLevel="EncryptSensitiveWithUserKey">
            <Variables>
                <Variable Name="vMasterJobLogId" DataType="Int32">1</Variable>
            </Variables>
            <Tasks>
                <ExecutePackage Name="PKG - Execute FixMe">
                    <ExternalProjectPackage Package="FixMe.dtsx" />
                </ExecutePackage>
            </Tasks>
        </Package>
        <Package Name="FixMe" ProtectionLevel="EncryptSensitiveWithUserKey">
            <Variables>
                <Variable Name="vJobLogId" DataType="Int32">0</Variable>
            </Variables>
            <Tasks>
                <Script Name="SCR - Get vJobLogId from parent vMasterJobLogId" ProjectCoreName="ST_GetJobLogIdHere" >
                    <ScriptTaskProjectReference ScriptTaskProjectName="ST_GetJobLogIdScript" />
                </Script>
            </Tasks>
        </Package>
    </Packages>

</Biml>

我错过了什么?为什么在我手动打开代码 window 之前包会失败? 在此先感谢您的帮助, 西蒙

阅读上面的评论以澄清问题。

原来BIML Express/BidsHelper in Visual Studio 2015不知道在Project属性中设置了SQL Server的哪个目标版本

解决方案是安装 VS2013 / SSDT 2014 和 BIML Express for VS2013 以便能够正确生成 SSIS 2014 包。

VS 2015/SSDT/BIML Express 只会为 SQL Server SSIS 2016 包生成脚本任务。

感谢比尔的回答。

当您将 VS2017 与 SSDT 一起使用并安装最新(预览)版本的 BimlExpress 2018 时,它可以正常工作。

VS2015也有同样的问题,升级到新版本的BimlExpress解决了。