本文整理汇总了C#中LoadState.GetOrCreateProjectId方法的典型用法代码示例。如果您正苦于以下问题:C# LoadState.GetOrCreateProjectId方法的具体用法?C# LoadState.GetOrCreateProjectId怎么用?C# LoadState.GetOrCreateProjectId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LoadState
的用法示例。
在下文中一共展示了LoadState.GetOrCreateProjectId方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ResolveProjectReferencesAsync
private async Task<ResolvedReferences> ResolveProjectReferencesAsync(
ProjectId thisProjectId,
string thisProjectPath,
IReadOnlyList<ProjectFileReference> projectFileReferences,
bool preferMetadata,
LoadState loadedProjects,
CancellationToken cancellationToken)
{
var resolvedReferences = new ResolvedReferences();
var reportMode = this.SkipUnrecognizedProjects ? ReportMode.Log : ReportMode.Throw;
foreach (var projectFileReference in projectFileReferences)
{
string fullPath;
if (TryGetAbsoluteProjectPath(projectFileReference.Path, Path.GetDirectoryName(thisProjectPath), reportMode, out fullPath))
{
// if the project is already loaded, then just reference the one we have
var existingProjectId = loadedProjects.GetProjectId(fullPath);
if (existingProjectId != null)
{
resolvedReferences.ProjectReferences.Add(new ProjectReference(existingProjectId, projectFileReference.Aliases));
continue;
}
IProjectFileLoader loader;
TryGetLoaderFromProjectPath(fullPath, ReportMode.Ignore, out loader);
// get metadata if preferred or if loader is unknown
if (preferMetadata || loader == null)
{
var projectMetadata = await this.GetProjectMetadata(fullPath, projectFileReference.Aliases, _properties, cancellationToken).ConfigureAwait(false);
if (projectMetadata != null)
{
resolvedReferences.MetadataReferences.Add(projectMetadata);
continue;
}
}
// must load, so we really need loader
if (TryGetLoaderFromProjectPath(fullPath, reportMode, out loader))
{
// load the project
var projectId = await this.GetOrLoadProjectAsync(fullPath, loader, preferMetadata, loadedProjects, cancellationToken).ConfigureAwait(false);
// If that other project already has a reference on us, this will cause a circularity.
// This check doesn't need to be in the "already loaded" path above, since in any circularity this path
// must be taken at least once.
if (loadedProjects.ProjectAlreadyReferencesProject(projectId, targetProject: thisProjectId))
{
// We'll try to make this metadata if we can
var projectMetadata = await this.GetProjectMetadata(fullPath, projectFileReference.Aliases, _properties, cancellationToken).ConfigureAwait(false);
if (projectMetadata != null)
{
resolvedReferences.MetadataReferences.Add(projectMetadata);
}
continue;
}
else
{
resolvedReferences.ProjectReferences.Add(new ProjectReference(projectId, projectFileReference.Aliases));
continue;
}
}
}
else
{
fullPath = projectFileReference.Path;
}
// cannot find metadata and project cannot be loaded, so leave a project reference to a non-existent project.
var id = loadedProjects.GetOrCreateProjectId(fullPath);
resolvedReferences.ProjectReferences.Add(new ProjectReference(id, projectFileReference.Aliases));
}
return resolvedReferences;
}
示例2: LoadProjectAsync
private async Task<ProjectId> LoadProjectAsync(string projectFilePath, IProjectFileLoader loader, bool preferMetadata, LoadState loadedProjects, CancellationToken cancellationToken)
{
Debug.Assert(projectFilePath != null);
Debug.Assert(loader != null);
var projectId = loadedProjects.GetOrCreateProjectId(projectFilePath);
var projectName = Path.GetFileNameWithoutExtension(projectFilePath);
var projectFile = await loader.LoadProjectFileAsync(projectFilePath, _properties, cancellationToken).ConfigureAwait(false);
var projectFileInfo = await projectFile.GetProjectFileInfoAsync(cancellationToken).ConfigureAwait(false);
var projectDirectory = Path.GetDirectoryName(projectFilePath);
var outputFilePath = projectFileInfo.OutputFilePath;
var outputDirectory = Path.GetDirectoryName(outputFilePath);
VersionStamp version;
if (!string.IsNullOrEmpty(projectFilePath) && File.Exists(projectFilePath))
{
version = VersionStamp.Create(File.GetLastWriteTimeUtc(projectFilePath));
}
else
{
version = VersionStamp.Create();
}
// translate information from command line args
var commandLineParser = _workspace.Services.GetLanguageServices(loader.Language).GetService<ICommandLineParserService>();
var metadataService = _workspace.Services.GetService<IMetadataService>();
var analyzerService = _workspace.Services.GetService<IAnalyzerService>();
var commandLineArgs = commandLineParser.Parse(
arguments: projectFileInfo.CommandLineArgs,
baseDirectory: projectDirectory,
isInteractive: false,
sdkDirectory: RuntimeEnvironment.GetRuntimeDirectory());
// we only support file paths in /r command line arguments
var resolver = new WorkspaceMetadataFileReferenceResolver(metadataService, new RelativePathResolver(commandLineArgs.ReferencePaths, commandLineArgs.BaseDirectory));
var metadataReferences = commandLineArgs.ResolveMetadataReferences(resolver);
var analyzerLoader = analyzerService.GetLoader();
foreach (var path in commandLineArgs.AnalyzerReferences.Select(r => r.FilePath))
{
analyzerLoader.AddDependencyLocation(path);
}
var analyzerReferences = commandLineArgs.ResolveAnalyzerReferences(analyzerLoader);
var defaultEncoding = commandLineArgs.Encoding;
// docs & additional docs
var docFileInfos = projectFileInfo.Documents.ToImmutableArrayOrEmpty();
var additionalDocFileInfos = projectFileInfo.AdditionalDocuments.ToImmutableArrayOrEmpty();
// check for duplicate documents
var allDocFileInfos = docFileInfos.AddRange(additionalDocFileInfos);
CheckDocuments(allDocFileInfos, projectFilePath, projectId);
var docs = new List<DocumentInfo>();
foreach (var docFileInfo in docFileInfos)
{
string name;
ImmutableArray<string> folders;
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out name, out folders);
docs.Add(DocumentInfo.Create(
DocumentId.CreateNewId(projectId, debugName: docFileInfo.FilePath),
name,
folders,
projectFile.GetSourceCodeKind(docFileInfo.FilePath),
new FileTextLoader(docFileInfo.FilePath, defaultEncoding),
docFileInfo.FilePath,
docFileInfo.IsGenerated));
}
var additionalDocs = new List<DocumentInfo>();
foreach (var docFileInfo in additionalDocFileInfos)
{
string name;
ImmutableArray<string> folders;
GetDocumentNameAndFolders(docFileInfo.LogicalPath, out name, out folders);
additionalDocs.Add(DocumentInfo.Create(
DocumentId.CreateNewId(projectId, debugName: docFileInfo.FilePath),
name,
folders,
SourceCodeKind.Regular,
new FileTextLoader(docFileInfo.FilePath, defaultEncoding),
docFileInfo.FilePath,
docFileInfo.IsGenerated));
}
// project references
var resolvedReferences = await ResolveProjectReferencesAsync(
projectId, projectFilePath, projectFileInfo.ProjectReferences, preferMetadata, loadedProjects, cancellationToken).ConfigureAwait(false);
// add metadata references for project refs converted to metadata refs
metadataReferences = metadataReferences.Concat(resolvedReferences.MetadataReferences);
//.........这里部分代码省略.........