當前位置: 首頁>>代碼示例>>C#>>正文


C# Project.GetProperty方法代碼示例

本文整理匯總了C#中Microsoft.Build.Evaluation.Project.GetProperty方法的典型用法代碼示例。如果您正苦於以下問題:C# Project.GetProperty方法的具體用法?C# Project.GetProperty怎麽用?C# Project.GetProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Microsoft.Build.Evaluation.Project的用法示例。


在下文中一共展示了Project.GetProperty方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

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

示例2: SimpleImportAndSemanticValues

        public void SimpleImportAndSemanticValues ()
        {
            string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Import Project='test_imported.proj' />
</Project>";
            string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <A>x</A>
    <B>y</B>
  </PropertyGroup>
  <ItemGroup>
    <X Include=""included.txt"" />
  </ItemGroup>
</Project>";
            using (var ts = File.CreateText (temp_file_name))
                ts.Write (imported);
            try {
                var reader = XmlReader.Create (new StringReader (xml));
                var root = ProjectRootElement.Create (reader);
                Assert.AreEqual (temp_file_name, root.Imports.First ().Project, "#1");
                var proj = new Project (root);
                var prop = proj.GetProperty ("A");
                Assert.IsNotNull (prop, "#2");
                Assert.IsTrue (prop.IsImported, "#3");
                var item = proj.GetItems ("X").FirstOrDefault ();
                Assert.IsNotNull (item, "#4");
                Assert.AreEqual ("included.txt", item.EvaluatedInclude, "#5");
            } finally {
                File.Delete (temp_file_name);
            }
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:31,代碼來源:ResolvedImportTest.cs

示例3: CompileClassifier

        /// <summary>
        /// Creates a DecisionTreeClassifier.exe from a decision tree, returning the file path of the new exe
        /// </summary>
        public static string CompileClassifier(TreeNode decisionTree)
        {
            var assemblyLocation = Assembly.GetExecutingAssembly().Location;
            var assemblyDirectory = new FileInfo(assemblyLocation).DirectoryName ?? "";

            var classifierDir = Path.Combine(assemblyDirectory, "DecisionTreeClassifier");

            var projFullPath = Path.Combine(classifierDir, "DecisionTreeClassifier.csproj");
            var mainFullPath = Path.Combine(classifierDir, "Program.cs");

            ReplaceSerializedTreeLine(mainFullPath, decisionTree);

            // load up the classifier project
            var proj = new Project(projFullPath);

            // set project to compile special DecisionTree config
            proj.SetProperty("Configuration", "DecisionTree");

            // set the output path
            proj.SetProperty("DecisionTreeOutputPath", assemblyDirectory);

            // make a logger to catch possible build errors
            var logger = new SimpleBuildLogger();

            // if we failed to build the classifier, we're screwed
            if (!proj.Build(logger))
            {
                var sb = new StringBuilder();
                sb.AppendLine("***************************************");
                sb.AppendLine("**** Failed To Compile Classifier! ****");
                sb.AppendLine("***************************************");
                foreach (var error in logger.Errors)
                {
                    sb.AppendLine(error.Message + " " + error.File + ": " + error.LineNumber);
                }
                throw new Exception(sb.ToString());
            }

            // return the executable name
            var exeFileName = proj.GetProperty("AssemblyName").EvaluatedValue + ".exe";
            return Path.Combine(assemblyDirectory, exeFileName);
        }
開發者ID:aldenquimby,項目名稱:cs4701,代碼行數:45,代碼來源:Compiler.cs

示例4: GetFirstProperty

        /// <summary>
        /// Get the property named "p" in the project provided
        /// </summary>
        private static ProjectProperty GetFirstProperty(string content)
        {
            ProjectRootElement projectXml = ProjectRootElement.Create(XmlReader.Create(new StringReader(content)));
            Project project = new Project(projectXml);
            ProjectProperty property = project.GetProperty("p");

            return property;
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:11,代碼來源:ProjectProperty_Tests.cs

示例5: IsReservedProperty

        public void IsReservedProperty()
        {
            Project project = new Project();
            project.FullPath = @"c:\x";
            project.ReevaluateIfNecessary();

            Assert.Equal(false, project.GetProperty("MSBuildProjectFile").IsEnvironmentProperty);
            Assert.Equal(false, project.GetProperty("MSBuildProjectFile").IsGlobalProperty);
            Assert.Equal(true, project.GetProperty("MSBuildProjectFile").IsReservedProperty);
            Assert.Equal(false, project.GetProperty("MSBuildProjectFile").IsImported);
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:11,代碼來源:ProjectProperty_Tests.cs

示例6: SetPropertyImported

        public void SetPropertyImported()
        {
            Assert.Throws<InvalidOperationException>(() =>
            {
                string file = null;

                try
                {
                    file = Microsoft.Build.Shared.FileUtilities.GetTemporaryFile();
                    Project import = new Project();
                    import.SetProperty("p", "v0");
                    import.Save(file);

                    ProjectRootElement xml = ProjectRootElement.Create();
                    xml.AddImport(file);
                    Project project = new Project(xml);

                    ProjectProperty property = project.GetProperty("p");
                    property.UnevaluatedValue = "v1";
                }
                finally
                {
                    File.Delete(file);
                }
            }
           );
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:27,代碼來源:ProjectProperty_Tests.cs

示例7: IsEnvironmentVariable

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

            Assert.Equal(true, project.GetProperty("username").IsEnvironmentProperty);
            Assert.Equal(false, project.GetProperty("username").IsGlobalProperty);
            Assert.Equal(false, project.GetProperty("username").IsReservedProperty);
            Assert.Equal(false, project.GetProperty("username").IsImported);
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:9,代碼來源:ProjectProperty_Tests.cs

示例8: IsGlobalProperty

        public void IsGlobalProperty()
        {
            Dictionary<string, string> globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            globalProperties["g"] = String.Empty;
            Project project = new Project(globalProperties, null, ProjectCollection.GlobalProjectCollection);

            Assert.Equal(false, project.GetProperty("g").IsEnvironmentProperty);
            Assert.Equal(true, project.GetProperty("g").IsGlobalProperty);
            Assert.Equal(false, project.GetProperty("g").IsReservedProperty);
            Assert.Equal(false, project.GetProperty("g").IsImported);
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:11,代碼來源:ProjectProperty_Tests.cs

示例9: Choose

        public void Choose ()
        {
            string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <Choose>
    <When Condition="" '$(DebugSymbols)' != '' "">
      <PropertyGroup>
        <DebugXXX>True</DebugXXX>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup>
        <DebugXXX>False</DebugXXX>
      </PropertyGroup>
    </Otherwise>
  </Choose>
</Project>";
            var xml = XmlReader.Create (new StringReader (project_xml));
            var root = ProjectRootElement.Create (xml);
            root.FullPath = "ProjectTest.Choose.proj";
            var proj = new Project (root);
            var p = proj.GetProperty ("DebugXXX");
            Assert.IsNotNull (p, "#1");
            Assert.AreEqual ("False", p.EvaluatedValue, "#2");
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:24,代碼來源:ProjectTest.cs

示例10: GetProjects

        public List<CsProjFile> GetProjects()
        {
            UnloadAllProjects();
            var response = new List<CsProjFile>();
            var files = new List<string>();
            getCsProjFiles(ref files, SolutionFolder);
            foreach (var file in files)
            {
                var project = new Project(file);
                var name = Path.GetFileName(file).Replace(".csproj", "");
                var csproj = new CsProjFile
                {
                    AbsolutePath = file,
                    GuidString = project.GetProperty("ProjectGuid").EvaluatedValue,
                    Name = name,
                    PathToSolution =
                        @".." + Path.GetDirectoryName(file).ToLower().Replace(SolutionFolder.ToLower(), "") + @"\" +
                        name + ".csproj"
                };
                response.Add(csproj);
            }
            UnloadAllProjects();
            return response;
        }
開發者ID:MiniverCheevy,項目名稱:Spawn,代碼行數:24,代碼來源:VisualStudioHelper.cs

示例11: ExternallyMarkDirty

        public void ExternallyMarkDirty()
        {
            Project project = new Project();
            project.SetProperty("p", "v");
            project.ReevaluateIfNecessary();

            Assert.Equal(false, project.IsDirty);

            ProjectProperty property1 = project.GetProperty("p");

            project.MarkDirty();

            Assert.Equal(true, project.IsDirty);

            project.ReevaluateIfNecessary();

            Assert.Equal(false, project.IsDirty);

            ProjectProperty property2 = project.GetProperty("p");

            Assert.Equal(false, Object.ReferenceEquals(property1, property2)); // different object indicates reevaluation occurred
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:22,代碼來源:Project_Tests.cs

示例12: ChangeGlobalPropertyAfterReevaluation

        public void ChangeGlobalPropertyAfterReevaluation()
        {
            Project project = new Project();
            project.SetGlobalProperty("p", "v1");
            project.ReevaluateIfNecessary();
            project.SetGlobalProperty("p", "v2");

            Assert.Equal("v2", project.GetPropertyValue("p"));
            Assert.Equal(true, project.GetProperty("p").IsGlobalProperty);
        }
開發者ID:cameron314,項目名稱:msbuild,代碼行數:10,代碼來源:Project_Tests.cs

示例13: EvaluateMSBuildThisFileProperty

        public void EvaluateMSBuildThisFileProperty ()
        {
            string xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <A>$(MSBuildThisFile)</A>
  </PropertyGroup>
  <Import Project='test_imported.proj' />
</Project>";
            string imported = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
  <PropertyGroup>
    <B>$(MSBuildThisFile)</B>
  </PropertyGroup>
</Project>";
            using (var ts = File.CreateText (temp_file_name))
                ts.Write (imported);
            try {
                var reader = XmlReader.Create (new StringReader (xml));
                var root = ProjectRootElement.Create (reader);
                var proj = new Project (root);
                var a = proj.GetProperty ("A");
                Assert.AreEqual (string.Empty, a.EvaluatedValue, "#1");
                var b = proj.GetProperty ("B");
                Assert.AreEqual (temp_file_name, b.EvaluatedValue, "#2");

                var pi  = new ProjectInstance (root);
                var ai = pi.GetProperty ("A");
                Assert.AreEqual (string.Empty, ai.EvaluatedValue, "#3");
                var bi = pi.GetProperty ("B");
                Assert.AreEqual (temp_file_name, bi.EvaluatedValue, "#4");
            } finally {
                File.Delete (temp_file_name);
            }
        }
開發者ID:nlhepler,項目名稱:mono,代碼行數:33,代碼來源:ResolvedImportTest.cs

示例14: RemoveProperty

        public void RemoveProperty()
        {
            Project project = new Project();
            int environmentPropertyCount = Helpers.MakeList(project.Properties).Count;

            project.SetProperty("p1", "v1");
            project.ReevaluateIfNecessary();

            project.RemoveProperty(project.GetProperty("p1"));

            string expected = ObjectModelHelpers.CleanupFileContents(@"<Project ToolsVersion=""msbuilddefaulttoolsversion"" xmlns=""msbuildnamespace"" />");

            Helpers.VerifyAssertProjectContent(expected, project.Xml);

            Assert.Equal(null, project.GetProperty("p1"));
            ProjectInstance instance = project.CreateProjectInstance();
            Assert.Equal(String.Empty, instance.GetPropertyValue("p1"));
            Assert.Equal(0, Helpers.Count(project.Properties) - environmentPropertyCount);
        }
開發者ID:cdmihai,項目名稱:msbuild,代碼行數:19,代碼來源:DefinitionEditing_Tests.cs

示例15: Compile

 //private void UnzipShell()
 //{
 //    var shell = new Shell();
 //    var srcFlder = shell.NameSpace(Paths.MooegeDownloadPath);
 //    var destFlder = shell.NameSpace(Paths.RepositoriesPath);
 //    var items = srcFlder.Items();
 //    destFlder.CopyHere(items, 20);
 //}
 private bool Compile()
 {
     LocalRevision = LastRevision;
     var path = Path.Combine(Paths.RepositoriesPath, Name, "src", "Mooege", "Mooege-VS2010.csproj");
     var project = new Project(path);
     project.SetProperty("Configuration", Configuration.MadCow.CompileAsDebug ? "Debug" : "Release");
     project.SetProperty("Platform", "x86");
     //project.SetProperty("OutputPath", Path.Combine(Paths.RepositoriesPath, Name, "compiled"));
     //project.SetProperty("TargetDir", Path.Combine(Paths.RepositoriesPath, Name, "compiled"));
     project.SetProperty("OutDir", Path.Combine(Paths.RepositoriesPath, Name, "compiled"));
     var p = project.GetProperty("OutputPath");
     return project.Build(new FileLogger());
 }
開發者ID:OverlordCW,項目名稱:MadCow,代碼行數:21,代碼來源:Repository.cs


注:本文中的Microsoft.Build.Evaluation.Project.GetProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。