Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As you've noticed, the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.vstahosting.ivstahelper%28v=sql.110%29" rel="nofollow">VSTA helper methods</a> you could use in 2008 were moved/removed in 2012. It is still possible to do, but the code has changed.</p> <p>The easiest thing to do is load an existing project using <a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.vstahosting.ivstahelper.loadprojectfromfolder" rel="nofollow">VstaHelper.LoadProjectFromFolder</a>().</p> <p>If you want to dynamically add script files, see the snippet below. There are two main things you need to keep in mind:</p> <p>The ScriptingEngine and VstaHelper classes represent VSTA itself. This is where you’d create the project, and add new files. You cannot remove or replace an existing file directly here. When you call SaveProjecToStorage(), it's like closing the VSTA window … it saves the project and compiled binary to the ScriptTask. </p> <p>ScriptTask.ScriptStorage allows you to directly manipulate the source file contents. From here, you can modify the content of a file. </p> <p>The following code snippet should help you get started.</p> <pre><code>static void Main(string[] args) { // 1. Create new package, and add a script task var pkg = new Package(); var exec = pkg.Executables.Add("STOCK:ScriptTask"); var th = (TaskHost)exec; th.Name = "Script Task"; th.Description = "This is a Script Task"; var task = (ScriptTask)th.InnerObject; // 2. Set the script language - "CSharp" or "VisualBasic" task.ScriptLanguage = VSTAScriptLanguages.GetDisplayName("CSharp"); // 3. Set any variables used by the script //task.ReadWriteVariables = "User::Var1, User::Var2"; // 4. Create a new project from the template located in the default path task.ScriptingEngine.VstaHelper.LoadNewProject(task.ProjectTemplatePath, null, "MyScriptProject"); // 5. Initialize the designer project, add a new code file, and build //task.ScriptingEngine.VstaHelper.Initalize("", true); //task.ScriptingEngine.VstaHelper.AddFileToProject("XX.cs", "FileContents"); //task.ScriptingEngine.VstaHelper.Build(""); // 6. Persist the VSTA project + binary to the task if (!task.ScriptingEngine.SaveProjectToStorage()) { throw new Exception("Save failed"); } // 7. Use the following code to replace the ScriptMain contents var contents = File.ReadAllText("path to file"); var scriptFile = task.ScriptStorage.ScriptFiles["ScriptMain.cs"] = new VSTAScriptProjectStorage.VSTAScriptFile(VSTAScriptProjectStorage.Encoding.UTF8, contents); // 8. Reload the script project, build and save task.ScriptingEngine.LoadProjectFromStorage(); task.ScriptingEngine.VstaHelper.Build(""); // 9. Persist the VSTA project + binary to the task if (!task.ScriptingEngine.SaveProjectToStorage()) { throw new Exception("Save failed"); } // 10. Cleanup task.ScriptingEngine.DisposeVstaHelper(); // 11. Save string xml; pkg.SaveToXML(out xml, null); File.WriteAllText(@"c:\temp\package.dtsx", xml); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload