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


C# Evaluation.Project类代码示例

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


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

示例1: Project

        public Project(Solution solution, string title, string fileName)
        {
            AssembliesResolved = false;
            ReferencedAssemblies = new List<string>();
            CompilerSettings = new CompilerSettings();
            ReferencedProjects = new List<string>();
            Files = new List<File>();
            Solution = solution;
            Title = title;
            FileName = Path.GetFullPath(fileName);

            ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
            MsBuildProject = new Microsoft.Build.Evaluation.Project(fileName);

            AssemblyName = MsBuildProject.GetPropertyValue("AssemblyName");
            CompilerSettings.AllowUnsafeBlocks = MsBuildProject.GetPropertyAsBoolean("AllowUnsafeBlocks");
            CompilerSettings.CheckForOverflow = MsBuildProject.GetPropertyAsBoolean("CheckForOverflowUnderflow");
            var defineConstants = MsBuildProject.GetPropertyValue("DefineConstants");

            foreach (string symbol in defineConstants.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                CompilerSettings.ConditionalSymbols.Add(symbol.Trim());
            }

            foreach (var sourceCodeFile in MsBuildProject.GetItems("Compile"))
            {
                Files.Add(new File(this, Path.Combine(MsBuildProject.DirectoryPath, sourceCodeFile.EvaluatedInclude)));
            }

            foreach (var projectReference in MsBuildProject.GetItems("ProjectReference"))
            {
                string referencedFileName = Path.GetFullPath(Path.Combine(MsBuildProject.DirectoryPath, projectReference.EvaluatedInclude));
                ReferencedProjects.Add(referencedFileName);
            }
        }
开发者ID:rpepato,项目名称:StructEx,代码行数:35,代码来源:Project.cs

示例2: AddEnsureImportedTarget

        private static void AddEnsureImportedTarget(MicrosoftBuildEvaluationProject msBuildProject, string targetsPath)
        {
            // get the target
            var targetElement = msBuildProject.Xml.Targets.FirstOrDefault(
                target => target.Name.Equals(targetName, StringComparison.OrdinalIgnoreCase));

            // if the target does not exist, create the target
            if (targetElement == null)
            {
                targetElement = msBuildProject.Xml.AddTarget(targetName);

                // PrepareForBuild is used here because BeforeBuild does not work for VC++ projects.
                targetElement.BeforeTargets = "PrepareForBuild";

                var propertyGroup = targetElement.AddPropertyGroup();
                propertyGroup.AddProperty("ErrorText", CommonResources.EnsureImportedMessage);
            }

            var errorTask = targetElement.AddTask("Error");
            errorTask.Condition = "!Exists('" + targetsPath + "')";
            var errorText = string.Format(
                CultureInfo.InvariantCulture,
                @"$([System.String]::Format('$(ErrorText)', '{0}'))",
                targetsPath);
            errorTask.SetParameter("Text", errorText);
        }
开发者ID:mauroa,项目名称:NuGet.VisualStudioExtension,代码行数:26,代码来源:MicrosoftBuildEvaluationProjectUtility.cs

示例3: CreateBuildProject

        void CreateBuildProject()
        {
            string projectPath = Path.Combine(buildDirectory, "content.contentproj");
            string outputPath = Path.Combine(buildDirectory, "bin");

            // Create the build project.
            projectRootElement = ProjectRootElement.Create(projectPath);

            // Include the standard targets file that defines how to build XNA Framework content.
            projectRootElement.AddImport(Application.StartupPath + "\\Exporters\\FBX\\XNA\\XNA Game Studio\\" +
                                         "v4.0\\Microsoft.Xna.GameStudio.ContentPipeline.targets");

            buildProject = new Project(projectRootElement);

            buildProject.SetProperty("XnaPlatform", "Windows");
            buildProject.SetProperty("XnaProfile", "Reach");
            buildProject.SetProperty("XnaFrameworkVersion", "v4.0");
            buildProject.SetProperty("Configuration", "Release");
            buildProject.SetProperty("OutputPath", outputPath);
            buildProject.SetProperty("ContentRootDirectory", ".");
            buildProject.SetProperty("ReferencePath", Application.StartupPath);

            // Register any custom importers or processors.
            foreach (string pipelineAssembly in pipelineAssemblies)
            {
                buildProject.AddItem("Reference", pipelineAssembly);
            }

            // Hook up our custom error logger.
            errorLogger = new ErrorLogger();

            buildParameters = new BuildParameters(ProjectCollection.GlobalProjectCollection)
                                  {Loggers = new ILogger[] {errorLogger}};
        }
开发者ID:nicolasmassouh,项目名称:Babylon.js,代码行数:34,代码来源:ContentBuilder.cs

示例4: SetDefaultToolsVersion

        public void SetDefaultToolsVersion()
        {
            string oldValue = Environment.GetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION");

            try
            {
                // In the new world of figuring out the ToolsVersion to use, we completely ignore the default
                // ToolsVersion in the ProjectCollection.  However, this test explicitly depends on modifying 
                // that, so we need to turn the new defaulting behavior off in order to verify that this still works.  
                Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", "1");
                InternalUtilities.RefreshInternalEnvironmentValues();

                ProjectCollection collection = new ProjectCollection();
                collection.AddToolset(new Toolset("x", @"c:\y", collection, null));

                collection.DefaultToolsVersion = "x";

                Assert.AreEqual("x", collection.DefaultToolsVersion);

                string content = @"
                    <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' >
                        <Target Name='t'/>
                    </Project>
                ";

                Project project = new Project(XmlReader.Create(new StringReader(content)), null, null, collection);

                Assert.AreEqual(project.ToolsVersion, "x");
            }
            finally
            {
                Environment.SetEnvironmentVariable("MSBUILDLEGACYDEFAULTTOOLSVERSION", oldValue);
                InternalUtilities.RefreshInternalEnvironmentValues();
            }
        }
开发者ID:JamesLinus,项目名称:msbuild,代码行数:35,代码来源:Project_Internal_Tests.cs

示例5: ProjectGetter

        public void ProjectGetter()
        {
            Project project = new Project();
            ProjectItem item = project.AddItem("i", "i1")[0];

            Assert.Equal(true, Object.ReferenceEquals(project, item.Project));
        }
开发者ID:nikson,项目名称:msbuild,代码行数:7,代码来源:ProjectItem_Tests.cs

示例6: generate

        internal static void generate(string filename, string version, string asmName, string ns, ProjectType type)
        {
            Project p = new Project();
            string typeDesc = null;

            p.Xml.DefaultTargets = "Build";
            createItemGroup(p, "ProjectConfigurations");
            createGlobals(ns, type, p, "Globals");
            p.Xml.AddImport(@"$(VCTargetsPath)\Microsoft.Cpp.Default.props");

            switch (type) {
                case ProjectType.ConsoleApp: typeDesc = "Application"; break;
                case ProjectType.XamlApp: typeDesc = "Application"; break;
                case ProjectType.ClassLibrary: typeDesc = "DynamicLibrary"; break;
                default:
                    throw new InvalidOperationException("unhandled projectType: " + type);
            }
            createCfgProp(p.Xml, typeDesc, true);
            createCfgProp(p.Xml, typeDesc, false);
            p.Xml.AddImport(@"$(VCTargetsPath)\Microsoft.Cpp.props");
            addPropertySheetImports(p.Xml);
            addPropertyGroup(p.Xml, makeCfgCondition(DEBUG, PLATFORM), new Blah2(b2));
            addPropertyGroup(p.Xml, makeCfgCondition(RELEASE, PLATFORM), new Blah2(b2));
            addItemDefs(p.Xml);

            const string C_TARGET_RULES = @"$(VCTargetsPath)\Microsoft.Cpp.targets";
            var v99 = p.Xml.CreateImportElement(C_TARGET_RULES);
            p.Xml.AppendChild(v99);
            p.Save(filename);
        }
开发者ID:surak8,项目名称:ProjectGen,代码行数:30,代码来源:CProjectGenerator.cs

示例7: ProjectGetter

        public void ProjectGetter()
        {
            Project project = new Project();
            ProjectProperty property = project.SetProperty("p", "v");

            Assert.Equal(true, Object.ReferenceEquals(project, property.Project));
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:7,代码来源:ProjectProperty_Tests.cs

示例8: generateFiles

        internal static void generateFiles(Project p, PGOptions opts1, ProjectItemGroupElement pige)
        {
            Dictionary<string, string> tmp = new Dictionary<string, string>();
            WinDataProvider wdp = new WinDataProvider(WIN_NAME, opts1.projectNamespace, opts1.xamlType == XamlWindowType.RegularWindow);
            AppDataProvider apd = new AppDataProvider(wdp.fileName, opts1.projectNamespace);
            HomeDataProvider hdp = null;
            string tmp2;

            XamlFileGenerator.generateFile(apd, opts1);
            XamlFileGenerator.generateFile(wdp, opts1);

            if (opts1.xamlType == XamlWindowType.NavigationWindow) {
                hdp = new HomeDataProvider(wdp.homePage, opts1.projectNamespace);
                XamlFileGenerator.generateFile(hdp, opts1);
                generatePageAndModel(pige, hdp);
            }

            if (!string.IsNullOrEmpty(tmp2 = wdp.viewModelName) && File.Exists(tmp2)) {
                generateCompile(pige, tmp2);
            }

            generateApp(pige, apd);
            generatePage(pige, wdp);

            if (opts1.xamlPages.Count > 0) {
                GeneralPage gp;
                foreach (string aPageName in opts1.xamlPages) {
                    gp = new GeneralPage(aPageName, opts1.projectNamespace);
                    XamlFileGenerator.generateFile(gp, opts1);
                    generatePageAndModel(pige, gp);
                }
            }
        }
开发者ID:surak8,项目名称:ProjectGen,代码行数:33,代码来源:XamlGenerator.cs

示例9: TaskFinished

        public void TaskFinished(object sender, BuildEventArgs e)
        {
            var task = (CscTask)e.Task;
            var generator = (GenerateMsBuildTask)sender;
            var projectFileName = String.Format(
                    "{0}{1}{2}.csproj",
                    task.Sources.BaseDirectory.FullName,
                    Path.DirectorySeparatorChar,
                    Path.GetFileNameWithoutExtension(task.OutputFile.Name));

            ProjectRootElement project = null;
            if (!File.Exists(projectFileName))
                project = ProjectRootElement.Create(projectFileName);
            else
                project = ProjectRootElement.Open(projectFileName);
            var projectManipulator = new MB.Project(project);

            project.DefaultTargets = "Build";
            SetKnownProperties(project, task);
            GenerateReferences(project, projectManipulator, task, generator);
            GenerateCompileIncludes(project, projectManipulator, task);
            project.EnsureImportExists("$(MSBuildToolsPath)\\Microsoft.CSharp.targets");

            generator.RegisterProjectInSolution(project);
            project.Save();
        }
开发者ID:skolima,项目名称:generate-msbuild,代码行数:26,代码来源:CscTranslator.cs

示例10: ResolveProjectReferences

 protected override IEnumerable<ProjectReference> ResolveProjectReferences(Project project)
 {
     return
         base.ResolveProjectReferences(project)
             //Don't include project reference to pMixins
             .Where(p => !p.ToString().EndsWith(projectMatchingString));
 }
开发者ID:prescottadam,项目名称:pMixins,代码行数:7,代码来源:TestMicrosoftBuildProjectAssemblyReferenceResolver.cs

示例11: SetUnevaluatedValueOverwritesElementValue

		public void SetUnevaluatedValueOverwritesElementValue ()
		{
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <Foo>Bar</Foo>
    <Item/>
    <X>1</X>
    <X>2</X>
    <PATH>overriden</PATH>
  </PropertyGroup>
</Project>";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			var pe = root.Properties.First ();
			Assert.AreEqual ("Bar", pe.Value, "#1");
			var proj = new Project (root);
			var prop = proj.Properties.First (p => p.Name == "Foo");
			Assert.AreEqual ("Bar", prop.UnevaluatedValue, "#2");
			prop.UnevaluatedValue = "x";
			Assert.AreEqual ("x", pe.Value, "#3");
			
			prop = proj.Properties.First (p => p.Name == "X");
			Assert.AreEqual ("2", prop.UnevaluatedValue, "#4");
			Assert.IsNotNull (prop.Predecessor, "#5");
			Assert.AreEqual ("1", prop.Predecessor.UnevaluatedValue, "#6");
			
			// environment property could also be Predecessor (and removed...maybe.
			// I could reproduce only NRE = .NET bug with environment property so far.)
			prop = proj.Properties.First (p => p.Name == "PATH");
			Assert.AreEqual ("overriden", prop.UnevaluatedValue, "#7");
			Assert.IsNotNull (prop.Predecessor, "#8");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:32,代码来源:ProjectPropertyTest.cs

示例12: LoadedProject

        public static Microsoft.Build.Evaluation.Project LoadedProject(String path, bool cached)
        {
            Microsoft.Build.Evaluation.Project project = null;
            ICollection<Microsoft.Build.Evaluation.Project> projects = 
                ProjectCollection.GlobalProjectCollection.GetLoadedProjects(path);


            if (projects.Count == 0)
            {
                project = new Microsoft.Build.Evaluation.Project(path);
            }
            else
            {
                project = projects.First();
                if(!cached)
                {
                    //
                    // That is required to get C++ project properties re-evaluated
                    // with Visual Studio 2013 and Visual Studio 2015
                    //
                    ProjectCollection.GlobalProjectCollection.UnloadProject(project);
                    ProjectCollection.GlobalProjectCollection.UnloadAllProjects();
                    project = ProjectCollection.GlobalProjectCollection.LoadProject(path);
                }
            }
            return project;
        }
开发者ID:alux-xu,项目名称:ice-builder-visualstudio,代码行数:27,代码来源:MSBuildUtils.cs

示例13: ProjectProcessor

		public ProjectProcessor(string path)
		{
			using (ProjectCollection pc = new ProjectCollection())
			{
				this.Project = pc.GetLoadedProjects(path).FirstOrDefault();
			}
		}
开发者ID:tomgrv,项目名称:PA.InnoSetupProcessor,代码行数:7,代码来源:ProjectProcessor.cs

示例14: CreateProjectInstancePassesEnvironment

        public void CreateProjectInstancePassesEnvironment()
        {
            Project p = new Project();
            ProjectInstance i = p.CreateProjectInstance();

            Assert.Equal(true, i.GetPropertyValue("username") != null);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:7,代码来源:ProjectInstance_Tests.cs

示例15: GetDependsOnTargetsAsList

        public static IList<string> GetDependsOnTargetsAsList(this ProjectTargetInstance target,Project project)
        {
            if (target == null) { throw new ArgumentNullException("target"); }
            if (project == null) { throw new ArgumentNullException("project"); }

            List<string> targets = new List<string>();
            string depTargets = target.DependsOnTargets != null ? target.DependsOnTargets : string.Empty;
            string depTargetsEvaluated = project.ExpandString(depTargets);

            string[] dtArray = depTargetsEvaluated.Split(';');
            dtArray.ToList().ForEach(t => {
                if (!string.IsNullOrWhiteSpace(t)) {
                    string tName = t.Trim();
                    if (!string.IsNullOrWhiteSpace(tName) &&
                        string.Compare(";", tName, StringComparison.InvariantCultureIgnoreCase) != 0) {
                        targets.Add(tName);
                    }
                }
            });

            int numTarges = targets != null ? targets.Count() : 0;
            string tempDebug = null;
            if (numTarges >= 1) {
                tempDebug = targets[0];
            }

            return targets;
        }
开发者ID:sayedihashimi,项目名称:msbuild-analyzer,代码行数:28,代码来源:ProjectTargetInstanceExtension.cs


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