public override async Task <string> OnGetEvaluatedPropertyValueAsync( string evaluatedPropertyValue, IProjectProperties defaultProperties) { using (ProjectLockReleaser access = await _projectLockService.ReadLockAsync()) { Microsoft.Build.Construction.ProjectRootElement projectXml = await access.GetProjectXmlAsync(_unconfiguredProject.FullPath); return(await _helper.GetPropertyAsync(projectXml, defaultProperties)); } }
public async Task OpenProjectXmlForUpgradeableReadAsync(UnconfiguredProject project, Func <ProjectRootElement, CancellationToken, Task> action, CancellationToken cancellationToken = default) { Requires.NotNull(project, nameof(project)); Requires.NotNull(project, nameof(action)); using (ProjectLockReleaser access = await _projectLockService.UpgradeableReadLockAsync(cancellationToken)) { ProjectRootElement rootElement = await access.GetProjectXmlAsync(project.FullPath, cancellationToken); // Only async to let the caller upgrade to a // write lock via OpenProjectXmlForWriteAsync await action(rootElement, cancellationToken); } }
public async Task <TResult> OpenProjectXmlForReadAsync <TResult>(UnconfiguredProject project, Func <ProjectRootElement, TResult> action, CancellationToken cancellationToken = default) { Requires.NotNull(project, nameof(project)); Requires.NotNull(project, nameof(action)); using (ProjectLockReleaser access = await _projectLockService.ReadLockAsync(cancellationToken)) { ProjectRootElement rootElement = await access.GetProjectXmlAsync(project.FullPath, cancellationToken); // Deliberately not async to reduce the type of // code you can run while holding the lock. return(action(rootElement)); } }
public async Task <TResult> OpenProjectForReadAsync <TResult>(ConfiguredProject project, Func <Project, TResult> action, CancellationToken cancellationToken = default) { Requires.NotNull(project, nameof(project)); Requires.NotNull(project, nameof(action)); using (ProjectLockReleaser access = await _projectLockService.ReadLockAsync(cancellationToken)) { Project evaluatedProject = await access.GetProjectAsync(project, cancellationToken) .ConfigureAwait(true); // Deliberately not async to reduce the type of // code you can run while holding the lock. return(action(evaluatedProject)); } }