public void Startup() { //TODO: Make sure the config is valid! if (ProjectPath.Contains("\\")) { ProjectName = ProjectPath.Substring(ProjectPath.LastIndexOf("\\") + 1); } else { ProjectName = ProjectPath; } ProjectName = ProjectName.Replace(".csproj", string.Empty).Replace(".vbproj", string.Empty); _publishDir = Path.Combine(Directory.GetCurrentDirectory(), PublishDirectory ?? "SpecsForMvc.TestSite"); _intermediateDir = Path.Combine(Directory.GetCurrentDirectory(), IntermediateDirectory ?? "SpecsForMvc.TempIntermediateDir"); var properties = new Dictionary <string, string> { { "DeployOnBuild", "true" }, { "DeployTarget", "Package" }, { "_PackageTempDir", "\"" + _publishDir + "\"" }, //If you think this looks bad, that's because it does. What this //actually outputs looks like: "path\to\whatever\\" //The backslash on the end has to be escaped, otherwise msbuild.exe //will interpret it as escaping the final quote, which is incorrect. { "BaseIntermediateOutputPath", "\"" + _intermediateDir + "\\\\\"" }, { "AutoParameterizationWebConfigConnectionStrings", "false" }, { "Platform", Platform ?? "AnyCPU" }, //Needed for Post-Build events that reference the SolutionDir macro/property. { "SolutionDir", @"""" + Path.GetDirectoryName(SolutionPath) + "\\\\\"" } }; if (!string.IsNullOrEmpty(Configuration)) { properties.Add("Configuration", Configuration); } if (!string.IsNullOrEmpty(OutputPath)) { properties.Add("OutputPath", "\"" + OutputPath + "\\\\\""); } PublishSite(properties); StartIISExpress(); }
public override bool Execute() { Console.WriteLine("Environment {0}", Environment); Console.WriteLine("Server {0}", Server); Console.WriteLine("Port {0}", Port); Console.WriteLine("ProjectPath {0}", ProjectPath); Console.WriteLine("OutputPath {0}", OutputPath); Project project; EnvironmentSettingsManager environmentManager; DeploymentResults results; DeploymentPackage package; bool result = false; //Create a temporary folder for the K2 project files string tempPath = Path.GetTempPath().Trim('\\').Trim('/'); string k2DeployFolder = tempPath + @"\K2Deploy"; DeleteDirectory(k2DeployFolder); try { Console.WriteLine("\n\n\n************** BEGIN PACKAGE ******************\n"); //Check parameters if (!ProjectPath.EndsWith(".k2proj")) { throw new ArgumentException("ProjectPath must end with .k2proj"); } //Create a temporary folder for the code string projectFolder = ProjectPath.Substring(0, ProjectPath.LastIndexOf('\\')); Console.WriteLine("\nProject Folder: " + projectFolder); //Copy the files to the temp folder Console.WriteLine("\nCreating temporary folder: " + k2DeployFolder); CopyFolder(projectFolder, k2DeployFolder); //Ensure we have access to all the files. Console.WriteLine("\nSetting writable permissions for folder: " + tempPath); bool success = SetAcl(k2DeployFolder, "F", true); if (!success) { throw new Exception("Failed to set ACLs on folder " + tempPath); } //Ensure the feils are all writable SetWritable(k2DeployFolder); //Load the project file string newProjectFile = k2DeployFolder + @"\" + ProjectPath.Substring(1 + ProjectPath.LastIndexOf('\\')); Console.WriteLine("\nLoading project file: " + newProjectFile); project = new Project(); project.Load(newProjectFile); // Compile the K2 Project Console.WriteLine("\nCompiling project file: " + newProjectFile); results = project.Compile(); //Grab the deployment package environmentManager = GetEnvironmentManager(); package = GetDeploymentPackage(project, environmentManager); Console.WriteLine("\nSetting writable permissions for folder: " + OutputPath); success = SetAcl(OutputPath, "F", true); if (!success) { throw new Exception("Failed to set ACLs on folder " + OutputPath); } //Ensure the feils are all writable SetWritable(OutputPath); Console.WriteLine("\nSaving deployment package to folder: " + OutputPath); package.Save(OutputPath, "K2DeploymentPackage"); result = true; //////Console.WriteLine("\nExecuting deployment package..."); //////results = package.Execute(); //////Console.WriteLine("\nSuccessful = " + results); //////result = results.Successful; //////Console.WriteLine("\nSuccessful = " + result); } catch (Exception ex) { Console.Write(ex.Message); throw; } finally { Console.WriteLine("\nDeleting k2DeployFolder " + k2DeployFolder); DeleteDirectory(k2DeployFolder); } Console.WriteLine("\n\n\n************** END PACKAGE ******************\n\n\n"); return(result); }