SSIS - How to Copy Variables From a SSIS Package to Another SSIS Package


As we know that we can copy Connection Managers, Tasks and Transformations between SSIS Packages but how would we copy the variables from a SSIS Package to another SSIS Package. This can save us time while development in cases where we need to create variables with same name and data types.


We can not click on Variable/s to copy and then go to second SSIS Package and paste it. I have created two SSIS Packages Package1 and Package2. The Package1 has two variables as shown Variable1 and Variable2 as shown below

Fig 1: Variables in SSIS Package1

To copy variables we have to go to the SSIS Package code and then copy the required variable code and paste in Package2 xml file. Before you copy and paste the variable from the code, make sure you have saved the copy of your SSIS Packages in case you mess up with SSIS Package code;)

Right Click on Package1 and Click on View Code and then copy the part as shown below
Fig 2: Package1 View Code 

Copy the code as shown below
Fig 3: Copy Variables code from Package1

Go to Package2. Right click and then Click on View Code and then paste the code we have copied in above step as shown below
Fig 4: Paste Variable's code in Package2

Save the file by using Ctrl+S or by using Save button. Once the file is saved, we will see that two variables are created in Package2 as shown below
Fig 5: Variables copied to Package2