📄 vbcompiler.cs
字号:
// VBCompiler.cs
// Copyright (C) 2001 Mike Krueger
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
using System;
using System.IO;
using System.CodeDom.Compiler;
using Microsoft.VisualBasic;
using SharpDevelop.Internal.Project;
using SharpDevelop.Internal.Parser;
using SharpDevelop.Tool.Data;
namespace VBDefinition {
/// <summary>
/// This class controls the compilation of C Sharp files and C Sharp projects
/// </summary>
public class VBCompiler : ISdCompiler
{
ICodeCompiler compiler;
public VBCompiler()
{
compiler = new VBCodeProvider().CreateCompiler();
}
public CompilerResults CompileFile(string filename)
{
DefaultLibrary library = new DefaultLibrary();
CompilerParameters options = new CompilerParameters(library.Library);
string exe = filename.Substring(0, filename.LastIndexOf('.')) + ".exe";
options.GenerateExecutable = true;
options.OutputAssembly = exe;
return compiler.CompileAssemblyFromFile(options, filename);
}
public CompilerResults CompileProject(ISdProject project)
{
VBProject p = (VBProject)project;
VBProjectCompilerParameters compilerparameters = (VBProjectCompilerParameters)p.CompilerParameters;
DefaultLibrary library = new DefaultLibrary();
CompilerParameters options = new CompilerParameters(library.Library);
string exe = p.OutputDirectory + "\\" + p.OutputAssembly + (compilerparameters.CompileTarget == CompileTarget.Library ? ".dll" : ".exe");
foreach (string lib in p.References)
options.ReferencedAssemblies.Add(lib);
options.GenerateExecutable = compilerparameters.CompileTarget != CompileTarget.Library;
options.OutputAssembly = exe;
options.IncludeDebugInformation = compilerparameters.Debugmode;
string[] files = (string[])p.Files.ToArray(typeof(string));
return compiler.CompileAssemblyFromFileBatch(options, files);
/*
string resources = "";
string libs = "";
string options = "";
string files = "";
DefaultLibrary library = (DefaultLibrary)Option.GetProperty("SharpDevelop.Parser.VBCompiler.DefaultLibraries", new DefaultLibrary());
foreach (string lib in library.Library)
libs += " \"/r:" + lib + "\"";
foreach (string lib in p.Modules)
libs += " \"/addmodule:" + lib + "\"";
// if (compilerparameters.Debugmode)
// options += " /debug:+ /debug:full /d:DEBUG";
// if (compilerparameters.Optimize)
// options += " /o";
// if (compilerparameters.UnsafeCode)
// options += " /unsafe";
switch (compilerparameters.CompileTarget) {
case CompileTarget.Exe:
options += " /t:exe";
break;
case CompileTarget.WinExe:
options += " /t:winexe";
break;
case CompileTarget.Library:
options += " /t:library";
break;
default:
options += " /t:module";
break;
}
foreach (string file in p.Files) {
switch (System.IO.Path.GetExtension(file).ToLower()) {
case ".vb":
files += " \"" + file + '"';
break;
case ".resources":
resources += " \"/res:" + file + "\"";
break;
}
}
TempFileCollection tf = new TempFileCollection ();
string output = "";
string error = "";
string outstr = "vbc " + options + " \"/out:" + exe+ '"' + " " + files + libs + resources;
Executor.ExecWaitWithCapture(outstr, tf, ref output, ref error);
CompilerResults cr = ParseOutput(tf, output);
File.Delete(output);
File.Delete(error);
return cr;*/
}
/*
static CompilerResults ParseOutput(TempFileCollection tf, string file)
{
StreamReader sr = File.OpenText(file);
for (int i = 0;i < 6; ++i)
sr.ReadLine();
CompilerResults cr = new CompilerResults(tf);
while (true) {
string next = sr.ReadLine();
Console.WriteLine(next);
if (next == null)
break;
CompilerError error = new CompilerError();
int index = next.IndexOf(": ");
if (index < 0)
continue;
string description = null;
string errorwarning = null;
string location = null;
string s1 = next.Substring(0, index);
string s2 = next.Substring(index + 2);
index = s2.IndexOf(": ");
if (index == -1) {
errorwarning = s1;
description = s2;
} else {
location = s1;
s1 = s2.Substring(0, index);
s2 = s2.Substring(index + 2);
errorwarning = s1;
description = s2;
}
if (location != null) {
int idx1 = location.LastIndexOf('(');
int idx2 = location.LastIndexOf(')');
string filename = location.Substring(0, idx1);
string pos = location.Substring(idx1 + 1, idx2 - idx1 - 1);
string[] pos2 = pos.Split(new char[] {','});
error.Column = Int32.Parse(pos2[1]);
error.Line = Int32.Parse(pos2[0]);
error.FileName = Path.GetFullPath(filename); // + "\\" + Path.GetFileName(filename);
}
string[] what = errorwarning.Split(new char[] { ' ' } );
error.IsWarning = what[0].Equals("warning");
error.ErrorNumber = what[what.Length - 1];
error.ErrorText = description;
cr.Errors.Add(error);
}
sr.Close();
return cr;
}*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -