(global::System.StringComparer.Ordinal); var exactExclusions = new global::System.Collections.Generic.HashSet(global::System.StringComparer.Ordinal); var prefixExclusions = new global::System.Collections.Generic.List(); var namespacePattern = new global::System.Text.RegularExpressions.Regex( @"^\s*namespace\s+([A-Za-z_][A-Za-z0-9_.]*)\s*(?:;|\{)", global::System.Text.RegularExpressions.RegexOptions.Compiled); if (ExcludedNamespaces != null) { foreach (var excludedNamespace in ExcludedNamespaces) { if (!string.IsNullOrWhiteSpace(excludedNamespace.ItemSpec)) { exactExclusions.Add(excludedNamespace.ItemSpec.Trim()); } } } if (ExcludedNamespacePrefixes != null) { foreach (var excludedPrefix in ExcludedNamespacePrefixes) { if (!string.IsNullOrWhiteSpace(excludedPrefix.ItemSpec)) { prefixExclusions.Add(excludedPrefix.ItemSpec.Trim()); } } } foreach (var sourceFile in SourceFiles) { var path = sourceFile.ItemSpec; if (!global::System.IO.File.Exists(path)) { continue; } foreach (var line in global::System.IO.File.ReadLines(path)) { var match = namespacePattern.Match(line); if (!match.Success) { continue; } var namespaceName = match.Groups[1].Value; if (!namespaceName.StartsWith("GFramework.", global::System.StringComparison.Ordinal)) { continue; } if (exactExclusions.Contains(namespaceName)) { continue; } var excludedByPrefix = false; foreach (var prefix in prefixExclusions) { if (namespaceName.StartsWith(prefix, global::System.StringComparison.Ordinal)) { excludedByPrefix = true; break; } } if (!excludedByPrefix) { discoveredNamespaces.Add(namespaceName); } } } static string Escape(string value) { return global::System.Security.SecurityElement.Escape(value) ?? value; } var directory = global::System.IO.Path.GetDirectoryName(OutputFile); if (!string.IsNullOrEmpty(directory)) { global::System.IO.Directory.CreateDirectory(directory); } var builder = new global::System.Text.StringBuilder(); var msbuildPropertyOpen = new string(new[] { '$', '(' }); var msbuildItemOpen = new string(new[] { '@', '(' }); builder.AppendLine(""); builder.AppendLine(" "); builder.AppendLine(" "); builder.AppendLine(" "); builder.Append(" "); foreach (var namespaceName in discoveredNamespaces) { builder.Append(" <"); builder.Append(NamespaceItemName); builder.Append(" Include=\""); builder.Append(Escape(namespaceName)); builder.AppendLine("\" />"); } builder.Append(" <"); builder.Append(NamespaceItemName); builder.Append(" Remove=\""); builder.Append(msbuildItemOpen); builder.AppendLine("GFrameworkExcludedUsing)\" />"); builder.Append(" "); builder.AppendLine(" "); builder.AppendLine(""); global::System.IO.File.WriteAllText(OutputFile, builder.ToString(), new global::System.Text.UTF8Encoding(false)); Log.LogMessage(global::Microsoft.Build.Framework.MessageImportance.Low, $"Generated {discoveredNamespaces.Count} transitive global usings for {OutputFile}."); ]]> <_GFrameworkTransitiveGlobalUsingsEnabled Condition="'$(EnableGFrameworkPackageTransitiveGlobalUsings)' == 'true' and '$(IsPackable)' != 'false'">true <_GFrameworkTransitiveGlobalUsingsPrimaryTargetFramework Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true' and '$(TargetFrameworks)' != ''">$([System.String]::Copy('$(TargetFrameworks)').Split(';')[0]) <_GFrameworkTransitiveGlobalUsingsGenerationBuild Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true' and ('$(TargetFrameworks)' == '' or '$(TargetFramework)' == '$(_GFrameworkTransitiveGlobalUsingsPrimaryTargetFramework)')">true <_GFrameworkTransitiveGlobalUsingsPackageId Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true' and '$(PackageId)' != ''">$(PackageId) <_GFrameworkTransitiveGlobalUsingsPackageId Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true' and '$(_GFrameworkTransitiveGlobalUsingsPackageId)' == ''">$(AssemblyName) <_GFrameworkTransitiveGlobalUsingsOutputFile Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true'">$(BaseIntermediateOutputPath)gframework/$(_GFrameworkTransitiveGlobalUsingsPackageId).props <_GFrameworkTransitiveGlobalUsingsItemName Condition="'$(_GFrameworkTransitiveGlobalUsingsEnabled)' == 'true'">_$([System.Text.RegularExpressions.Regex]::Replace('$(MSBuildProjectName)', '[^A-Za-z0-9_]', '_'))_TransitiveUsing