protected async Task <Document> GetOrCreateSuppressionsDocumentAsync(CancellationToken c) { int index = 1; var suppressionsFileName = s_globalSuppressionsFileName + Fixer.DefaultFileExtension; var suppressionsFilePath = GetSuppressionsFilePath(suppressionsFileName); Document suppressionsDoc = null; while (suppressionsDoc == null) { var hasDocWithSuppressionsName = false; foreach (var document in _project.Documents) { var filePath = document.FilePath; var fullPath = !string.IsNullOrEmpty(filePath) ? Path.GetFullPath(filePath) : filePath; if (fullPath == suppressionsFilePath) { // Existing global suppressions file, see if this file only has global assembly attributes. hasDocWithSuppressionsName = true; var t = await document.GetSyntaxTreeAsync(c).ConfigureAwait(false); var r = await t.GetRootAsync(c).ConfigureAwait(false); if (r.ChildNodes().All(n => Fixer.IsAttributeListWithAssemblyAttributes(n))) { suppressionsDoc = document; break; } } } if (suppressionsDoc == null) { if (hasDocWithSuppressionsName || File.Exists(suppressionsFilePath)) { index++; suppressionsFileName = s_globalSuppressionsFileName + index.ToString() + Fixer.DefaultFileExtension; suppressionsFilePath = GetSuppressionsFilePath(suppressionsFileName); } else { // Create an empty global suppressions file. suppressionsDoc = _project.AddDocument(suppressionsFileName, string.Empty); } } } return(suppressionsDoc); }