Creating Script Task Projects inline

gravatar

Scott Currie

Biml supports the creation of a script project that can be referenced from multiple tasks/components. But sometimes, when writing automation code, you'd prefer to create the script projects inline with the project. This snippet shows how to do that for Script Tasks.

published 05.03.13

last updated 05.03.13


Share

                            


<Biml xmlns="http://schemas.varigence.com/biml.xsd">
	<Packages>
		<Package Name="Package2" ConstraintMode="Parallel" ProtectionLevel="EncryptSensitiveWithUserKey">
			<Tasks>
				<Script ProjectCoreName="ST_232fecafb70a4e8a904cc21f8870eed0" Name="ScriptTask 1">
					<ScriptTaskProject>
						<ScriptTaskProject ProjectCoreName="ST_c41ad4bf47544c49ad46f4440163feae" Name="TaskScriptProject1">
							<AssemblyReferences>
								<AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" />
								<AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" />
								<AssemblyReference AssemblyPath="System.dll" />
								<AssemblyReference AssemblyPath="System.AddIn.dll" />
								<AssemblyReference AssemblyPath="System.Data.dll" />
								<AssemblyReference AssemblyPath="System.Windows.Forms.dll" />
								<AssemblyReference AssemblyPath="System.Xml.dll" />
							</AssemblyReferences>
							<Files>
								<File Path="AssemblyInfo.cs">
									using System.Reflection;
									using System.Runtime.CompilerServices;

									//
									// General Information about an assembly is controlled through the following
									// set of attributes. Change these attribute values to modify the information
									// associated with an assembly.
									//
									[assembly: AssemblyTitle("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
									[assembly: AssemblyDescription("")]
									[assembly: AssemblyConfiguration("")]
									[assembly: AssemblyCompany("Varigence")]
									[assembly: AssemblyProduct("ST_c41ad4bf47544c49ad46f4440163feae.csproj")]
									[assembly: AssemblyCopyright("Copyright @ Varigence 2013")]
									[assembly: AssemblyTrademark("")]
									[assembly: AssemblyCulture("")]
									//
									// Version information for an assembly consists of the following four values:
									//
									//      Major Version
									//      Minor Version
									//      Build Number
									//      Revision
									//
									// You can specify all the values or you can default the Revision and Build Numbers
									// by using the '*' as shown below:

									[assembly: AssemblyVersion("1.0.*")]
								</File>
								<File Path="ScriptMain.cs">
									using System;
									using System.Data;
									using Microsoft.SqlServer.Dts.Runtime;
									using System.Windows.Forms;

									// if SSIS2012, use the following line:
									[Microsoft.SqlServer.Dts.Tasks.ScriptTask.SSISScriptTaskEntryPointAttribute]
									
									// if earlier version, use the next line instead of the above line:
									// [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")]
									public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
									{
									enum ScriptResults
									{
									Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
									Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
									};

									public void Main()
									{
									Dts.TaskResult = (int)ScriptResults.Success;
									}
									}
								</File>
							</Files>
						</ScriptTaskProject>
					</ScriptTaskProject>
				</Script>
			</Tasks>
		</Package>
	</Packages>
</Biml>
                        

Biml supports the creation of a script project that can be referenced from multiple tasks/components. But sometimes, when writing automation code, you'd prefer to create the script projects inline with the project. This snippet shows how to do that for Script Tasks.

Essentially, all you need to do is embed the contents of the script project that you would normally put in a separate ScriptProject root node directly under the ScriptProject node of the ScriptProject task.

You are not authorized to comment. A verification email has been sent to your email address. Please verify your account.

Comments

gravatar

Jim2

9:01pm 01.24.14

I have multiple version of .Net Framework. After generating a package from this script above, I had to change the Target Framework manually from 2.0 to 3.5. Is there a way to change the Framework version in the Biml script?

Thanks, Jim Jao

gravatar

Ethan0

2:40pm 07.10.17

How would I go about writing VB.net code and specifying that this is what it is?

Thanks!

gravatar

Corban

1:18pm 08.18.17

I spent 3 hours before realising I had the same problem as Jim2 below and had to manually change the framework to 3.5. Would definitely appreciate a script solution to this. Or is there a way to change the default framework in SSDT or BIDS?

gravatar

Lonnie

2:50am 12.12.17

I cannot add some of the conditional operators in the script task. Say something like this bool test = 1 <= 2; or boot test2 = true && true; it does not seem to like the operators <= or && there may be others. Every time I try to use these operators I usually get an error at the begging of the code that says something about names cannot start with '=' Do you know of any ways to get around this. Has anyone else come up against this? Has anyone else figured out how to get around this?

gravatar

Lonnie

2:09pm 12.12.17

I figured this out I needed to replace the < with @lt; and the & with @amp;

gravatar

Lonnie

2:12pm 12.12.17

sorry < and &

gravatar

Lonnie

2:12pm 12.12.17

& lt; & amp;