本文整理汇总了C#中Saltarelle.Compiler.Driver.CompilerOptions类的典型用法代码示例。如果您正苦于以下问题:C# CompilerOptions类的具体用法?C# CompilerOptions怎么用?C# CompilerOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CompilerOptions类属于Saltarelle.Compiler.Driver命名空间,在下文中一共展示了CompilerOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCompileAsyncTaskGenericMethod
public void CanCompileAsyncTaskGenericMethod()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File1.cs"), @"
using System.Threading.Tasks;
public class C1 {
public async Task<int> M() {
var t = new Task(() => {});
await t;
return 0;
}
}");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File1.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
}, "File1.cs", "Test.dll", "Test.js");
}
示例2: ChangingTheWarningLevelWorks
public void ChangingTheWarningLevelWorks()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js"),
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages.Select(m => m.Code).ToList(), Is.EquivalentTo(new[] { 219, 78 }));
}, "File.cs", "Test.dll", "Test.js");
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = 0l; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js"),
WarningLevel = 3,
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(er.AllMessages.Select(m => m.Code), Is.EqualTo(new[] { 219 }));
}, "File.cs", "Test.dll", "Test.js");
}
示例3: Compile
/// <param name="options">Compile options</param>
/// <param name="runInSeparateAppDomain">Should be set to true for production code, but there are issues with NUnit, so tests need to set this to false.</param>
public bool Compile(CompilerOptions options, bool runInSeparateAppDomain)
{
try {
AppDomain ad = null;
var actualOut = Console.Out;
try {
Console.SetOut(new StringWriter()); // I don't trust the third-party libs to not generate spurious random messages, so make sure that any of those messages are suppressed.
var er = new ErrorReporterWrapper(_errorReporter, actualOut);
Executor executor;
if (runInSeparateAppDomain) {
var setup = new AppDomainSetup { ApplicationBase = Path.GetDirectoryName(typeof(Executor).Assembly.Location) };
ad = AppDomain.CreateDomain("SCTask", null, setup);
executor = (Executor)ad.CreateInstanceAndUnwrap(typeof(Executor).Assembly.FullName, typeof(Executor).FullName);
}
else {
executor = new Executor();
}
return executor.Compile(options, er);
}
finally {
if (ad != null) {
AppDomain.Unload(ad);
}
if (actualOut != null) {
Console.SetOut(actualOut);
}
}
}
catch (Exception ex) {
_errorReporter.InternalError(ex, null, TextLocation.Empty);
return false;
}
}
示例4: GetAssemblyName
private static string GetAssemblyName(CompilerOptions options) {
if (options.OutputAssemblyPath != null)
return Path.GetFileNameWithoutExtension(options.OutputAssemblyPath);
else if (options.SourceFiles.Count > 0)
return Path.GetFileNameWithoutExtension(options.SourceFiles[0]);
else
return null;
}
示例5: HandleReferences
private static void HandleReferences(CompilerOptions options, string value) {
foreach (var reference in value.Split(new[] { ',' }).Select(s => s.Trim()).Where(s => s != "")) {
int i = reference.IndexOf('=');
if (i >= 0)
options.References.Add(new Reference(reference.Substring(i + 1), reference.Substring(0, i)));
else
options.References.Add(new Reference(reference));
}
}
示例6: MapSettings
private static CompilerSettings MapSettings(CompilerOptions options, string outputAssemblyPath, string outputDocFilePath, IErrorReporter er) {
var allPaths = options.AdditionalLibPaths.Concat(new[] { Environment.CurrentDirectory }).ToList();
var result = new CompilerSettings {
Target = (options.HasEntryPoint ? Target.Exe : Target.Library),
Platform = Platform.AnyCPU,
TargetExt = (options.HasEntryPoint ? ".exe" : ".dll"),
MainClass = options.EntryPointClass,
VerifyClsCompliance = false,
Optimize = false,
Version = LanguageVersion.V_5,
EnhancedWarnings = false,
LoadDefaultReferences = false,
TabSize = 1,
WarningsAreErrors = options.TreatWarningsAsErrors,
FatalCounter = 100,
WarningLevel = options.WarningLevel,
Encoding = Encoding.UTF8,
DocumentationFile = !string.IsNullOrEmpty(options.DocumentationFile) ? outputDocFilePath : null,
OutputFile = outputAssemblyPath,
AssemblyName = GetAssemblyName(options),
StdLib = false,
StdLibRuntimeVersion = RuntimeVersion.v4,
StrongNameKeyContainer = options.KeyContainer,
StrongNameKeyFile = options.KeyFile,
};
result.SourceFiles.AddRange(options.SourceFiles.Select((f, i) => new SourceFile(f, f, i + 1)));
foreach (var r in options.References) {
string resolvedPath = ResolveReference(r.Filename, allPaths, er);
if (r.Alias == null) {
if (!result.AssemblyReferences.Contains(resolvedPath))
result.AssemblyReferences.Add(resolvedPath);
}
else
result.AssemblyReferencesAliases.Add(Tuple.Create(r.Alias, resolvedPath));
}
foreach (var c in options.DefineConstants)
result.AddConditionalSymbol(c);
foreach (var w in options.DisabledWarnings)
result.SetIgnoreWarning(w);
foreach (var w in options.WarningsAsErrors)
result.AddWarningAsError(w);
foreach (var w in options.WarningsNotAsErrors)
result.AddWarningOnly(w);
if (options.EmbeddedResources.Count > 0)
result.Resources = options.EmbeddedResources.Select(r => new AssemblyResource(r.Filename, r.ResourceName, isPrivate: !r.IsPublic) { IsEmbeded = true }).ToList();
if (result.AssemblyReferencesAliases.Count > 0) { // NRefactory does currently not support reference aliases, this check will hopefully go away in the future.
er.Region = DomRegion.Empty;
er.Message(Messages._7998, "aliased reference");
}
return result;
}
示例7: CanInitializeListWithCollectionInitializer
public void CanInitializeListWithCollectionInitializer()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("Test.cs"), @"using System.Collections.Generic; public class C1 { public void M() { var l = new List<int> { 1 }; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("Test.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(result, Is.True, "Compilation failed with " + string.Join(Environment.NewLine, er.AllMessagesText));
}, "File1.cs", "Test.dll", "Test.js");
}
示例8: HandleWarningsAsErrors
private static void HandleWarningsAsErrors(CompilerOptions options, string value) {
string param;
if (value != null && (value[0] == '-' || value[0] == '/')) {
var colon = value.IndexOf(':');
param = colon >= 0 ? value.Substring(colon + 1) : null;
}
else {
param = value;
}
if (param != null) {
HandleIntegerList(options.WarningsAsErrors, param, "warnaserror");
}
else {
options.TreatWarningsAsErrors = true;
}
}
示例9: SimpleCompilationWorks
public void SimpleCompilationWorks() {
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections; public class C1 { public JsDictionary M() { return null; } }");
File.WriteAllText(Path.GetFullPath("File2.cs"), @"using System.Collections; public class C2 { public JsDictionary M() { return null; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File1.cs"), Path.GetFullPath("File2.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var driver = new CompilerDriver(new MockErrorReporter());
var result = driver.Compile(options, null);
Assert.That(result, Is.True);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
}, "File1.cs", "File2.cs", "Test.dll", "Test.js");
}
示例10: AssemblyNameIsCorrectInTheGeneratedScript
public void AssemblyNameIsCorrectInTheGeneratedScript() {
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections; public class C1 { public JsDictionary M() { return null; } }");
File.WriteAllText(Path.GetFullPath("File2.cs"), @"using System.Collections; public class C2 { public JsDictionary M() { return null; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File1.cs"), Path.GetFullPath("File2.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.Assembly.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var driver = new CompilerDriver(new MockErrorReporter());
var result = driver.Compile(options);
Assert.That(result, Is.True);
var text = File.ReadAllText(Path.GetFullPath("Test.js"));
Assert.That(text.Contains("ss.initAssembly($asm, 'Test.Assembly')")); // Verify that the symbol was passed to the script compiler.
}, "File1.cs", "File2.cs", "Test.Assembly.dll", "Test.js");
}
示例11: CanCompileLockStatement
public void CanCompileLockStatement()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File1.cs"), @"using System.Collections.Generic; public class C1 { public void M() { lock (new object()) {} } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File1.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var driver = new CompilerDriver(new MockErrorReporter());
var result = driver.Compile(options, false);
Assert.That(result, Is.True);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.True, "Assembly should be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.True, "Script should be written");
}, "File1.cs", "Test.dll", "Test.js");
}
示例12: CompileErrorsAreReportedAndCauseFilesNotToBeGenerated
public void CompileErrorsAreReportedAndCauseFilesNotToBeGenerated() {
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"public class C1 { public void M() { var x = y; } }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js")
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, null);
Assert.That(result, Is.False);
Assert.That(er.AllMessages.Any(m => m.Severity == MessageSeverity.Error && m.Code == 103 && m.Region.FileName == Path.GetFullPath("File.cs") && m.Region.Begin == new TextLocation(1, 45) && m.Format != null && m.Args.Length == 0));
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.False, "Assembly should not be written");
Assert.That(File.Exists(Path.GetFullPath("Test.js")), Is.False, "Script should not be written");
}, "File.cs", "Test.dll", "Test.js");
}
示例13: AssemblyThatCanNotBeLocatedCausesError7997
public void AssemblyThatCanNotBeLocatedCausesError7997()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"class Class1 { public void M() {} }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath), new Reference("MyNonexistentAssembly") },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("Test.dll"),
OutputScriptPath = Path.GetFullPath("Test.js"),
MinimizeScript = false,
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
var result = driver.Compile(options, false);
Assert.That(er.AllMessages, Has.Count.EqualTo(1));
Assert.That(er.AllMessages.Any(m => m.Code == 7997 && (string)m.Args[0] == "MyNonexistentAssembly"));
Assert.That(result, Is.False);
Assert.That(File.Exists(Path.GetFullPath("Test.dll")), Is.False);
}, "File.cs", "Test.dll", "Test.js");
}
示例14: ReadProject
private CompilerOptions ReadProject(string filename, string solutionDir = null) {
var basePath = Path.GetDirectoryName(filename);
var opts = new CompilerOptions();
string content = File.ReadAllText(filename);
content = content.Replace("$(SolutionDir)", solutionDir + "\\");
var project = XDocument.Parse(content);
var nsm = new XmlNamespaceManager(new NameTable());
nsm.AddNamespace("msb", "http://schemas.microsoft.com/developer/msbuild/2003");
var projectReferences = project.XPathSelectElements("msb:Project/msb:ItemGroup/msb:ProjectReference", nsm)
.Select(n => n.Attribute("Include").Value).ToList()
.Select(f => Path.GetFullPath(Path.Combine(basePath, Path.GetDirectoryName(f), "bin", "Debug", Path.GetFileNameWithoutExtension(f) + ".dll"))).ToList();
opts.SourceFiles.AddRange(project.XPathSelectElements("msb:Project/msb:ItemGroup/msb:Compile", nsm).Select(item => Path.GetFullPath(Path.Combine(basePath, item.Attributes("Include").Single().Value))));
opts.References.AddRange(project.XPathSelectElements("msb:Project/msb:ItemGroup/msb:Reference/msb:HintPath", nsm).Select(item => new Reference(Path.GetFullPath(Path.Combine(basePath, item.Value)))));
opts.References.AddRange(projectReferences.Select(item => new Reference(item)));
opts.OutputAssemblyPath = Path.GetFullPath("output.dll");
opts.OutputScriptPath = Path.GetFullPath("output.js");
return opts;
}
示例15: ErrorWritingTheOutputScriptGivesCS7951
public void ErrorWritingTheOutputScriptGivesCS7951()
{
UsingFiles(() => {
File.WriteAllText(Path.GetFullPath("File.cs"), @"class Class1 { public void M() {} }");
var options = new CompilerOptions {
References = { new Reference(Common.MscorlibPath) },
SourceFiles = { Path.GetFullPath("File.cs") },
OutputAssemblyPath = Path.GetFullPath("MyOutputFile.dll"),
OutputScriptPath = Path.GetFullPath("MyOutputFile.js"),
DocumentationFile = Path.GetFullPath("MyOutputFile.xml"),
};
var er = new MockErrorReporter();
var driver = new CompilerDriver(er);
bool result;
using (File.Open(Path.GetFullPath("MyOutputFile.js"), FileMode.Create)) {
result = driver.Compile(options, false);
}
Assert.That(result, Is.False);
Assert.That(er.AllMessages.Any(m => m.Code == 7951 && m.Args.Length == 1));
}, "File.cs", "MyOutputFile.dll", "MyOutputFile.js", "MyOutputFile.xml");
}