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


C# Project.Load方法代码示例

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


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

示例1: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		/// <returns></returns>
		public override bool Execute() {
			foreach (ITaskItem projectTaskItem in this.Projects) {
				this.Log.LogMessage("Fixing up the {0} sample for shipping as source code.", Path.GetFileNameWithoutExtension(projectTaskItem.ItemSpec));

				var project = new Project();
				Uri projectUri = new Uri(projectTaskItem.GetMetadata("FullPath"));
				project.Load(projectTaskItem.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);

				if (this.RemoveImportsStartingWith != null && this.RemoveImportsStartingWith.Length > 0) {
					project.Imports.Cast<Import>()
						.Where(import => this.RemoveImportsStartingWith.Any(start => import.ProjectPath.StartsWith(start, StringComparison.OrdinalIgnoreCase)))
						.ToList()
						.ForEach(import => project.Imports.RemoveImport(import));
				}

				if (this.AddReferences != null) {
					foreach (var reference in this.AddReferences) {
						BuildItem item = project.AddNewItem("Reference", reference.ItemSpec);
						foreach (DictionaryEntry metadata in reference.CloneCustomMetadata()) {
							item.SetMetadata((string)metadata.Key, (string)metadata.Value);
						}
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:33,代码来源:FixupShippingToolSamples.cs

示例2: Execute

		public override bool Execute() {
			if (this.ProjectReferences.Length != this.References.Length) {
				this.Log.LogError("ProjectReferences and References arrays do not have matching lengths.");
			}

			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);

				var projectReferences = doc.EvaluatedItems.OfType<BuildItem>().Where(item => item.Name == "ProjectReference");
				var matchingReferences = from reference in projectReferences
										 join refToRemove in this.ProjectReferences on reference.Include equals refToRemove.ItemSpec
										 let addIndex = Array.IndexOf(this.ProjectReferences, refToRemove)
										 select new { Remove = reference, Add = this.References[addIndex] };
				foreach (var matchingReference in matchingReferences) {
					this.Log.LogMessage("Removing project reference to \"{0}\" from \"{1}\".", matchingReference.Remove.Include, project.ItemSpec);
					doc.RemoveItem(matchingReference.Remove);
					if (matchingReference.Add.ItemSpec != "REMOVE") {
						this.Log.LogMessage("Adding assembly reference to \"{0}\" to \"{1}\".", matchingReference.Add.ItemSpec, project.ItemSpec);
						var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(matchingReference.Add.ItemSpec), true);
						newReference.SetMetadata("HintPath", matchingReference.Add.ItemSpec);
					}
				}

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:29,代码来源:ChangeProjectReferenceToAssemblyReference.cs

示例3: 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

示例4: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			foreach (var projectTaskItem in this.Projects) {
				var project = new Project();
				project.Load(projectTaskItem.ItemSpec);

				foreach (var projectItem in this.Items) {
					string itemType = projectItem.GetMetadata("ItemType");
					if (string.IsNullOrEmpty(itemType)) {
						itemType = "None";
					}
					BuildItem newItem = project.AddNewItem(itemType, projectItem.ItemSpec, false);
					var customMetadata = projectItem.CloneCustomMetadata();
					foreach (DictionaryEntry entry in customMetadata) {
						string value = (string)entry.Value;
						if (value.Length > 0) {
							newItem.SetMetadata((string)entry.Key, value);
						}
					}
				}

				project.Save(projectTaskItem.ItemSpec);
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:28,代码来源:AddProjectItems.cs

示例5: MsVisitProjects

		void MsVisitProjects(VisitProject visitor)
		{
			Engine e = new Engine(RuntimeEnvironment.GetRuntimeDirectory());
            if(e.GetType().Assembly.GetName().Version.Major == 2)
				try { e.GlobalProperties.SetProperty("MSBuildToolsPath", RuntimeEnvironment.GetRuntimeDirectory()); }
				catch { }

			foreach (FileInfo file in _projects)
			{
				Project prj = new Project(e);
				try
				{
					prj.Load(file.FullName);
				}
				catch (Exception ex)
				{
					Console.Error.WriteLine("Unable to open project: {0}", file);
					Log.Verbose(ex.ToString());
					continue;
				}

				visitor(new MsBuildProject(prj));
				e.UnloadProject(prj);
			}
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:25,代码来源:ProjectVisitor.cs

示例6: Load

 public virtual IDisposable Load(Project project, string file)
 {
     var backup = Directory.GetCurrentDirectory();
     Directory.SetCurrentDirectory(Path.GetDirectoryName(Path.GetFullPath(file)));
     project.Load(Path.GetFileName(file));
     return Disposable.Create(() => Directory.SetCurrentDirectory(backup));
 }
开发者ID:redrezo,项目名称:gradle-msbuild-plugin,代码行数:7,代码来源:PlatformProjectHelper.cs

示例7: MSBuildProject

        //=====================================================================
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="projectFile">The MSBuild project to load</param>
        public MSBuildProject(string projectFile)
        {
            msBuildProject = new Project(Engine.GlobalEngine);

            if(!File.Exists(projectFile))
                throw new BuilderException("BE0051", "The specified project " +
                    "file does not exist: " + projectFile);

            if(Path.GetExtension(projectFile).ToUpperInvariant() == ".VCPROJ")
                throw new BuilderException("BE0068", "Incompatible Visual " +
                    "Studio project file format.  See error code help topic " +
                    "for more information.\r\nC++ project files prior to Visual " +
                    "Studio 2010 are not currently supported.");

            try
            {
                msBuildProject.Load(projectFile);
            }
            catch (InvalidProjectFileException ex)
            {
                // Some MSBuild 4.0 projects cannot be loaded yet.  Their
                // targets must be added as individual documentation sources
                // and reference items.
                if(reInvalidAttribute.IsMatch(ex.Message))
                    throw new BuilderException("BE0068", "Incompatible Visual " +
                        "Studio project file format.  See error code help topic " +
                        "for more information.\r\nThis project may be for a " +
                        "newer version of MSBuild and cannot be loaded.  " +
                        "Error message:", ex);

                throw;
            }
        }
开发者ID:codemonster234,项目名称:scbuilder,代码行数:38,代码来源:MSBuildProject.cs

示例8: LoadSpecFlowProjectFromMsBuild

        public static SpecFlowProject LoadSpecFlowProjectFromMsBuild(string projectFile)
        {
            projectFile = Path.GetFullPath(projectFile);
            Project project = new Project();
            project.Load(projectFile, ProjectLoadSettings.IgnoreMissingImports);

            string projectFolder = Path.GetDirectoryName(projectFile);

            SpecFlowProject specFlowProject = new SpecFlowProject();
            specFlowProject.ProjectFolder = projectFolder;
            specFlowProject.ProjectName = Path.GetFileNameWithoutExtension(projectFile);
            specFlowProject.AssemblyName = project.GetEvaluatedProperty("AssemblyName");
            specFlowProject.DefaultNamespace = project.GetEvaluatedProperty("RootNamespace");

            var items = project.GetEvaluatedItemsByName("None").Cast<BuildItem>()
                .Concat(project.GetEvaluatedItemsByName("Content").Cast<BuildItem>());
            foreach (BuildItem item in items)
            {
                var extension = Path.GetExtension(item.FinalItemSpec);
                if (extension.Equals(".feature", StringComparison.InvariantCultureIgnoreCase))
                {
                    var featureFile = new SpecFlowFeatureFile(item.FinalItemSpec);
                    var ns = item.GetEvaluatedMetadata("CustomToolNamespace");
                    if (!String.IsNullOrEmpty(ns))
                        featureFile.CustomNamespace = ns;
                    specFlowProject.FeatureFiles.Add(featureFile);
                }

                if (Path.GetFileName(item.FinalItemSpec).Equals("app.config", StringComparison.InvariantCultureIgnoreCase))
                {
                    GeneratorConfigurationReader.UpdateConfigFromFile(specFlowProject.GeneratorConfiguration, Path.Combine(projectFolder, item.FinalItemSpec));
                }
            }
            return specFlowProject;
        }
开发者ID:xerxesb,项目名称:SpecFlow,代码行数:35,代码来源:MsBuildProjectReader.cs

示例9: Refresh

		public void Refresh ()
		{
			RunSTA (delegate
			{
				project = new Project (engine);
				project.Load (file);
			});
		}
开发者ID:Tak,项目名称:monodevelop-novell,代码行数:8,代码来源:ProjectBuilder.cs

示例10: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
						Project project = new Project();
						project.Load(taskItem.ItemSpec);
						project.DefaultToolsVersion = "3.5";

						if (this.DowngradeMvc2ToMvc1) {
							string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
							if (!string.IsNullOrEmpty(projectTypeGuids)) {
								projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
								project.SetProperty("ProjectTypeGuids", projectTypeGuids);
							}
						}

						// Web projects usually have an import that includes these substrings
						foreach (Import import in project.Imports) {
							import.ProjectPath = import.ProjectPath
								.Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
								.Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
						}

						// VS2010 won't let you have a System.Core reference, but VS2008 requires it.
						BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
						if (!references.Cast<BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase))) {
							project.AddNewItem("Reference", "System.Core");
						}

						project.Save(taskItem.ItemSpec);
						break;
					case ProjectClassification.VS2010Solution:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
						string[] contents = File.ReadAllLines(taskItem.ItemSpec);
						if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
							contents[2] != "# Visual Studio 2010") {
							this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
							break;
						}

						contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
						contents[2] = "# Visual Studio 2008";

						for (int i = 3; i < contents.Length; i++) {
							contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
						}

						File.WriteAllLines(taskItem.ItemSpec, contents);
						break;
					default:
						this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
						break;
				}
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:61,代码来源:DowngradeProjects.cs

示例11: Main

        public static void Main(string[] args)
        {
            var parser = new Parser(new Worm.WormFactory());
            string workingDir = Directory.GetCurrentDirectory();

            DirectoryInfo libRoot = Directory.GetParent(workingDir).Parent.Parent.GetDirectories("fullflow-lib")[0];
            string modelProjectFile = String.Format("{0}/fullflow-lib.csproj", libRoot.FullName);

            PocoModel model = parser.Parse(modelProjectFile);

            foreach (PocoEntity entity in model.Entities)
            {
                Console.WriteLine("DbFactory: {0}", entity.DbFactory.GetType().Name);
                Console.WriteLine("PocoClassName: {0}", entity.PocoClassName);
                Console.WriteLine("PocoFilename: {0}", entity.PocoFilename);
                Console.WriteLine("PocoNamespace: {0}", entity.PocoNamespace);
                Console.WriteLine("TableName: {0}", entity.TableName);
                Console.WriteLine();

                foreach (PocoField field in entity.Fields)
                {
                    Console.WriteLine("AccessModifier: {0}", field.AccessModifier);
                    Console.WriteLine("AllowNull: {0}", field.AllowNull);
                    Console.WriteLine("ColumnName: {0}", field.ColumnName);
                    Console.WriteLine("HasGetter: {0}", field.HasGetter);
                    Console.WriteLine("HasSetter: {0}", field.HasSetter);
                    Console.WriteLine("IdGenerator: {0}", field.IdGenerator);
                    Console.WriteLine("IsEnum: {0}", field.IsEnum);
                    Console.WriteLine("IsPrimaryKey: {0}", field.IsPrimaryKey);
                    Console.WriteLine("Name: {0}", field.Name);
                    Console.WriteLine("StorageType: {0}", field.StorageType);
                    Console.WriteLine("Type: {0}", field.Type);
                    Console.WriteLine();
                }

                Console.WriteLine();
            }

            Engine eng = new Engine();
            Project proj = new Project(eng);
            proj.Load(modelProjectFile);
            BuildItemGroup compileBuildItemGroup = GetCompileIncludeBuildItemGroup(proj);

            var writer = new DbClassWriter(new WormFactory());
            foreach (PocoEntity entity in model.Entities)
            {
                CodeFile cf = writer.Generate(entity);
                //cf.Filename = cf.Filename.Replace("fullflowlib", "fullflow-lib");
                WriteCodeFile(libRoot, cf);
                AddFileToProject(compileBuildItemGroup, cf);
            }

            proj.Save(modelProjectFile);

            // compile the project again
            parser.Parse(modelProjectFile);
        }
开发者ID:pingvinen,项目名称:worm,代码行数:57,代码来源:Program.cs

示例12: CompileProject

        public Assembly CompileProject(string projectFileName)
        {
            Assembly existing;
            if (Compilations.TryGetValue(Path.GetFullPath(projectFileName), out existing))
            {
                return existing;
            }

            var project = new Microsoft.Build.BuildEngine.Project();
            project.Load(projectFileName);

            var projectName = Environment.NameTable.GetNameFor(project.EvaluatedProperties["AssemblyName"].Value);
            var projectPath = project.FullFileName;
            var compilerOptions = new SpecSharpOptions();
            var assemblyReferences = new List<IAssemblyReference>();
            var moduleReferences = new List<IModuleReference>();
            var programSources = new List<SpecSharpSourceDocument>();
            var assembly = new SpecSharpAssembly(projectName, projectPath, Environment, compilerOptions, assemblyReferences, moduleReferences, programSources);
            var helper = new SpecSharpCompilationHelper(assembly.Compilation);

            Compilations[Path.GetFullPath(projectFileName)] = assembly;

            assemblyReferences.Add(Environment.LoadAssembly(Environment.CoreAssemblySymbolicIdentity));
            project.Build("ResolveAssemblyReferences");
            foreach (BuildItem item in project.GetEvaluatedItemsByName("ReferencePath"))
            {
                var assemblyName = new System.Reflection.AssemblyName(item.GetEvaluatedMetadata("FusionName"));
                var name = Environment.NameTable.GetNameFor(assemblyName.Name);
                var culture = assemblyName.CultureInfo != null ? assemblyName.CultureInfo.Name : "";
                var version = assemblyName.Version == null ? new Version(0, 0) : assemblyName.Version;
                var token = assemblyName.GetPublicKeyToken();
                if (token == null) token = new byte[0];
                var location = item.FinalItemSpec;
                var identity = new AssemblyIdentity(name, culture, version, token, location);
                var reference = Environment.LoadAssembly(identity);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("ProjectReference"))
            {
                var name = Environment.NameTable.GetNameFor(Path.GetFileNameWithoutExtension(item.FinalItemSpec));
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var reference = CompileProject(location);
                assemblyReferences.Add(reference);
            }

            foreach (BuildItem item in project.GetEvaluatedItemsByName("Compile"))
            {
                var location = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(project.FullFileName), item.FinalItemSpec));
                var name = Environment.NameTable.GetNameFor(location);
                var programSource = new SpecSharpSourceDocument(helper, name, location, File.ReadAllText(location));
                programSources.Add(programSource);
            }

            return assembly;
        }
开发者ID:dbremner,项目名称:specsharp,代码行数:56,代码来源:MSBuildCompiler.cs

示例13: LoadProjectFromFile

        // public methods...
        public void LoadProjectFromFile(string prjPath)
        {
            if (prjPath == null)
                throw new ArgumentNullException("prjPath");

            //string msBuildPath = GetDotNetRoot();
            Engine engine = new Engine(); //msBuildPath);
            _Project = new Project(engine);
            _Project.Load(prjPath);
        }
开发者ID:kevinmiles,项目名称:dxcorecommunityplugins,代码行数:11,代码来源:MsBuildProjectLoader.cs

示例14: Execute

		public override bool Execute() {
			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);
				
				var reference = doc.GetEvaluatedItemsByName("Reference").OfType<BuildItem>().
					Where(item => string.Equals(item.GetMetadata("HintPath"), OldReference, StringComparison.OrdinalIgnoreCase)).Single();
				reference.SetMetadata("HintPath", NewReference);

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:hnlshzx,项目名称:DotNetOpenAuth,代码行数:14,代码来源:ChangeAssemblyReference.cs

示例15: Execute

		public override bool Execute() {
			foreach (var project in Projects) {
				Project doc = new Project();
				doc.Load(project.ItemSpec);
				
				var projectReference = doc.EvaluatedItems.OfType<BuildItem>().Where(
					item => item.Name == "ProjectReference" && item.Include == ProjectReference).Single();
				doc.RemoveItem(projectReference);

				var newReference = doc.AddNewItem("Reference", Path.GetFileNameWithoutExtension(Reference));
				newReference.SetMetadata("HintPath", Reference);

				doc.Save(project.ItemSpec);
			}

			return true;
		}
开发者ID:Belxjander,项目名称:Asuna,代码行数:17,代码来源:ChangeProjectReferenceToAssemblyReference.cs


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