Пример #1
0
        public void BuildProjectFilesInParallel2()
        {
            string[] fileNames = new string[10];
            string[] fileNames2 = new string[10];
            string[] fileNamesLeafs = new string[10];
            string[] childTraversals = new string[10];
            string parentTraversal = TraversalProjectFile("CTrav");
            string traversalProject = TraversalProjectFile("ABC");

            string[][] targetNamesPerProject = new string[fileNames.Length][];
            IDictionary[] targetOutPutsPerProject = new IDictionary[fileNames.Length];
            BuildPropertyGroup[] globalPropertiesPerProject = new BuildPropertyGroup[fileNames.Length];
            
            string[] tempfilesToDelete = new string[fileNames.Length];
            string[] tempfilesToDelete2 = new string[fileNames.Length];
            string[] tempfilesToDelete3 = new string[fileNames.Length];
            string[] tempfilesToDelete4 = new string[fileNames.Length];
            Engine engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    string[] ProjectFiles1 = CreateGlobalPropertyProjectFileWithExtension("ABC");
                    string[] ProjectFiles2 = CreateGlobalPropertyProjectFileWithExtension("DEF");
                    string[] FileNamesLeafs = CreateGlobalPropertyProjectFileWithExtension("LEAF");
                    string[] ChildTraversals = CreateSingleProjectTraversalFileWithExtension(FileNamesLeafs[0],"CTrav");

                    fileNames[i] = ProjectFiles1[0];
                    fileNames2[i] = ProjectFiles2[0];
                    fileNamesLeafs[i] = FileNamesLeafs[0];
                    childTraversals[i] = ChildTraversals[0];
                    
                    tempfilesToDelete[i] = ProjectFiles1[1];
                    tempfilesToDelete2[i] = ProjectFiles2[1];
                    tempfilesToDelete3[i] = FileNamesLeafs[1];
                    tempfilesToDelete4[i] = ChildTraversals[1];
                    targetNamesPerProject[i] = new string[] { "Build" };
                }


                // Try building a traversal project that had other traversals
                
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFile(parentTraversal, new string[] { "Build" }, new BuildPropertyGroup(), null, BuildSettings.None, "3.5");
                engine.Shutdown();

                 engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                // Try building the same traversal project on the same engine one after another
                engine.BuildProjectFile(traversalProject);
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();

                // Try building the same set of project files on the same engine one after another
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.Shutdown();

                // Try building a set of project files, then the same set as a traversal on the same engine
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFiles(fileNames2, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();


                // Try building a traversal, then the same files which are in the traversal in parallel on the same engine
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFile(traversalProject);
                engine.BuildProjectFiles(fileNames2, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.Shutdown();
                /* Do the same as above using single proc */

                // Try building the same traversal project on the same engine one after another
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 1, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFile(traversalProject);
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();

                // Try building the same set of project files on the same engine one after another
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 1, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.Shutdown();

                // Try building a set of project files, then the same set as a traversal on the same engine
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 1, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFiles(fileNames2, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();

                // Try building a traversal, then the same files which are in the traversal in parallel on the same engine
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFile(traversalProject);
                engine.BuildProjectFiles(fileNames2, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
            }
            finally
            {
                engine.Shutdown();
                for (int i = 0; i < fileNames.Length; i++)
                {
                    File.Delete(fileNames[i]);
                    File.Delete(fileNames2[i]);
                    File.Delete(fileNamesLeafs[i]);
                    File.Delete(childTraversals[i]);
                    File.Delete(tempfilesToDelete[i]);
                    File.Delete(tempfilesToDelete2[i]);
                    File.Delete(tempfilesToDelete3[i]);
                    File.Delete(tempfilesToDelete4[i]);
                }
                File.Delete(traversalProject);
            }
        }
Пример #2
0
        public void BuildProjectFilesInParallel()
        {

            //Gets the currently loaded assembly in which the specified class is defined
            Assembly engineAssembly = Assembly.GetAssembly(typeof(Engine));
            string loggerClassName = "Microsoft.Build.BuildEngine.ConfigurableForwardingLogger";
            string loggerAssemblyName = engineAssembly.GetName().FullName;
            LoggerDescription forwardingLoggerDescription = new LoggerDescription(loggerClassName, loggerAssemblyName, null, null, LoggerVerbosity.Normal);

            string[] fileNames = new string[10];
            string traversalProject = TraversalProjectFile("ABC");
            string[][] targetNamesPerProject = new string[fileNames.Length][];
            IDictionary[] targetOutPutsPerProject = new IDictionary[fileNames.Length];
            BuildPropertyGroup[] globalPropertiesPerProject = new BuildPropertyGroup[fileNames.Length];
            string[] tempfilesToDelete = new string[fileNames.Length];
            Engine engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+AppDomain.CurrentDomain.BaseDirectory);
            engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
            try
            {
                for (int i = 0; i < fileNames.Length; i++)
                {
                    string[] ProjectFiles1 = CreateGlobalPropertyProjectFileWithExtension("ABC");
                    fileNames[i] = ProjectFiles1[0];
                    tempfilesToDelete[i] = ProjectFiles1[1];
                    targetNamesPerProject[i] = new string[] { "Build" };
                }

                // Test building a traversal
              
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();
                
                // Test building the same set of files in parallel
                Console.Out.WriteLine("1:"+Process.GetCurrentProcess().MainModule.FileName);
                Console.Out.WriteLine("2:" + AppDomain.CurrentDomain.BaseDirectory);
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterDistributedLogger(new ConsoleLogger(LoggerVerbosity.Normal), forwardingLoggerDescription);
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);
                engine.Shutdown();

                // Do the same using singleproc
                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 4, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFile(traversalProject);
                engine.Shutdown();

                engine = new Engine(null, ToolsetDefinitionLocations.ConfigurationFile | ToolsetDefinitionLocations.Registry, 1, "msbuildlocation="+ AppDomain.CurrentDomain.BaseDirectory);
                engine.RegisterLogger(new ConsoleLogger(LoggerVerbosity.Normal));
                engine.BuildProjectFiles(fileNames, targetNamesPerProject, globalPropertiesPerProject, targetOutPutsPerProject, BuildSettings.None, new string[fileNames.Length]);

            }
            finally
            {
                engine.Shutdown();
                for (int i = 0; i < fileNames.Length; i++)
                {
                    File.Delete(fileNames[i]);
                    File.Delete(tempfilesToDelete[i]);
                }
                File.Delete(traversalProject);
            }
        }