public Task SetProjectGuidAsync(Guid value) { // Avoid searching for the <ProjectGuid/> if we've already checked previously in GetProjectGuidAsync. // This handles project open, avoids us needed to take another read-lock during setting of it. // // Technically a project could add a <ProjectGuid/> latter down the track by editing the project or // reloading from disk, however, both the solution, CPS and other components within Visual Studio // do not handle the GUID changing underneath them. if (_isPersistedInProject == false) { return(Task.CompletedTask); } return(_projectAccessor.OpenProjectXmlForUpgradeableReadAsync(_project, async(projectXml, cancellationToken) => { ProjectPropertyElement property = FindProjectGuidProperty(projectXml); if (property != null) { _isPersistedInProject = true; // Avoid touching the project file unless the actual GUID has changed, regardless of format if (!TryParseGuid(property, out Guid result) || value != result) { await _projectAccessor.OpenProjectXmlForWriteAsync(_project, (root) => { property.Value = ProjectCollection.Escape(value.ToString("B").ToUpperInvariant()); }).ConfigureAwait(true); } } else { _isPersistedInProject = false; } })); }
public override async Task <string> OnSetPropertyValueAsync( string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary <string, string> dimensionalConditions = null) { if (await _helper.TrySetPropertyAsync(unevaluatedPropertyValue, defaultProperties)) { return(null); } await _projectAccessor.OpenProjectXmlForWriteAsync(_unconfiguredProject, projectXml => _helper.SetProperty(unevaluatedPropertyValue, projectXml)); return(null); }
public void Add(string bstrImport) { if (!_importsList.IsPresent(bstrImport)) { _threadingService.ExecuteSynchronously(async() => { await _projectAccessor.OpenProjectXmlForWriteAsync(_unconfiguredProjectVSServices.Project, project => { project.AddItem(ImportItemTypeName, bstrImport); }); await _importsList.ReceiveLatestSnapshotAsync(); }); } else { throw new ArgumentException(string.Format("{0} - Namespace is already imported", bstrImport), nameof(bstrImport)); } }