本文整理汇总了C#中Microsoft.CodeAnalysis.Project.WithCompilationOptions方法的典型用法代码示例。如果您正苦于以下问题:C# Project.WithCompilationOptions方法的具体用法?C# Project.WithCompilationOptions怎么用?C# Project.WithCompilationOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.Project
的用法示例。
在下文中一共展示了Project.WithCompilationOptions方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithoutParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("MissingParamDocumentation.xml", contentWithoutParamDocumentation);
string contentWithParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<param name=""foo"">Param 1</param>
<param name=""bar"">Param 2</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithParamDocumentation.xml", contentWithParamDocumentation);
string contentWithInvalidParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<param>Test</param>
<param/>
<param name="""">Test</param>
<param name="" "">Test</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithInvalidParamDocumentation.xml", contentWithInvalidParamDocumentation);
string contentWithInheritedDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<inheritdoc />
<param>Test</param>
<param/>
<param name="""">Test</param>
<param name="" "">Test</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithInheritedDocumentation.xml", contentWithInheritedDocumentation);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例2: GetProjectAnalyzerDiagnosticsAsync
/// <summary>
/// Returns a list of all analyzer diagnostics inside the specific project. This is an asynchronous operation.
/// </summary>
/// <param name="analyzers">The list of analyzers that should be used</param>
/// <param name="project">The project that should be analyzed</param>
/// <param name="force"><see langword="true"/> to force the analyzers to be enabled; otherwise,
/// <see langword="false"/> to use the behavior configured for the specified <paramref name="project"/>.</param>
/// <param name="cancellationToken">The cancellation token that the task will observe.</param>
/// <returns>A list of diagnostics inside the project</returns>
private static async Task<ImmutableArray<Diagnostic>> GetProjectAnalyzerDiagnosticsAsync(ImmutableArray<DiagnosticAnalyzer> analyzers, Project project, bool force, CancellationToken cancellationToken)
{
var supportedDiagnosticsSpecificOptions = new Dictionary<string, ReportDiagnostic>();
if (force)
{
foreach (var analyzer in analyzers)
{
foreach (var diagnostic in analyzer.SupportedDiagnostics)
{
// make sure the analyzers we are testing are enabled
supportedDiagnosticsSpecificOptions[diagnostic.Id] = ReportDiagnostic.Default;
}
}
}
// Report exceptions during the analysis process as errors
supportedDiagnosticsSpecificOptions.Add("AD0001", ReportDiagnostic.Error);
// update the project compilation options
var modifiedSpecificDiagnosticOptions = supportedDiagnosticsSpecificOptions.ToImmutableDictionary().SetItems(project.CompilationOptions.SpecificDiagnosticOptions);
var modifiedCompilationOptions = project.CompilationOptions.WithSpecificDiagnosticOptions(modifiedSpecificDiagnosticOptions);
var processedProject = project.WithCompilationOptions(modifiedCompilationOptions);
Compilation compilation = await processedProject.GetCompilationAsync(cancellationToken).ConfigureAwait(false);
CompilationWithAnalyzers compilationWithAnalyzers = compilation.WithAnalyzers(analyzers, cancellationToken: cancellationToken);
var diagnostics = await FixAllContextHelper.GetAllDiagnosticsAsync(compilation, compilationWithAnalyzers, analyzers, project.Documents, true, cancellationToken).ConfigureAwait(false);
return diagnostics;
}
示例3: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithoutDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("NoDocumentation.xml", contentWithoutDocumentation);
string contentWithoutParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("NoParamDocumentation.xml", contentWithoutParamDocumentation);
string contentWithParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<param name=""foo"">Test</param>
<param name=""bar"">Test</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("ParamDocumentation.xml", contentWithParamDocumentation);
string contentWithEmptyParamDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<param name=""foo""></param>
<param name=""bar"">
</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("EmptyParamDocumentation.xml", contentWithEmptyParamDocumentation);
string contentWithEmptyParamDocumentation2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<param name=""foo""/>
<param name=""bar"">
<para>
</para>
</param>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("EmptyParamDocumentation2.xml", contentWithEmptyParamDocumentation2);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例4: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
<MethodName>
<summary>
Sample method.
</summary>
<returns>
A <see cref=""Task""/> representing the asynchronous operation.
</returns>
</MethodName>
</Class1>
";
resolver.XmlReferences.Add("ClassWithSummary.xml", contentWithSummary);
string contentWithInheritedSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
<MethodName>
<inheritdoc/>
</MethodName>
</Class1>
";
resolver.XmlReferences.Add("ClassWithInheritedSummary.xml", contentWithInheritedSummary);
string contentWithEmptySummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<Class1>
<MethodName>
<summary>
</summary>
<returns>
A <see cref=""Task""/> representing the asynchronous operation.
</returns>
</MethodName>
</Class1>
";
resolver.XmlReferences.Add("ClassWithEmptySummary.xml", contentWithEmptySummary);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例5: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithoutSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
</ClassName>
";
resolver.XmlReferences.Add("ClassWithoutSummary.xml", contentWithoutSummary);
string contentWithSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<summary>
Foo
</summary>
</ClassName>
";
resolver.XmlReferences.Add("ClassWithSummary.xml", contentWithSummary);
string contentWithDefaultSummary = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<summary>
Summary description for the ClassName class.
</summary>
</ClassName>
";
resolver.XmlReferences.Add("ClassWithDefaultSummary.xml", contentWithDefaultSummary);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例6: CompileProject
/// <summary>
/// Compiles the given P# project.
/// </summary>
/// <param name="project">Project</param>
private void CompileProject(Project project)
{
CompilationOptions options = null;
if (this.CompilationContext.Configuration.OptimizationTarget == OptimizationTarget.Debug)
{
options = project.CompilationOptions.WithOptimizationLevel(OptimizationLevel.Debug);
}
else if (this.CompilationContext.Configuration.OptimizationTarget == OptimizationTarget.Release)
{
options = project.CompilationOptions.WithOptimizationLevel(OptimizationLevel.Release);
}
project = project.WithCompilationOptions(options);
var compilation = project.GetCompilationAsync().Result;
try
{
if (this.CompilationContext.Configuration.CompilationTarget == CompilationTarget.Library ||
this.CompilationContext.Configuration.CompilationTarget == CompilationTarget.Testing ||
this.CompilationContext.Configuration.CompilationTarget == CompilationTarget.Remote)
{
this.ToFile(compilation, OutputKind.DynamicallyLinkedLibrary,
project.OutputFilePath, true, true);
}
else
{
this.ToFile(compilation, project.CompilationOptions.OutputKind,
project.OutputFilePath, true, true);
}
}
catch (ApplicationException ex)
{
IO.Error.ReportAndExit(ex.Message);
}
}
示例7: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithoutElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<TestMethod>
<summary>
Foo
</summary>
</TestMethod>
</TestClass>
";
resolver.XmlReferences.Add("MissingElementDocumentation.xml", contentWithoutElementDocumentation);
string contentWithElementDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<TestMethod>
<summary>
Foo
</summary>
<param name=""param1"">Param 1</param>
<param name=""param2"">Param 2</param>
<param name=""param3"">Param 3</param>
</TestMethod>
</TestClass>
";
resolver.XmlReferences.Add("WithElementDocumentation.xml", contentWithElementDocumentation);
string contentWithInheritedDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<TestMethod>
<inheritdoc />
</TestMethod>
</TestClass>
";
resolver.XmlReferences.Add("InheritedDocumentation.xml", contentWithInheritedDocumentation);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例8: ApplyCompilationOptions
/// <inheritdoc/>
protected override Project ApplyCompilationOptions(Project project)
{
var resolver = new TestXmlReferenceResolver();
string contentWithoutDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("NoDocumentation.xml", contentWithoutDocumentation);
string contentWithoutReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithoutReturns.xml", contentWithoutReturns);
string contentWithReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<returns>Test</returns>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithReturns.xml", contentWithReturns);
string contentWithEmptyReturns = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<returns>
</returns>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithEmptyReturns.xml", contentWithEmptyReturns);
string contentWithEmptyReturns2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<returns />
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithEmptyReturns2.xml", contentWithEmptyReturns2);
string contentWithEmptyReturns3 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<ClassName>
<Method>
<summary>
Foo
</summary>
<returns></returns>
</Method>
</ClassName>
";
resolver.XmlReferences.Add("WithEmptyReturns3.xml", contentWithEmptyReturns3);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}
示例9: ApplyCompilationOptions
//.........这里部分代码省略.........
string correctDocumentation = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>
Some documentation.
</summary>
<remark>Some remark.</remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("Correct.xml", correctDocumentation);
string correctWithEmptyReferenceElements = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>
Some documentation <see cref=""TestClass""/>.
</summary>
<summary>
Some documentation <see cref=""TestClass2""/>.
</summary>
<remark>Some remark.</remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("CorrectWithEmptyElements.xml", correctWithEmptyReferenceElements);
string correctWithEmptyElements = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary></summary>
<remark></remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("CorrectEmpty.xml", correctWithEmptyElements);
string inherited = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<inheritdoc />
</Test>
</TestClass>
";
resolver.XmlReferences.Add("Inherited.xml", inherited);
string badWithNormalization = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>
Some documentation <see cref=""TestClass""/>.
</summary>
<summary>
Some documentation <see cref = ""TestClass"" />.
</summary>
<remark>Some remark.</remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("BadWithNormalization.xml", badWithNormalization);
string badWithDuplicates = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>Some documentation.</summary>
<remark>Some documentation.</remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("BadWithDuplicates.xml", badWithDuplicates);
string badWithDuplicates2 = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>
Some documentation.
</summary>
<remark> Some documentation. </remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("BadWithDuplicates2.xml", badWithDuplicates2);
string withIgnoredParameters = @"<?xml version=""1.0"" encoding=""utf-8"" ?>
<TestClass>
<Test>
<summary>The parameter is not used.</summary>
<remark>The parameter is not used.</remark>
</Test>
</TestClass>
";
resolver.XmlReferences.Add("WithIgnoredParameters.xml", withIgnoredParameters);
project = base.ApplyCompilationOptions(project);
project = project.WithCompilationOptions(project.CompilationOptions.WithXmlReferenceResolver(resolver));
return project;
}