本文整理汇总了C#中Microsoft.CodeAnalysis.AdhocWorkspace.AddMetadataReference方法的典型用法代码示例。如果您正苦于以下问题:C# AdhocWorkspace.AddMetadataReference方法的具体用法?C# AdhocWorkspace.AddMetadataReference怎么用?C# AdhocWorkspace.AddMetadataReference使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.AdhocWorkspace
的用法示例。
在下文中一共展示了AdhocWorkspace.AddMetadataReference方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateProject
protected Project CreateProject(Dictionary<string, string> sources)
{
string fileNamePrefix = DefaultFilePathPrefix;
string fileExt = CSharpDefaultFileExt;
var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp);
foreach (var reference in References)
{
solution = solution.AddMetadataReference(projectId, reference);
}
int count = 0;
foreach (var source in sources)
{
var newFileName = source.Key;
var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
solution = solution.AddDocument(documentId, newFileName, SourceText.From(source.Value));
count++;
}
var project = solution.GetProject(projectId)
.WithCompilationOptions(CompilationOptions);
return project;
}
示例2: CreateProject
/// <summary>
/// Create a project using the inputted strings as sources.
/// </summary>
/// <param name="sources">Classes in the form of strings</param>
/// <param name="language">The language the source code is in</param>
/// <returns>A Project created out of the Documents created from the source strings</returns>
private Project CreateProject(string[] sources, string language = LanguageNames.CSharp)
{
string fileNamePrefix = DefaultFilePathPrefix;
string fileExt = language == LanguageNames.CSharp ? CSharpDefaultFileExt : VisualBasicDefaultExt;
var projectId = ProjectId.CreateNewId(debugName: TestProjectName);
var solution = new AdhocWorkspace()
.CurrentSolution
.AddProject(projectId, TestProjectName, TestProjectName, language)
.AddMetadataReference(projectId, CorlibReference)
.AddMetadataReference(projectId, SystemCoreReference)
.AddMetadataReference(projectId, CSharpSymbolsReference)
.AddMetadataReference(projectId, CodeAnalysisReference);
foreach (var additionalReference in GetAdditionalReferences())
{
solution = solution.AddMetadataReference(projectId, additionalReference);
}
int count = 0;
foreach (var source in sources)
{
var newFileName = fileNamePrefix + count + "." + fileExt;
var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName);
solution = solution.AddDocument(documentId, newFileName, SourceText.From(source));
count++;
}
return solution.GetProject(projectId);
}