当前位置: 首页>>代码示例>>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;未经允许,请勿转载。