using Nuke.Common.ProjectModel; public static class ProjectsHelper { private const string SrcDirName = "src"; private const string TestDirName = "test"; private const string NativeProjectMarker = "Native"; // Contains word Native private const string TestsProjectMarker = "Tests"; // Ends with word Tests private const string NetFrameworkMarker = ".NetFramework"; // Ends with word .NetFramework private const string CoreProjectSelector = "OpenTelemetry.AutoInstrumentation*"; private const string TestApplicationSelector = "TestApplication.*"; private const string TestLibrarySelector = "TestLibrary.*"; public static IEnumerable GetManagedSrcProjects(this Solution solution) { return solution .GetProjects(CoreProjectSelector) .Where(x => // Should contain in the src directory x.Directory.ToString().Contains(SrcDirName) && // Should not be native projects !x.Name.Contains(NativeProjectMarker)); } public static IEnumerable GetNativeSrcProjects(this Solution solution) { return solution .GetProjects(CoreProjectSelector) .Where(x => // Should contain in the src directory x.Directory.ToString().Contains(SrcDirName) && // Should be native projects x.Name.Contains(NativeProjectMarker)); } public static IEnumerable GetManagedTestProjects(this Solution solution) { return solution.GetManagedUnitTestProjects() .Concat(new[] { solution.GetManagedIntegrationTestProject() }); } public static IEnumerable GetManagedUnitTestProjects(this Solution solution) { return solution .GetProjects(CoreProjectSelector) .Where(x => // Should contain in the test directory x.Directory.ToString().Contains(TestDirName) && // Should not be native projects !x.Name.Contains(NativeProjectMarker) && // Should be test projects x.Name.EndsWith(TestsProjectMarker)); } public static Project GetManagedIntegrationTestProject(this Solution solution) { return solution.GetProject(Projects.Tests.IntegrationTests); } public static IEnumerable GetTestApplications(this Solution solution) { var testApplications = solution.GetProjects(TestApplicationSelector); var testLibraries = solution.GetProjects(TestLibrarySelector); return testApplications.Concat(testLibraries); } public static Project GetTestMock(this Solution solution) { return solution.GetProject(Projects.Mocks.AutoInstrumentationMock); } public static Project GetBenchmarks(this Solution solution) { return solution.GetProject(Projects.Benchmarks.AutoInstrumentationBenchmarks); } public static IEnumerable GetWindowsOnlyTestApplications(this Solution solution) { return solution .GetTestApplications() .Where(x => x.Name.EndsWith(NetFrameworkMarker)); } public static IEnumerable GetCrossPlatformTestApplications(this Solution solution) { return solution .GetTestApplications() .Where(x => !x.Name.EndsWith(NetFrameworkMarker)); } public static Project GetNativeTestProject(this Solution solution) { return solution.GetProject(Projects.Tests.AutoInstrumentationNativeTests); } public static IEnumerable GetCrossPlatformManagedProjects(this Solution solution) { return solution.GetManagedSrcProjects() .Concat(solution.GetManagedTestProjects()) .Concat(solution.GetCrossPlatformTestApplications()) .Concat(new[] { solution.GetTestMock() }) .Concat(new[] { solution.GetBenchmarks() }); } public static IEnumerable GetNativeProjects(this Solution solution) { return solution.GetNativeSrcProjects() .Concat(new[] { solution.GetNativeTestProject() }); } }