using System.Xml.Linq; string root = Path.GetFullPath(args.Length == 0 ? "." : args[0]); var allowed = new Dictionary>(StringComparer.Ordinal) { ["Domain"] = new(), ["Application"] = new() { "Domain" }, ["Infrastructure"] = new() { "Domain", "Application" }, ["Host"] = new() { "Domain", "Application", "Infrastructure" } }; int violations = 0; foreach (var item in allowed) { string path = Path.Combine(root, item.Key, item.Key + ".csproj"); var document = XDocument.Load(path); foreach (var reference in document.Descendants().Where(element => element.Name.LocalName == "ProjectReference")) { string include = (string?)reference.Attribute("Include") ?? throw new InvalidOperationException("Missing Include"); string targetPath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(path)!, include)); string target = Path.GetFileNameWithoutExtension(targetPath); string expectedPath = Path.Combine(root, target, target + ".csproj"); if (!item.Value.Contains(target) || targetPath != expectedPath) { violations++; Console.WriteLine($"violation:{item.Key}->{target}"); } } } Console.WriteLine($"projects:{allowed.Count}"); Console.WriteLine($"violations:{violations}"); return violations == 0 ? 0 : 1;