private bool StartDevenvAndWait(VisualStudioInfo vsInfo, ParsedPath solutionFile) { // Now try and start devenv Process process = null; // Clear undocumented MS build environment variables that will confuse VS if set Environment.SetEnvironmentVariable("COMPLUS_INSTALLROOT", ""); Environment.SetEnvironmentVariable("COMPLUS_VERSION", ""); try { if (this.Verbose) { Output.Message(MessageImportance.Low, ScaffoldResources.StartingVS); } ProcessStartInfo startInfo = new ProcessStartInfo( vsInfo.DevEnvExe, "\"" + solutionFile + "\" \"" + this.ScriptPath + "\""); startInfo.WorkingDirectory = solutionFile.VolumeAndDirectory; startInfo.UseShellExecute = false; process = Process.Start(startInfo); } catch (Win32Exception e) { Output.Error(ScaffoldResources.UnableToStartVS, solutionFile, e.Message); return(false); } // Devenv has started. Wait for it to exit. if (process != null) { if (this.Verbose && this.Wait) { Output.Message(MessageImportance.Low, ScaffoldResources.WaitingForVS); } // At this point we free the server/parent scaffold process so that it can // exit and return control of the console to the user. Any logging after this // point might silently fail if the remote build engine decides to away, but that's OK. Output.Outputter.OutputCustomEvent(new RemoteOutputEventArgs(true)); process.WaitForExit(); process.Close(); process = null; } else { Output.Error(ScaffoldResources.VSDidNotStart); return(false); } return(true); }
private void RealExecute() { // At this point, we need a program (the default argument) if (this.ScriptPath == null) { Output.Error(ScaffoldResources.NoSourceSpecified); return; } // Fully qualify the program this.ScriptPath = this.ScriptPath.MakeFullPath(); if (this.ScriptPath.File == String.Empty) { Output.Error(ScaffoldResources.NoEmptyFilename); return; } else if (this.ScriptPath.HasWildcards) { Output.Error(ScaffoldResources.NoSourceWildcards); return; } else if (this._Language == ScriptLanguage.Unknown) { Output.Error(ScaffoldResources.FileNameMustEndIn); return; } // TODO-johnls-12/15/2007: More project types coming soon...? if (this._Language != ScriptLanguage.CSharp) { Output.Error(ScaffoldResources.OnlyCSharpSourcesSupported); return; } // Look for installed VS versions get information about them IList <VisualStudioInfo> vsInfos = VisualStudioInfo.GetInstalledVisualStudios(); if (vsInfos.Count == 0) { // Must have at least one supported version of Visual Studio installed Output.Error(ScaffoldResources.VSNotInstalled(StringUtility.Join(", ", ScriptInfo.ValidVisualStudioVersions))); return; } // Get list of installed runtimes. IList <RuntimeInfo> runtimeInfos = RuntimeInfo.GetInstalledRuntimes(); // If VS is installed we have at least one runtime... if (runtimeInfos.Count == 0) { Output.Error(ScaffoldResources.RuntimeNotInstalled(StringUtility.Join(", ", ScriptInfo.ValidRuntimeVersions))); return; } ScriptInfo scriptInfo = null; VisualStudioInfo vsInfo; RuntimeInfo runtimeInfo; if (File.Exists(this.ScriptPath)) { try { // Grab script information from script scriptInfo = ScriptInfo.GetScriptInfo(this.ScriptPath); } catch (ScriptInfoException e) { Output.Error(e.Message); return; } // Validate that VS/CLR/FX versions installed runtimeInfo = ((List <RuntimeInfo>)runtimeInfos).Find( v => (scriptInfo.ClrVersion == v.ClrVersion && scriptInfo.FxVersion == v.FxVersion)); vsInfo = ((List <VisualStudioInfo>)vsInfos).Find( v => (scriptInfo.VsVersion == v.VsVersion)); if (runtimeInfo == null || vsInfo == null) { Output.Error(ScaffoldResources.ScriptsRequiredClrFxAndVsNotInstalled(scriptInfo.ClrVersion, scriptInfo.FxVersion, scriptInfo.VsVersion)); return; } } else { vsInfo = vsInfos[0]; runtimeInfo = runtimeInfos[0]; scriptInfo = new ScriptInfo(vsInfo.VsVersion, runtimeInfo.ClrVersion, runtimeInfo.FxVersion, new List <string>()); // Go grab references from the csc.rsp file and add CodeRunner.dll and ToolBelt.dll // in the same directory as Scaffold.exe. scriptInfo.References.AddRange(GrabSystemRspFileReferences(runtimeInfo.FxInstallPath.Append("csc.rsp", PathType.File), runtimeInfo)); scriptInfo.References.Add(@"$(CodeRunnerPath)CodeRunner.dll"); scriptInfo.References.Add(@"$(CodeRunnerPath)ToolBelt.dll"); } ParsedPath projectDir = CreateTempDirectory(); if (!CreateProjectFiles(scriptInfo, vsInfo, runtimeInfo, projectDir)) { return; } StartDevenvAndWait(vsInfos[0], new ParsedPath( projectDir.VolumeAndDirectory + this.ScriptPath.File + ".sln", PathType.File)); DeleteDirectory(projectDir); }
private bool CreateProjectFiles(ScriptInfo scriptInfo, VisualStudioInfo vsInfo, RuntimeInfo runtimeInfo, ParsedPath projectDir) { if (!Directory.Exists(this.ScriptPath.VolumeAndDirectory)) { Output.Error(ScaffoldResources.DirectoryDoesNotExist(this.ScriptPath.VolumeAndDirectory)); return(false); } Dictionary <string, string> dict = new Dictionary <string, string>(); dict.Add("AssemblyName", this.ScriptPath.File); dict.Add("SourceDirectory", this.ScriptPath.VolumeAndDirectory); dict.Add("SourceName", this.ScriptPath.FileAndExtension); dict.Add("ProjectGuid", Guid.NewGuid().ToString().ToUpper()); dict.Add("ProjectTypeExt", ScriptEnvironment.GetExtensionFromScaffoldLanguage(this.language)); dict.Add("ProductVersion", String.Format("{0}.{1}", vsInfo.VsVersion, vsInfo.VsBuild)); dict.Add("ToolsVersion", String.Format(" ToolsVersion=\"{0}\" ", scriptInfo.FxVersion)); dict.Add("TargetFrameworkVersion", "v" + scriptInfo.FxVersion); dict.Add("ScriptVsVersion", scriptInfo.VsVersion); dict.Add("ScriptClrVersion", scriptInfo.ClrVersion); dict.Add("ScriptFxVersion", scriptInfo.FxVersion); switch (scriptInfo.VsVersion) { case "10.0": dict.Add("SolutionFileVersion", "11.00"); dict.Add("VSName", "2010"); break; case "9.0": dict.Add("SolutionFileVersion", "10.00"); dict.Add("VSName", "2008"); break; case "8.0": dict.Add("ToolsVersion", ""); dict.Add("SolutionFileVersion", "9.00"); dict.Add("VSName", "2005"); break; } dict.Add("ScriptReferencesComment", CreateCommentSnippetFromReferences(scriptInfo.References)); dict.Add("ReferenceXmlSnippet", CreateXmlSnippetFromReferences(ScriptInfo.GetFullScriptReferencesPaths(scriptPath, scriptInfo, runtimeInfo))); string tagProgramFile = this.ScriptTemplate; if (tagProgramFile == null || !File.Exists(tagProgramFile)) { tagProgramFile = GetResource("CodeRunner.Templates.Template.cs"); } string sourceFile = StringUtility.ReplaceTags(tagProgramFile, "%", "%", dict); string tagCsProjFile = GetResource("CodeRunner.Templates.Template.csproj"); string csProjFile = StringUtility.ReplaceTags(tagCsProjFile, "%", "%", dict); string tagCsProjUserFile = GetResource("CodeRunner.Templates.Template.csproj.user"); string csProjUserFile = StringUtility.ReplaceTags(tagCsProjUserFile, "%", "%", dict); string tagSlnFile = GetResource("CodeRunner.Templates.Template.sln"); string slnFile = StringUtility.ReplaceTags(tagSlnFile, "%", "%", dict); try { if (!File.Exists(this.ScriptPath)) { CreateFile(this.ScriptPath, sourceFile); } CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".csproj", csProjFile); CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".csproj.user", csProjUserFile); CreateFile(projectDir.VolumeAndDirectory + this.ScriptPath.File + ".sln", slnFile); } catch (IOException exp) { Output.Error("{0}", exp.Message); return(false); } return(true); }