/// <summary> /// Try to retrieve the current state for the specified project document. /// </summary> /// <param name="documentUri"> /// The project document URI. /// </param> /// <param name="reload"> /// Reload the project if it is already loaded? /// </param> /// <returns> /// The project document. /// </returns> public async Task <ProjectDocument> GetProjectDocument(Uri documentUri, bool reload = false) { string projectFilePath = VSCodeDocumentUri.GetFileSystemPath(documentUri); bool isNewProject = false; ProjectDocument projectDocument = _projectDocuments.GetOrAdd(documentUri, _ => { isNewProject = true; if (MasterProject == null) { return(MasterProject = new MasterProjectDocument(this, documentUri, Log)); } return(MasterProject); }); try { if (isNewProject || reload) { using (await projectDocument.Lock.WriterLockAsync()) { await projectDocument.Load(); } } } catch (Exception loadError) { Log.Error(loadError, "Unexpected error loading file {ProjectFilePath}.", projectFilePath); } return(projectDocument); }
/// <summary> /// Create a new <see cref="SubProjectDocument"/>. /// </summary> /// <param name="workspace"> /// The document workspace. /// </param> /// <param name="documentUri"> /// The document URI. /// </param> /// <param name="logger"> /// The application logger. /// </param> /// <param name="masterProjectDocument"> /// The master project document that owns the sub-project. /// </param> public SubProjectDocument(Workspace workspace, Uri documentUri, ILogger logger, MasterProjectDocument masterProjectDocument) : base(workspace, documentUri, logger) { if (masterProjectDocument == null) { throw new ArgumentNullException(nameof(masterProjectDocument)); } MasterProjectDocument = masterProjectDocument; }
/// <summary> /// Try to retrieve the current state for the specified project document. /// </summary> /// <param name="documentUri"> /// The project document URI. /// </param> /// <param name="reload"> /// Reload the project if it is already loaded? /// </param> /// <returns> /// The project document. /// </returns> public async Task <ProjectDocument> GetProjectDocument(Uri documentUri, bool reload = false) { string projectFilePath = VSCodeDocumentUri.GetFileSystemPath(documentUri); bool isNewProject = false; ProjectDocument projectDocument = _projectDocuments.GetOrAdd(documentUri, _ => { isNewProject = true; if (MasterProject == null) { return(MasterProject = new MasterProjectDocument(this, documentUri, Log)); } SubProjectDocument subProject = new SubProjectDocument(this, documentUri, Log, MasterProject); MasterProject.AddSubProject(subProject); return(subProject); }); if (!_msbuildVersionLogged) { if (MSBuildHelper.HaveMSBuild) { Log.Information("Using MSBuild engine v{MSBuildVersion:l} from {MSBuildPath}.", MSBuildHelper.MSBuildVersion, MSBuildHelper.MSBuildPath ); } else { Log.Warning("Failed to find any version of MSBuild compatible with the current .NET SDK (respecting global.json)."); } _msbuildVersionLogged = true; } try { if (isNewProject || reload) { using (await projectDocument.Lock.WriterLockAsync()) { await projectDocument.Load(); } } } catch (XmlException invalidXml) { Log.Error("Error parsing project file {ProjectFilePath}: {ErrorMessage:l}", projectFilePath, invalidXml.Message ); } catch (Exception loadError) { Log.Error(loadError, "Unexpected error loading file {ProjectFilePath}.", projectFilePath); } return(projectDocument); }