public void Load(DotNetProjectConfiguration config) { VBCompilerParameters c = (VBCompilerParameters)config.CompilationParameters; this.config = config; cmbOptimize.Active = c.Optimize ? 0 : 1; cmbDefineDEBUG.Active = c.DefineDebug ? 0 : 1; cmbDefineTRACE.Active = c.DefineTrace ? 0 : 1; cmbEnableWarnings.Active = c.WarningsDisabled ? 1 : 0; cmbGenerateXmlDocumentation.Active = string.IsNullOrEmpty(c.DocumentationFile) ? 1 : 0; cmbRemoveIntegerChecks.Active = c.RemoveIntegerChecks ? 0 : 1; switch (c.DebugType.ToLower()) { case "none": cmbDebugType.Active = 0; break; case "pdbonly": cmbDebugType.Active = 1; break; case "full": default: cmbDebugType.Active = 2; break; } txtDontWarnAbout.Text = c.NoWarn; txtDefineConstants.Text = c.DefineConstants; txtTreatAsError.Text = c.WarningsAsErrors; txtAdditionalArguments.Text = c.AdditionalParameters; }
protected override DotNetCompilerParameters OnCreateCompilationParameters(DotNetProjectConfiguration config, ConfigurationKind kind) { var pars = new VBCompilerParameters(); if (kind == ConfigurationKind.Debug) { pars.AddDefineSymbol("DEBUG"); } else if (kind == ConfigurationKind.Release) { pars.Optimize = true; } return(pars); }
public void StorePanelContents() { VBCompilerParameters c = (VBCompilerParameters)config.CompilationParameters; c.Optimize = cmbOptimize.Active == 0; c.DefineDebug = cmbDefineDEBUG.Active == 0; c.DefineTrace = cmbDefineTRACE.Active == 0; c.WarningsDisabled = cmbEnableWarnings.Active == 1; c.DocumentationFile = cmbGenerateXmlDocumentation.Active == 0 ? config.ParentItem.Name + ".xml" : string.Empty; c.RemoveIntegerChecks = cmbRemoveIntegerChecks.Active == 0; c.DebugType = cmbDebugType.ActiveText; c.NoWarn = txtDontWarnAbout.Text; c.DefineConstants = txtDefineConstants.Text; c.WarningsAsErrors = txtTreatAsError.Text; c.AdditionalParameters = txtAdditionalArguments.Text; }
protected override DotNetCompilerParameters OnCreateCompilationParameters (DotNetProjectConfiguration config, ConfigurationKind kind) { var pars = new VBCompilerParameters (); if (kind == ConfigurationKind.Debug) pars.AddDefineSymbol ("DEBUG"); else if (kind == ConfigurationKind.Release) pars.Optimize = true; return pars; }
string GenerateOptions(DotNetProjectConfiguration configuration, VBCompilerParameters compilerparameters, VBProjectParameters projectparameters, string outputFileName) { DotNetProject project = (DotNetProject)configuration.ParentItem; StringBuilder sb = new StringBuilder(); sb.AppendFormat("\"-out:{0}\"", outputFileName); sb.AppendLine(); sb.AppendLine("-nologo"); sb.AppendLine("-utf8output"); sb.AppendLine("-quiet"); sb.AppendFormat("-debug:{0}", compilerparameters.DebugType); sb.AppendLine(); if (compilerparameters.Optimize) { sb.AppendLine("-optimize+"); } if (projectparameters.OptionStrict) { sb.AppendLine("-optionstrict+"); } else { sb.AppendLine("-optionstrict-"); } if (projectparameters.OptionExplicit) { sb.AppendLine("-optionexplicit+"); } else { sb.AppendLine("-optionexplicit-"); } if (projectparameters.BinaryOptionCompare) { sb.AppendLine("-optioncompare:binary"); } else { sb.AppendLine("-optioncompare:text"); } if (projectparameters.OptionInfer) { sb.AppendLine("-optioninfer+"); } else { sb.AppendLine("-optioninfer-"); } string mytype = projectparameters.MyType; if (!string.IsNullOrEmpty(mytype)) { sb.AppendFormat("-define:_MYTYPE=\\\"{0}\\\"", mytype); sb.AppendLine(); } string win32IconPath = projectparameters.ApplicationIcon; if (!string.IsNullOrEmpty(win32IconPath) && File.Exists(win32IconPath)) { sb.AppendFormat("\"-win32icon:{0}\"", win32IconPath); sb.AppendLine(); } if (!string.IsNullOrEmpty(projectparameters.CodePage)) { TextEncoding enc = TextEncoding.GetEncoding(projectparameters.CodePage); sb.AppendFormat("-codepage:{0}", enc.CodePage); sb.AppendLine(); } if (!string.IsNullOrEmpty(project.DefaultNamespace)) { sb.AppendFormat("-rootnamespace:{0}", project.DefaultNamespace); sb.AppendLine(); } if (!string.IsNullOrEmpty(compilerparameters.DefineConstants)) { sb.AppendFormat("\"-define:{0}\"", compilerparameters.DefineConstants); sb.AppendLine(); } if (compilerparameters.DefineDebug) { sb.AppendLine("-define:DEBUG=-1"); } if (compilerparameters.DefineTrace) { sb.AppendLine("-define:TRACE=-1"); } if (compilerparameters.WarningsDisabled) { sb.AppendLine("-nowarn"); } else if (!string.IsNullOrEmpty(compilerparameters.NoWarn)) { sb.AppendFormat("-nowarn:{0}", compilerparameters.NoWarn); sb.AppendLine(); } if (!string.IsNullOrEmpty(compilerparameters.WarningsAsErrors)) { sb.AppendFormat("-warnaserror+:{0}", compilerparameters.WarningsAsErrors); sb.AppendLine(); } if (configuration.SignAssembly) { if (File.Exists(configuration.AssemblyKeyFile)) { sb.AppendFormat("\"-keyfile:{0}\"", configuration.AssemblyKeyFile); sb.AppendLine(); } } if (!string.IsNullOrEmpty(compilerparameters.DocumentationFile)) { sb.AppendFormat("\"-doc:{0}\"", compilerparameters.DocumentationFile); sb.AppendLine(); } if (!string.IsNullOrEmpty(projectparameters.StartupObject) && projectparameters.StartupObject != "Sub Main") { sb.Append("-main:"); sb.Append(projectparameters.StartupObject); sb.AppendLine(); } if (compilerparameters.RemoveIntegerChecks) { sb.AppendLine("-removeintchecks+"); } if (!string.IsNullOrEmpty(compilerparameters.AdditionalParameters)) { sb.Append(compilerparameters.AdditionalParameters); sb.AppendLine(); } switch (configuration.CompileTarget) { case CompileTarget.Exe: sb.AppendLine("-target:exe"); break; case CompileTarget.WinExe: sb.AppendLine("-target:winexe"); break; case CompileTarget.Library: sb.AppendLine("-target:library"); break; case CompileTarget.Module: sb.AppendLine("-target:module"); break; default: throw new NotSupportedException("unknown compile target:" + configuration.CompileTarget); } return(sb.ToString()); }
public BuildResult Compile(ProjectItemCollection items, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, IProgressMonitor monitor) { VBCompilerParameters compilerparameters = (VBCompilerParameters)configuration.CompilationParameters; if (compilerparameters == null) { compilerparameters = new VBCompilerParameters(); } VBProjectParameters projectparameters = (VBProjectParameters)configuration.ProjectParameters; if (projectparameters == null) { projectparameters = new VBProjectParameters(); } string exe = configuration.CompiledOutputName; string responseFileName = Path.GetTempFileName(); StreamWriter writer = new StreamWriter(responseFileName); writer.WriteLine(GenerateOptions(configuration, compilerparameters, projectparameters, exe)); // Write references foreach (ProjectReference lib in items.GetAll <ProjectReference> ()) { foreach (string fileName in lib.GetReferencedFileNames(configSelector)) { writer.Write("\"-r:"); writer.Write(fileName); writer.WriteLine("\""); } } // Write source files and embedded resources foreach (ProjectFile finfo in items.GetAll <ProjectFile> ()) { if (finfo.Subtype != Subtype.Directory) { switch (finfo.BuildAction) { case "Compile": writer.WriteLine("\"" + finfo.Name + "\""); break; case "EmbeddedResource": string fname = finfo.Name; if (String.Compare(Path.GetExtension(fname), ".resx", true) == 0) { fname = Path.ChangeExtension(fname, ".resources"); } writer.WriteLine("\"-resource:{0},{1}\"", fname, finfo.ResourceId); break; default: continue; } } } // Write source files and embedded resources foreach (Import import in items.GetAll <Import> ()) { writer.WriteLine("-imports:{0}", import.Include); } TempFileCollection tf = new TempFileCollection(); writer.Close(); string output = ""; string compilerName = configuration.TargetRuntime.GetToolPath(configuration.TargetFramework, "vbc"); if (compilerName == null) { BuildResult res = new BuildResult(); res.AddError(string.Format("Visual Basict .NET compiler not found ({0})", configuration.TargetRuntime.DisplayName)); return(res); } string outstr = String.Concat(compilerName, " @", responseFileName); string workingDir = "."; if (configuration.ParentItem != null) { workingDir = configuration.ParentItem.BaseDirectory; } int exitCode; var envVars = configuration.TargetRuntime.GetToolsExecutionEnvironment(configuration.TargetFramework); monitor.Log.WriteLine(Path.GetFileName(compilerName) + " " + string.Join(" ", File.ReadAllLines(responseFileName))); exitCode = DoCompilation(outstr, tf, workingDir, envVars, ref output); monitor.Log.WriteLine(output); BuildResult result = ParseOutput(tf, output); if (result.Errors.Count == 0 && exitCode != 0) { // Compilation failed, but no errors? // Show everything the compiler said. result.AddError(output); } FileService.DeleteFile(responseFileName); if (configuration.CompileTarget != CompileTarget.Library) { WriteManifestFile(exe); } return(result); }
string GenerateOptions (DotNetProjectConfiguration configuration, VBCompilerParameters compilerparameters, VBProject projectparameters, string outputFileName) { var project = configuration.ParentItem; StringBuilder sb = new StringBuilder (); sb.AppendFormat ("\"-out:{0}\"", outputFileName); sb.AppendLine (); sb.AppendLine ("-nologo"); sb.AppendLine ("-utf8output"); sb.AppendLine ("-quiet"); sb.AppendFormat ("-debug:{0}", compilerparameters.DebugType); sb.AppendLine (); if (compilerparameters.Optimize) sb.AppendLine ("-optimize+"); if (projectparameters.OptionStrict) sb.AppendLine ("-optionstrict+"); else sb.AppendLine ("-optionstrict-"); if (projectparameters.OptionExplicit) sb.AppendLine ("-optionexplicit+"); else sb.AppendLine ("-optionexplicit-"); if (projectparameters.BinaryOptionCompare) sb.AppendLine ("-optioncompare:binary"); else sb.AppendLine ("-optioncompare:text"); if (projectparameters.OptionInfer) sb.AppendLine ("-optioninfer+"); else sb.AppendLine ("-optioninfer-"); string mytype = projectparameters.MyType; if (!string.IsNullOrEmpty (mytype)) { sb.AppendFormat ("-define:_MYTYPE=\\\"{0}\\\"", mytype); sb.AppendLine (); } string win32IconPath = projectparameters.ApplicationIcon; if (!string.IsNullOrEmpty (win32IconPath) && File.Exists (win32IconPath)) { sb.AppendFormat ("\"-win32icon:{0}\"", win32IconPath); sb.AppendLine (); } if (!string.IsNullOrEmpty (projectparameters.CodePage)) { TextEncoding enc = TextEncoding.GetEncoding (projectparameters.CodePage); sb.AppendFormat ("-codepage:{0}", enc.CodePage); sb.AppendLine (); } if (!string.IsNullOrEmpty (project.DefaultNamespace)) { sb.AppendFormat ("-rootnamespace:{0}", project.DefaultNamespace); sb.AppendLine (); } if (!string.IsNullOrEmpty (compilerparameters.DefineConstants)) { sb.AppendFormat ("\"-define:{0}\"", compilerparameters.DefineConstants); sb.AppendLine (); } if (compilerparameters.DefineDebug) sb.AppendLine ("-define:DEBUG=-1"); if (compilerparameters.DefineTrace) sb.AppendLine ("-define:TRACE=-1"); if (compilerparameters.WarningsDisabled) { sb.AppendLine ("-nowarn"); } else if (!string.IsNullOrEmpty (compilerparameters.NoWarn)) { sb.AppendFormat ("-nowarn:{0}", compilerparameters.NoWarn); sb.AppendLine (); } if (!string.IsNullOrEmpty (compilerparameters.WarningsAsErrors)) { sb.AppendFormat ("-warnaserror+:{0}", compilerparameters.WarningsAsErrors); sb.AppendLine (); } if (configuration.SignAssembly) { if (File.Exists (configuration.AssemblyKeyFile)) { sb.AppendFormat ("\"-keyfile:{0}\"", configuration.AssemblyKeyFile); sb.AppendLine (); } } if (configuration.DelaySign) sb.AppendLine ("-delaySign"); if (!string.IsNullOrEmpty (compilerparameters.DocumentationFile)) { sb.AppendFormat ("\"-doc:{0}\"", compilerparameters.DocumentationFile); sb.AppendLine (); } if (!string.IsNullOrEmpty (projectparameters.StartupObject) && projectparameters.StartupObject != "Sub Main") { sb.Append ("-main:"); sb.Append (projectparameters.StartupObject); sb.AppendLine (); } if (compilerparameters.RemoveIntegerChecks) sb.AppendLine ("-removeintchecks+"); if (!string.IsNullOrEmpty (compilerparameters.AdditionalParameters)) { sb.Append (compilerparameters.AdditionalParameters); sb.AppendLine (); } switch (configuration.CompileTarget) { case CompileTarget.Exe: sb.AppendLine ("-target:exe"); break; case CompileTarget.WinExe: sb.AppendLine ("-target:winexe"); break; case CompileTarget.Library: sb.AppendLine ("-target:library"); break; case CompileTarget.Module: sb.AppendLine ("-target:module"); break; default: throw new NotSupportedException("unknown compile target:" + configuration.CompileTarget); } return sb.ToString(); }
public BuildResult Compile (ProjectItemCollection items, DotNetProjectConfiguration configuration, ConfigurationSelector configSelector, ProgressMonitor monitor) { VBCompilerParameters compilerparameters = (VBCompilerParameters) configuration.CompilationParameters; if (compilerparameters == null) compilerparameters = new VBCompilerParameters (); var projectparameters = (VBProject) configuration.ParentItem; string exe = configuration.CompiledOutputName; string responseFileName = Path.GetTempFileName(); StreamWriter writer = new StreamWriter (responseFileName); writer.WriteLine (GenerateOptions (configuration, compilerparameters, projectparameters, exe)); // Write references foreach (ProjectReference lib in items.GetAll<ProjectReference> ()) { foreach (string fileName in lib.GetReferencedFileNames (configSelector)) { writer.Write ("\"-r:"); writer.Write (fileName); writer.WriteLine ("\""); } } // Write source files and embedded resources foreach (ProjectFile finfo in items.GetAll<ProjectFile> ()) { if (finfo.Subtype != Subtype.Directory) { switch (finfo.BuildAction) { case "Compile": writer.WriteLine("\"" + finfo.Name + "\""); break; case "EmbeddedResource": string fname = finfo.Name; if (String.Compare (Path.GetExtension (fname), ".resx", true) == 0) fname = Path.ChangeExtension (fname, ".resources"); writer.WriteLine("\"-resource:{0},{1}\"", fname, finfo.ResourceId); break; default: continue; } } } // Write source files and embedded resources foreach (Import import in items.GetAll<Import> ()) { writer.WriteLine ("-imports:{0}", import.Include); } TempFileCollection tf = new TempFileCollection (); writer.Close(); string output = ""; string compilerName = configuration.TargetRuntime.GetToolPath (configuration.TargetFramework, "vbc"); if (compilerName == null) { BuildResult res = new BuildResult (); res.AddError (string.Format ("Visual Basic .NET compiler not found ({0})", configuration.TargetRuntime.DisplayName)); return res; } string workingDir = "."; if (configuration.ParentItem != null) workingDir = configuration.ParentItem.BaseDirectory; int exitCode; var envVars = configuration.TargetRuntime.GetToolsExecutionEnvironment (configuration.TargetFramework); monitor.Log.WriteLine (Path.GetFileName (compilerName) + " " + string.Join (" ", File.ReadAllLines (responseFileName))); exitCode = DoCompilation (compilerName, responseFileName, tf, workingDir, envVars, ref output); monitor.Log.WriteLine (output); BuildResult result = ParseOutput (tf, output); if (result.Errors.Count == 0 && exitCode != 0) { // Compilation failed, but no errors? // Show everything the compiler said. result.AddError (output); } FileService.DeleteFile (responseFileName); if (configuration.CompileTarget != CompileTarget.Library) { WriteManifestFile (exe); } return result; }