private void DeploySingleFile(object state)
        {
            try
            {
                var project = state as Project;

                var variables = new SsdtVariableProvider().GetVariables(project.FullName);

                var settings = Config.Configuration.GetSettings(project);

                var filename = GetSelectedSolutionExplorerFileName();

                if (String.IsNullOrEmpty(filename))
                {
                    OutputWindowMessage.WriteMessage("Couldn't GetConfig filename");
                    return;
                }

                if (!filename.EndsWith(".sql"))
                {
                    OutputWindowMessage.WriteMessage("Single file deploy only works with .sql files - boo hoo hoo");
                    return;
                }

                var procname = ScriptProperties.GetScriptDetail(File.ReadAllText(filename)).Name;

                if (string.IsNullOrEmpty(procname))
                {
                    OutputWindowMessage.WriteMessage("Couldn't GetConfig proc name - boo hoo hoo");
                    return;
                }

                var fileContents = GetFileContents(filename);

                foreach (SqlCmdVariable v in variables)
                {
                    fileContents = fileContents.Replace(v.Name, v.Value);
                }

                if (!DtcAvailable())
                {
                    OutputWindowMessage.WriteMessage("Unable to deploy file, deploy uses msdtc to protect changes. Please ensure the service is enabled and running");
                    return;
                }

                using (var scope = new TransactionScope())
                {
                    try
                    {
                        var script = DeploymentScriptGenerator.BuildDeploy(fileContents);
                        var batches = script.Split( new string[] {"\r\nGO\r\n"}, StringSplitOptions.RemoveEmptyEntries);
                        foreach (var batch in batches)
                        {
                            new SqlGateway(settings.ConnectionString).Execute(batch);
                        }

                        scope.Complete();

                        OutputWindowMessage.WriteMessage(string.Format("Deployed File: {0}\r\n", filename));
                    }
                    catch (NullReferenceException)
                    {
                        OutputWindowMessage.WriteMessage(string.Format("Unable to deploy file {0}\r\n", filename));
                    }
                    catch (Exception ex)
                    {
                        OutputWindowMessage.WriteMessage(string.Format("Unable to deploy file {0} error : {1}\r\n",
                            filename, ex.Message));
                    }
                }
            }
            catch (Exception e)
            {
                OutputWindowMessage.WriteMessage("Deploying file Failed: " + e.Message);
            }
        }
        private void WriteDeployFile(string projectFile, string procName, string procFile, string outputDir)
        {
            var script = GetFileContents(procFile);
            if (string.IsNullOrEmpty(script))
            {
                OutputWindowMessage.WriteMessage("Could not read script file: " + procFile);
                return;
            }

            var variables = new SsdtVariableProvider().GetVariables(projectFile);

            foreach (SqlCmdVariable v in variables)
            {
                script = script.Replace(v.Name, v.Value);
            }

            var outputScript = new StringBuilder();
            outputScript.AppendFormat(DeploymentScriptGenerator.BuildDeploy(script));

            string outputScriptPath = Path.Combine(outputDir,
                string.Format("{0}.sql", DeploymentScriptGenerator.GetLastPartOfName(procName)));

            try
            {
                WriteFileContents(outputScriptPath, outputScript.ToString());
                OutputWindowMessage.WriteMessage("Written file: " + outputScriptPath);
            }
            catch (Exception e)
            {
                OutputWindowMessage.WriteMessage("Could not write file: " + outputScriptPath + " - error: " + e.Message);
            }
        }