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


C# Project.GetPropertyValue方法代码示例

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


在下文中一共展示了Project.GetPropertyValue方法的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: BuildProject

		public static MSbuildResult BuildProject(MsBuildSettings settings, string projectFileName, DirectoryInfo dir)
		{
			var result = new MSbuildResult();
			var path = Path.Combine(dir.FullName, projectFileName);
			var project = new Project(path, null, null, new ProjectCollection());
			project.SetProperty("CscToolPath", settings.CompilerDirectory.FullName);
			var includes = new HashSet<string>(
				project.AllEvaluatedItems
				.Where(i => i.ItemType == "None" || i.ItemType == "Content")
				.Select(i => Path.GetFileName(i.EvaluatedInclude.ToLowerInvariant())));
			foreach (var dll in settings.WellKnownLibsDirectory.GetFiles("*.dll"))
				if (!includes.Contains(dll.Name.ToLowerInvariant()))
					project.AddItem("None", dll.FullName);
			project.Save();
			using (var stringWriter = new StringWriter())
			{
				var logger = new ConsoleLogger(LoggerVerbosity.Minimal, stringWriter.Write, color => { }, () => { });
				result.Success = SyncBuild(project, logger);
				if (result.Success)
					result.PathToExe = Path.Combine(project.DirectoryPath,
													project.GetPropertyValue("OutputPath"),
													project.GetPropertyValue("AssemblyName") + ".exe");
				else
					result.ErrorMessage = stringWriter.ToString();
				return result;
			}
		}
开发者ID:kontur-edu,项目名称:uLearn,代码行数:27,代码来源:MsBuildRunner.cs

示例3: AddSolutionConfiguration

    static void AddSolutionConfiguration(string projectFile, Dictionary<string, string> properties)
    {
        var collection = new ProjectCollection(properties);
        var toolsVersion = default(string);
        var project = new Project(projectFile, properties, toolsVersion, collection);
        var config = project.GetPropertyValue("Configuration");
        var platform = project.GetPropertyValue("Platform");

        var xml = new XElement("SolutionConfiguration");
        xml.Add(new XElement("ProjectConfiguration",
            new XAttribute("Project", project.GetPropertyValue("ProjectGuid")),
            new XAttribute("AbsolutePath", project.FullPath),
            new XAttribute("BuildProjectInSolution", "true"))
        {
            Value = $"{config}|{platform}"
        });

        foreach (var reference in GetProjectReferences(project))
        {
            xml.Add(new XElement("ProjectConfiguration",
                new XAttribute("Project", reference.GetPropertyValue("ProjectGuid")),
                new XAttribute("AbsolutePath", reference.FullPath),
                new XAttribute("BuildProjectInSolution", "false"))
            {
                Value = $"{config}|{platform}"
            });
        }

        properties["CurrentSolutionConfigurationContents"] = xml.ToString(SaveOptions.None);
    }
开发者ID:xamarin,项目名称:NuGetizer3000,代码行数:30,代码来源:Builder.cs

示例4: CreateCompilation

        private Compilation CreateCompilation(Project project)
        {
            var outputPath = project.GetProperty("OutputPath").EvaluatedValue;

            if (!Path.IsPathRooted(outputPath))
            {
                outputPath = Path.Combine(Environment.CurrentDirectory, outputPath);
            }

            var searchPaths = ReadOnlyArray.OneOrZero(outputPath);
            var resolver = new DiskFileResolver(searchPaths, searchPaths, Environment.CurrentDirectory, arch => true, System.Globalization.CultureInfo.CurrentCulture);

            var metadataFileProvider = new MetadataFileProvider();

            // just grab a list of references (if they're null, ignore)
            var list = project.GetItems("Reference").Select(item =>
            {
                var include = item.EvaluatedInclude;
                var path = resolver.ResolveAssemblyName(include);
                if (path == null) return null;
                return metadataFileProvider.GetReference(path);
            }).Where(x => x != null);

            return Compilation.Create(project.GetPropertyValue("AssemblyName"),
                syntaxTrees: project.GetItems("Compile").Select(c => SyntaxTree.ParseFile(c.EvaluatedInclude)),
                references: list);
        }
开发者ID:pmacn,项目名称:DocPlagiarizer,代码行数:27,代码来源:DocPlagiarizerTask.cs

示例5: LoadAndInitProject

        private Project LoadAndInitProject(CSharpSolution solution, string fileName)
        {
            var globalProperties = new Dictionary<string, string>();
            globalProperties.Add("SolutionDir", solution.Directory);

            var msbuildProject = 
                new Project(fileName, globalProperties, null, 
                ProjectCollection.GlobalProjectCollection, ProjectLoadSettings.IgnoreMissingImports);

            AssemblyName = msbuildProject.GetPropertyValue("AssemblyName");
            CompilerSettings.AllowUnsafeBlocks = GetBoolProperty(msbuildProject, "AllowUnsafeBlocks") ?? false;
            CompilerSettings.CheckForOverflow = GetBoolProperty(msbuildProject, "CheckForOverflowUnderflow") ?? false;

            var defineConstants = msbuildProject.GetPropertyValue("DefineConstants");
            foreach (var symbol in defineConstants.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries))
                CompilerSettings.ConditionalSymbols.Add(symbol.Trim());

            return msbuildProject;
        }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:19,代码来源:CSharpProject.cs

示例6: ProjectFactory

        public ProjectFactory(Project project)
        {
            _project = project;
            ProjectProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            AddSolutionDir();
            _settings = null;

            // Get the target framework of the project
            string targetFrameworkMoniker = _project.GetPropertyValue("TargetFrameworkMoniker");
            if (!String.IsNullOrEmpty(targetFrameworkMoniker))
            {
                TargetFramework = new FrameworkName(targetFrameworkMoniker);
            }
        }
开发者ID:sistoimenov,项目名称:NuGet2,代码行数:14,代码来源:ProjectFactory.cs

示例7: ChangeGlobalProperties

        public void ChangeGlobalProperties()
        {
            Project project = new Project();
            ProjectPropertyElement propertyElement = project.Xml.AddProperty("p", "v0");
            propertyElement.Condition = "'$(g)'=='v1'";
            project.ReevaluateIfNecessary();
            Assert.Equal(String.Empty, project.GetPropertyValue("p"));

            Assert.Equal(true, project.SetGlobalProperty("g", "v1"));
            Assert.Equal(true, project.IsDirty);
            project.ReevaluateIfNecessary();
            Assert.Equal("v0", project.GetPropertyValue("p"));
            Assert.Equal("v1", project.GlobalProperties["g"]);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:14,代码来源:Project_Tests.cs

示例8: BasicFromXmlFollowImport

        public void BasicFromXmlFollowImport()
        {
            string importContent = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace'>
                        <PropertyGroup>
                            <p2>v3</p2>
                        </PropertyGroup>
                        <ItemGroup>
                            <i Include='i4'/>
                        </ItemGroup>
                        <Target Name='t2'>
                            <task/>
                        </Target>
                    </Project>");

            string importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.targets", importContent);

            string projectFileContent = ObjectModelHelpers.CleanupFileContents(@"
                    <Project xmlns='msbuildnamespace'>
                        <PropertyGroup Condition=""'$(Configuration)'=='Foo'"">
                            <p>v1</p>
                        </PropertyGroup>
                        <PropertyGroup Condition=""'$(Configuration)'!='Foo'"">
                            <p>v2</p>
                        </PropertyGroup>
                        <PropertyGroup>
                            <p2>X$(p)</p2>
                        </PropertyGroup>
                        <ItemGroup>
                            <i Condition=""'$(Configuration)'=='Foo'"" Include='i0'/>
                            <i Include='i1'/>
                            <i Include='$(p)X;i3'/>
                        </ItemGroup>
                        <Target Name='t'>
                            <task/>
                        </Target>
                        <Import Project='{0}'/>
                    </Project>");

            projectFileContent = String.Format(projectFileContent, importPath);

            ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectFileContent)));
            Project project = new Project(xml);

            Assert.Equal("v3", project.GetPropertyValue("p2"));

            List<ProjectItem> items = Helpers.MakeList(project.GetItems("i"));
            Assert.Equal(4, items.Count);
            Assert.Equal("i1", items[0].EvaluatedInclude);
            Assert.Equal("v2X", items[1].EvaluatedInclude);
            Assert.Equal("i3", items[2].EvaluatedInclude);
            Assert.Equal("i4", items[3].EvaluatedInclude);

            IList<ResolvedImport> imports = project.Imports;
            Assert.Equal(1, imports.Count);
            Assert.Equal(true, Object.ReferenceEquals(imports.First().ImportingElement, xml.Imports.ElementAt(0)));

            // We can take advantage of the fact that we will get the same ProjectRootElement from the cache if we try to
            // open it with a path; get that and then compare it to what project.Imports gave us.
            Assert.Equal(true, Object.ReferenceEquals(imports.First().ImportedProject, ProjectRootElement.Open(importPath)));

            // Test the logical project iterator
            List<ProjectElement> logicalElements = new List<ProjectElement>(project.GetLogicalProject());

            Assert.Equal(18, logicalElements.Count);

            ObjectModelHelpers.DeleteTempProjectDirectory();
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:68,代码来源:Project_Tests.cs

示例9: SetPropertyWithPropertyExpression

        public void SetPropertyWithPropertyExpression()
        {
            Project project = new Project();
            project.SetProperty("p0", "v0");
            project.SetProperty("p1", "$(p0)");

            Assert.Equal("v0", project.GetPropertyValue("p1"));
        }
开发者ID:cdmihai,项目名称:msbuild,代码行数:8,代码来源:DefinitionEditing_Tests.cs

示例10: GetBoolProperty

 private static bool? GetBoolProperty(Project p, string propertyName)
 {
     var val = p.GetPropertyValue(propertyName);
     bool result;
     if (bool.TryParse(val, out result))
         return result;
     else
         return null;
 }
开发者ID:JoeHosman,项目名称:sharpDox,代码行数:9,代码来源:CSharpProject.cs

示例11: EvaluateSamePropertiesInOrder

		public void EvaluateSamePropertiesInOrder ()
		{
			// used in Microsoft.Common.targets
			string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <BaseIntermediateOutputPath Condition=""'$(BaseIntermediateOutputPath)' == ''"">obj\</BaseIntermediateOutputPath>
  </PropertyGroup>
</Project>";
			var xml = XmlReader.Create (new StringReader (project_xml));
			var root = ProjectRootElement.Create (xml);
			var proj = new Project (root);
			Assert.AreEqual ("obj" + Path.DirectorySeparatorChar, proj.GetPropertyValue ("BaseIntermediateOutputPath"), "#1");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:13,代码来源:ProjectTest.cs

示例12: ChangeGlobalPropertiesInitiallyFromProjectCollection

        public void ChangeGlobalPropertiesInitiallyFromProjectCollection()
        {
            Dictionary<string, string> initial = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            initial.Add("p0", "v0");
            initial.Add("p1", "v1");
            ProjectCollection collection = new ProjectCollection(initial, null, ToolsetDefinitionLocations.ConfigurationFile);
            Project project = new Project(collection);
            ProjectPropertyElement propertyElement = project.Xml.AddProperty("pp", "vv");
            propertyElement.Condition = "'$(p0)'=='v0' and '$(p1)'=='v1b'";
            project.ReevaluateIfNecessary();
            Assert.Equal(String.Empty, project.GetPropertyValue("pp"));

            project.SetGlobalProperty("p1", "v1b");
            Assert.Equal(true, project.IsDirty);
            project.ReevaluateIfNecessary();
            Assert.Equal("vv", project.GetPropertyValue("pp"));
            Assert.Equal("v0", collection.GlobalProperties["p0"]);
            Assert.Equal("v1", collection.GlobalProperties["p1"]);
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:19,代码来源:Project_Tests.cs

示例13: ChangeEnvironmentProperty

        public void ChangeEnvironmentProperty()
        {
            Project project = new Project();
            project.SetProperty("computername", "v1");

            Assert.Equal("v1", project.GetPropertyValue("computername"));
            Assert.Equal(true, project.IsDirty);

            project.ReevaluateIfNecessary();

            Assert.Equal("v1", project.GetPropertyValue("computername"));
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:12,代码来源:Project_Tests.cs

示例14: GetSubToolsetVersion_FromEnvironment

        public void GetSubToolsetVersion_FromEnvironment()
        {
            string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");

            try
            {
                Environment.SetEnvironmentVariable("VisualStudioVersion", "ABCD");

                Project p = new Project(GetSampleProjectRootElement(), null, "4.0", new ProjectCollection());

                Assert.Equal("4.0", p.ToolsVersion);
                Assert.Equal("ABCD", p.SubToolsetVersion);
                Assert.Equal("ABCD", p.GetPropertyValue("VisualStudioVersion"));
            }
            finally
            {
                Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
            }
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:19,代码来源:Project_Tests.cs

示例15: MSBuildToolsVersionProperty40

        public void MSBuildToolsVersionProperty40()
        {
            Project project = new Project();

            Assert.Equal(ObjectModelHelpers.MSBuildDefaultToolsVersion, project.GetPropertyValue("msbuildtoolsversion"));
        }
开发者ID:cameron314,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs


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