當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。