当前位置: 首页>>代码示例>>C#>>正文


C# Engine.BuildProject方法代码示例

本文整理汇总了C#中Microsoft.Build.BuildEngine.Engine.BuildProject方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.BuildProject方法的具体用法?C# Engine.BuildProject怎么用?C# Engine.BuildProject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Build.BuildEngine.Engine的用法示例。


在下文中一共展示了Engine.BuildProject方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CompileSingle

        protected override bool CompileSingle(Engine engine, AbstractBaseGenerator gen, string workingPath, string target)
        {
            try
            {
                using (log4net.NDC.Push("Compiling " + gen.Description))
                {
                    Log.DebugFormat("Loading MsBuild Project");
                    var proj = new Project(engine);
                    proj.Load(Helper.PathCombine(workingPath, gen.TargetNameSpace, gen.ProjectFileName));

                    Log.DebugFormat("Compiling");
                    if (engine.BuildProject(proj, target))
                    {
                        return true;
                    }
                    else
                    {
                        Log.ErrorFormat("Failed to compile {0}", gen.Description);
                        return false;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed compiling " + gen.Description, ex);
                return false;
            }
        }
开发者ID:jrgcubano,项目名称:zetbox,代码行数:28,代码来源:MsBuildCompiler.cs

示例2: GetReferenceAssemblies

        /// <summary>
        /// Adds the assembly references from the given project to the given list
        /// </summary>
        /// <param name="projectPath">Absolute path to the project file itself</param>
        /// <param name="assemblies">List to add assembly names to</param>
        public static void GetReferenceAssemblies(string projectPath, IList<string> assemblies)
        {
            projectPath = Path.GetFullPath(projectPath);

            Engine engine = new Engine();
            var project = LoadProject(projectPath, engine);

            // Ask to be told of generated outputs
            IDictionary targetOutputs = new Dictionary<object, object>();
            string[] buildTargets = new string[] { "ResolveAssemblyReferences" };

            bool success = engine.BuildProject(project, buildTargets, targetOutputs);
            if (success)
            {
                BuildItemGroup buildItems = project.EvaluatedItems;
                foreach (BuildItem buildItem in buildItems)
                {
                    string otherProjectPath = buildItem.FinalItemSpec;
                    if (!Path.IsPathRooted(otherProjectPath))
                    {
                        otherProjectPath = Path.Combine(Path.GetDirectoryName(projectPath), otherProjectPath);
                    }

                    if (buildItem.Name.Equals("_ResolveAssemblyReferenceResolvedFiles", StringComparison.OrdinalIgnoreCase))
                    {
                        if (!assemblies.Contains(otherProjectPath))
                            assemblies.Add(otherProjectPath);
                    }
                    else if (buildItem.Name.Equals("ProjectReference", StringComparison.OrdinalIgnoreCase))
                    {
                        // Project references recursively extract references
                        string outputAssembly = GetOutputAssembly(otherProjectPath);

                        if (!string.IsNullOrEmpty(outputAssembly) && !assemblies.Contains(outputAssembly))
                            assemblies.Add(outputAssembly);
                    }
                }
            }
            MakeFullPaths(assemblies, Path.GetDirectoryName(projectPath));
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:45,代码来源:MsBuildHelper.cs

示例3: Execute


//.........这里部分代码省略.........
                if ((a is SubSystem) && !(b is SubSystem)) return -1;
                else if ((b is SubSystem) && !(a is SubSystem)) return 1;
                else return a.GetType().Name.CompareTo(b.GetType().Name);
            });

            RenderFeatureList(features, templateFields, renderers, fileItemGroup, phoneFileItemGroup, parameters);

            // Any added features?
            // HACK: This should be fixed soon, but meh... I'll get around to it
            List<Feature> addlFeatures = new List<Feature>();
            foreach (KeyValuePair<String, Feature> kv in classRep)
                if(!features.Contains(kv.Value))
                    addlFeatures.Add(kv.Value);
            RenderFeatureList(addlFeatures, templateFields, renderers, fileItemGroup, phoneFileItemGroup, parameters);

            // Save the project
            project.Save(Path.Combine(hostContext.Output, ProjectFileName) + ".csproj");
            #endregion

            // Compile?
            #region Compile this project

            // Does the user want to compile?
            if (parameters.ContainsKey("rimbapi-compile") && Convert.ToBoolean(parameters["rimbapi-compile"][0]))
            {
                string logPath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName()); // Create log
                Microsoft.Build.BuildEngine.FileLogger logger = new Microsoft.Build.BuildEngine.FileLogger();
                logger.Parameters = "logfile=" + logPath;
                engine.RegisterLogger(logger);

                System.Diagnostics.Trace.Write(String.Format("Compiling project (Build log {0})...", logPath), "information");

                // Compile
                if (engine.BuildProject(project))
                    System.Diagnostics.Trace.WriteLine("Success!", "information");
                else
                {
                    System.Diagnostics.Trace.WriteLine("Fail", "information");
                    throw new InvalidOperationException("Failed compilation, operation cannot continue");

                }
                engine.UnregisterAllLoggers();
                
            }
            #endregion

            #region Windows Phone

            if (makeWP7Proj)
            {

                // Setup project attributes
                pg = phoneProj.AddNewPropertyGroup(false);
                property = pg.AddNewProperty("Configuration", "Release");
                property.Condition = "'$(Configuration)' == ''";
                property = pg.AddNewProperty("Platform", "AnyCPU");
                property.Condition = "'$(Platform)' == ''";
                pg.AddNewProperty("ProductVersion", "10.0.20506");
                pg.AddNewProperty("SchemaVersion", "2.0");
                pg.AddNewProperty("ProjectGuid", Guid.NewGuid().ToString());
                pg.AddNewProperty("OutputType", "Library");
                pg.AddNewProperty("AppDesignerFolder", "Properties");
                pg.AddNewProperty("RootNamespace", parameters["rimbapi-target-ns"][0]);
                pg.AddNewProperty("AssemblyName", parameters["rimbapi-target-ns"][0] + ".Phone");
                pg.AddNewProperty("ProjectTypeGuids", "{C089C8C0-30E0-4E22-80C0-CE093F111A43};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}");
                pg.AddNewProperty("TargetFrameworkVersion", "v4.0");
开发者ID:oneminot,项目名称:everest,代码行数:67,代码来源:RimbaCsRenderer.cs

示例4: TestBuildProjectNull2

		public void TestBuildProjectNull2 ()
		{
			engine = new Engine (Consts.BinPath);
			engine.BuildProject (null, (string)null);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:EngineTest.cs

示例5: TestBuildProjectNull1

		public void TestBuildProjectNull1 ()
		{
			engine = new Engine (Consts.BinPath);
			engine.BuildProject (null, "foo");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:EngineTest.cs

示例6: TestBuildProject2

		public void TestBuildProject2 ()
		{
			engine = new Engine (Consts.BinPath);
			Project project = engine.CreateNewProject ();

			Assert.IsFalse (engine.BuildProject (project, (string)null), "#A1");
			Assert.IsFalse (engine.BuildProject (project, (string [])null), "#A2");
			Assert.IsFalse (engine.BuildProject (project, (string [])null, null), "#A3");
			Assert.IsFalse (engine.BuildProject (project, (string [])null, null, BuildSettings.None), "#A4");

			bool caught_exception = false;
			try {
				//null string in targetNames [] param
				engine.BuildProject (project, new string [] {null}, null);
			} catch {
				caught_exception = true;
			}
			if (!caught_exception)
				Assert.Fail ("Expected exception for Engine.BuildProject");
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:20,代码来源:EngineTest.cs

示例7: TestBuildProject1

		public void TestBuildProject1 ()
		{
			engine = new Engine (Consts.BinPath);
			engine.BuildProject (null);
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:5,代码来源:EngineTest.cs

示例8: windowsToolStripMenuItem_Click

        private void windowsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ComponentTypeContainer.UnloadAppDomain();
                //string msBuildPath = @"C:\Windows\Microsoft.NET\Framework\v3.5\";

                Microsoft.Build.BuildEngine.Engine engine = new Microsoft.Build.BuildEngine.Engine();
                // Instantiate a new FileLogger to generate build log
                Microsoft.Build.BuildEngine.FileLogger logger = new Microsoft.Build.BuildEngine.FileLogger();

                // Set the logfile parameter to indicate the log destination
                logger.Parameters = @"logfile=C:\temp\build.log";

                // Register the logger with the engine
                engine.RegisterLogger(logger);

                Microsoft.Build.BuildEngine.Project p = new Microsoft.Build.BuildEngine.Project(engine);
                p.Load(Path.Combine(_currentProject.Path, _currentProject.VisualStudioProjectPath));

                //bool success=p.Build("Rebuild");
                bool success = engine.BuildProject(p, "ReBuild");
                if (!success)
                {
                    DialogResult _res = MessageBox.Show("There was an error during build, Would you like to see the log?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (_res == DialogResult.Yes)
                    {
                        if (File.Exists(@"c:\temp\build.log"))
                            Process.Start("notepad.exe", @"c:\temp\build.log");
                        else
                            MessageBox.Show("Log file not found");
                    }
                }
            }
            catch (Exception err)
            {
                MilkshakeForm.ShowErrorMessage(err);
            }
        }
开发者ID:schminitz,项目名称:IceCreamXNA,代码行数:39,代码来源:MilkshakeForm.cs

示例9: GetSourceFiles

        /// <summary>
        /// Gets the source files used by the given project
        /// </summary>
        /// <param name="projectPath">Absolute path to the project file itself</param>
        public static List<string> GetSourceFiles(string projectPath)
        {
            List<string> items = new List<string>();

            projectPath = Path.GetFullPath(projectPath);

            Engine engine = new Engine();
            var project = LoadProject(projectPath, engine);

            ErrorLogger logger = new ErrorLogger();
            engine.RegisterLogger(logger);

            // Ask to be told of generated outputs
            IDictionary targetOutputs = new Dictionary<object, object>();
            string[] buildTargets = new string[] { "Build" };

            bool success = engine.BuildProject(project, buildTargets, targetOutputs);
            if (!success)
            {
                string message = string.Join(Environment.NewLine, logger.Errors.ToArray());
                Assert.Fail(message);
            }

            BuildItemGroup buildItems = project.EvaluatedItems;
            foreach (BuildItem buildItem in buildItems)
            {
                if (buildItem.Name.Equals("Compile", StringComparison.OrdinalIgnoreCase))
                {
                    items.Add(buildItem.FinalItemSpec);
                }
            }

            MakeFullPaths(items, Path.GetDirectoryName(projectPath));
            return items;
        }
开发者ID:OpenRIAServices,项目名称:OpenRiaServices,代码行数:39,代码来源:MsBuildHelper.cs

示例10: BuildProject

        private void BuildProject(IEnumerable<BuildItemFileInfo> buildItemFiles, Engine engine)
        {
            Microsoft.Build.BuildEngine.Project proj = engine.CreateNewProject();

            engine.RegisterLogger(new Log4NetMSBuildLogger(engine, proj));
            engine.RegisterLogger(new BuildLogMSBuildLogger(engine, proj));
            AssemblyName = Path.GetFileNameWithoutExtension(c_AssemblyName);
            proj.FullFileName = Path.Combine(LibraryPath, String.Format("{0}.csproj", AssemblyName));
            ConfigureProject(proj);

            BuildItemGroup items = proj.AddNewItemGroup();

            foreach (BuildItemFileInfo buildItemFile in buildItemFiles)
            {
                AddFileToProject(items, buildItemFile.Path, buildItemFile.Generator.MSBuildItemType);

                if (buildItemFile.Generator.DeployFile)
                    AddOutputFile(buildItemFile.Path);
            }

            proj.Save(Path.Combine(FullProjectDirectory, AssemblyName + ".csproj"));

            if (!engine.BuildProject(proj))
                throw new BuildException(String.Format(CultureInfo.CurrentUICulture, "Failed to build {0}", c_AssemblyName));

            string asmFileName = Path.Combine(OutputPath, c_AssemblyName);
            AddOutputFile(asmFileName);

            // deploy the associated .pdb, if it exists.
            string pdbFileName = Path.ChangeExtension(asmFileName, ".pdb");
            if (File.Exists(pdbFileName))
                AddOutputFile(pdbFileName);
        }
开发者ID:jboyce,项目名称:LinqToSData,代码行数:33,代码来源:SDataClientEntityDeploymentPackage.cs

示例11: Execute

		public void Execute ()
		{
			bool result = false;
			bool show_stacktrace = false;
			
			try {
				parameters.ParseArguments (args);
				show_stacktrace = (parameters.LoggerVerbosity == LoggerVerbosity.Detailed ||
					parameters.LoggerVerbosity == LoggerVerbosity.Diagnostic);
				
				if (parameters.DisplayVersion)
					ErrorUtilities.ShowVersion (false);
				
				engine  = new Engine (binPath);
				
				engine.GlobalProperties = this.parameters.Properties;
				
				if (!parameters.NoConsoleLogger) {
					printer = new ConsoleReportPrinter ();
					ConsoleLogger cl = new ConsoleLogger (parameters.LoggerVerbosity,
							printer.Print, printer.SetForeground, printer.ResetColor);

					cl.Parameters = parameters.ConsoleLoggerParameters;
					cl.Verbosity = parameters.LoggerVerbosity; 
					engine.RegisterLogger (cl);
				}
				
				foreach (LoggerInfo li in parameters.Loggers) {
					Assembly assembly;
					if (li.InfoType == LoadInfoType.AssemblyFilename)
						assembly = Assembly.LoadFrom (li.Filename);
					else
						assembly = Assembly.Load (li.AssemblyName);
					ILogger logger = (ILogger)Activator.CreateInstance (assembly.GetType (li.ClassName));
					logger.Parameters = li.Parameters;
					engine.RegisterLogger (logger); 
				}
				
				project = engine.CreateNewProject ();
				
				if (parameters.Validate) {
					if (parameters.ValidationSchema == null)
						project.SchemaFile = defaultSchema;
					else
						project.SchemaFile = parameters.ValidationSchema;
				}

				string projectFile = parameters.ProjectFile;
				if (!File.Exists (projectFile)) {
					ErrorUtilities.ReportError (0, String.Format ("Project file '{0}' not found.", projectFile));
					return;
				}

				project.Load (projectFile);
				
				string oldCurrentDirectory = Environment.CurrentDirectory;
				string dir = Path.GetDirectoryName (projectFile);
				if (!String.IsNullOrEmpty (dir))
					Directory.SetCurrentDirectory (dir);
				result = engine.BuildProject (project, parameters.Targets, null);
				Directory.SetCurrentDirectory (oldCurrentDirectory);
			}
			
			catch (InvalidProjectFileException ipfe) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ipfe.ToString () : ipfe.Message);
			}

			catch (InternalLoggerException ile) {
				ErrorUtilities.ReportError (0, show_stacktrace ? ile.ToString () : ile.Message);
			}

			catch (CommandLineException cle) {
				ErrorUtilities.ReportError(cle.ErrorCode, show_stacktrace ? cle.ToString() : cle.Message);
			}

			catch (Exception) {
				throw;
			}
			
			finally {
				if (engine != null)
					engine.UnregisterAllLoggers ();

				Environment.Exit (result ? 0 : 1);
			}

		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:87,代码来源:Main.cs


注:本文中的Microsoft.Build.BuildEngine.Engine.BuildProject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。