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


C# Project.SetProperty方法代码示例

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


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

示例1: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
						Project project = new Project();
						project.Load(taskItem.ItemSpec);
						project.DefaultToolsVersion = "3.5";

						if (this.DowngradeMvc2ToMvc1) {
							string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
							if (!string.IsNullOrEmpty(projectTypeGuids)) {
								projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
								project.SetProperty("ProjectTypeGuids", projectTypeGuids);
							}
						}

						// Web projects usually have an import that includes these substrings
						foreach (Import import in project.Imports) {
							import.ProjectPath = import.ProjectPath
								.Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
								.Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
						}

						// VS2010 won't let you have a System.Core reference, but VS2008 requires it.
						BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
						if (!references.Cast<BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase))) {
							project.AddNewItem("Reference", "System.Core");
						}

						project.Save(taskItem.ItemSpec);
						break;
					case ProjectClassification.VS2010Solution:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
						string[] contents = File.ReadAllLines(taskItem.ItemSpec);
						if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
							contents[2] != "# Visual Studio 2010") {
							this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
							break;
						}

						contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
						contents[2] = "# Visual Studio 2008";

						for (int i = 3; i < contents.Length; i++) {
							contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
						}

						File.WriteAllLines(taskItem.ItemSpec, contents);
						break;
					default:
						this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
						break;
				}
			}

			return !this.Log.HasLoggedErrors;
		}
开发者ID:jongalloway,项目名称:dotnetopenid,代码行数:61,代码来源:DowngradeProjects.cs

示例2: ProjectPathSet_ScalarValue

 public void ProjectPathSet_ScalarValue()
 {
     string importPath = String.Empty;
     string importPath2 = String.Empty;           
     try
     {
         importPath = ObjectModelHelpers.CreateFileInTempProjectDirectory("import.proj", TestData.Content3SimpleTargetsDefaultSpecified);
         importPath2 = ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.proj", TestData.Content3SimpleTargetsDefaultSpecified);
         Project p = new Project();
         p.AddNewImport(importPath, "true");
         p.SetProperty("path", importPath2);
         object o = p.EvaluatedProperties;
         BuildProperty path = CompatibilityTestHelpers.FindBuildProperty(p, "path");
         Import import = CompatibilityTestHelpers.FindFirstMatchingImportByPath(p.Imports, importPath);
         import.ProjectPath = "$(path)";
         Assertion.AssertEquals("$(path)", import.ProjectPath);
         o = p.EvaluatedProperties;
         Assertion.AssertEquals(false, object.Equals(importPath2, import.EvaluatedProjectPath)); // V9 OM does not evaluate imports
     }
     finally
     {
         CompatibilityTestHelpers.RemoveFile(importPath);
         CompatibilityTestHelpers.RemoveFile(importPath2);
     }
 }
开发者ID:nikson,项目名称:msbuild,代码行数:25,代码来源:Import_Tests.cs

示例3: ResetBuildVirtualPropertyReset

 public void ResetBuildVirtualPropertyReset()
 {
     Project p = new Project(new Engine());
     p.LoadXml(TestData.ContentCreatePropertyTarget);
     p.SetProperty("p", "v1");
     p.Build("CreatePropertyTarget");
     Assertion.AssertEquals("v", p.GetEvaluatedProperty("p"));
     p.ResetBuildStatus();
     Assertion.AssertEquals("v1", p.GetEvaluatedProperty("p"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:10,代码来源:Project_Tests.cs

示例4: SetPropertyDirtyAfterSet

 public void SetPropertyDirtyAfterSet()
 {
     Project p = new Project();
     p.SetProperty("property_name", "v");
     Assertion.AssertEquals(true, p.IsDirty);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例5: GetTaskNameScalar

 public void GetTaskNameScalar()
 {
     Project p = new Project(new Engine());
     p.AddNewUsingTaskFromAssemblyName("$(name)", "assemblyName");
     p.SetProperty("name", "TaskName");
     object o = p.EvaluatedItems;
     Assertion.AssertNotNull(CompatibilityTestHelpers.FindUsingTaskByName("$(name)", p.UsingTasks));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:8,代码来源:UsingTask_Tests.cs

示例6: TestSkipInvalidConfigurationsCase

        public void TestSkipInvalidConfigurationsCase()
        {
            string tmpFileName = Path.GetTempFileName();
            File.Delete(tmpFileName);
            string projectFilePath = tmpFileName + ".sln";

            string solutionContents =
                @"
                Microsoft Visual Studio Solution File, Format Version 9.00
                # Visual Studio 2005
                Project('{E24C65DC-7377-472B-9ABA-BC803B73C61A}') = 'C:\solutions\WebSite2\', '..\..\solutions\WebSite2\', '{F90528C4-6989-4D33-AFE8-F53173597CC2}'
                    ProjectSection(WebsiteProperties) = preProject
                        Debug.AspNetCompiler.VirtualPath = '/WebSite2'
                        Debug.AspNetCompiler.PhysicalPath = '..\..\solutions\WebSite2\'
                        Debug.AspNetCompiler.TargetPath = 'PrecompiledWeb\WebSite2\'
                        Debug.AspNetCompiler.Updateable = 'true'
                        Debug.AspNetCompiler.ForceOverwrite = 'true'
                        Debug.AspNetCompiler.FixedNames = 'true'
                        Debug.AspNetCompiler.Debug = 'True'
                        Release.AspNetCompiler.VirtualPath = '/WebSite2'
                        Release.AspNetCompiler.PhysicalPath = '..\..\solutions\WebSite2\'
                        Release.AspNetCompiler.TargetPath = 'PrecompiledWeb\WebSite2\'
                        Release.AspNetCompiler.Updateable = 'true'
                        Release.AspNetCompiler.ForceOverwrite = 'true'
                        Release.AspNetCompiler.FixedNames = 'true'
                        Release.AspNetCompiler.Debug = 'False'
                        VWDPort = '2776'
                        DefaultWebSiteLanguage = 'Visual C#'
                    EndProjectSection
                EndProject
                Global
                    GlobalSection(SolutionConfigurationPlatforms) = preSolution
                        Debug|Any CPU = Debug|Any CPU
                    EndGlobalSection
                    GlobalSection(ProjectConfigurationPlatforms) = postSolution
                        {F90528C4-6989-4D33-AFE8-F53173597CC2}.Debug|Any CPU.ActiveCfg = Debug|.NET
                        {F90528C4-6989-4D33-AFE8-F53173597CC2}.Debug|Any CPU.Build.0 = Debug|.NET
                    EndGlobalSection
                EndGlobal";

            File.WriteAllText(projectFilePath, solutionContents.Replace('\'', '"'));

            try
            {
                MockLogger logger = new MockLogger();
                Engine engine = new Engine();
                engine.RegisterLogger(logger);

                Project solutionWrapperProject = new Project(engine);
                solutionWrapperProject.Load(projectFilePath);

                solutionWrapperProject.SetProperty("Configuration", "Nonexistent");
                solutionWrapperProject.SetProperty("SkipInvalidConfigurations", "true");
                solutionWrapperProject.ToolsVersion = "4.0";

                // Build should complete successfully even with an invalid solution config if SkipInvalidConfigurations is true
                Assertion.AssertEquals(true, solutionWrapperProject.Build(null, null));

                // We should get the invalid solution configuration warning
                Assertion.AssertEquals(1, logger.Warnings.Count);
                BuildWarningEventArgs warning = logger.Warnings[0];

                // Don't look at warning.Code here -- it may be null if PseudoLoc has messed
                // with our resource strings. The code will still be in the log -- it just wouldn't get
                // pulled out into the code field.
                logger.AssertLogContains("MSB4126");

                // No errors expected
                Assertion.AssertEquals(0, logger.Errors.Count);
            }
            finally
            {
                File.Delete(projectFilePath);
            }
        }
开发者ID:nikson,项目名称:msbuild,代码行数:75,代码来源:SolutionWrapperProject_Tests.cs

示例7: CreateBuildProject

        /// <summary>
        /// Creates a temporary MSBuild content project in memory.
        /// </summary>
        void CreateBuildProject()
        {
            string projectPath = Path.Combine(buildDirectory, "content.contentproj");
            string outputPath = Path.Combine(buildDirectory, "bin");

            // Create the build engine.
            msBuildEngine = new Engine();

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

            msBuildEngine.RegisterLogger(errorLogger);
            msBuildEngine.DefaultToolsVersion = "3.5";
            // Create the build project.
            msBuildProject = new Project(msBuildEngine);

            msBuildProject.FullFileName = projectPath;

            msBuildProject.SetProperty("XnaPlatform", "Windows");
            msBuildProject.SetProperty("XnaFrameworkVersion", "v3.1");
            msBuildProject.SetProperty("Configuration", "Release");
            msBuildProject.SetProperty("OutputPath", outputPath);

            // Register any custom importers or processors.
            foreach (string pipelineAssembly in pipelineAssemblies)
            {
                msBuildProject.AddNewItem("Reference", pipelineAssembly);
            }
             	            // Reference SkinnedModelPipeline.
             	        string applicationDirectory = AppDomain.CurrentDomain.BaseDirectory;
             	        string dllPath = Path.Combine(applicationDirectory, "SkinnedModelPipeline.dll");
             	        string importDll = Path.GetFullPath(dllPath);
            this.msBuildProject.AddNewItem("Reference", importDll);

            // Include the standard targets file that defines
            // how to build XNA Framework content.
            msBuildProject.AddNewImport("$(MSBuildExtensionsPath)\\Microsoft\\XNA " +
                                        "Game Studio\\v3.1\\Microsoft.Xna.GameStudio" +
                                        ".ContentPipeline.targets", null);
        }
开发者ID:summer-of-software,项目名称:vtank,代码行数:43,代码来源:ContentBuilder.cs

示例8: Execute

		/// <summary>
		/// Executes this instance.
		/// </summary>
		public override bool Execute() {
			var newProjectToOldProjectMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			var createdProjectFiles = new List<TaskItem>();

			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
					case ProjectClassification.VS2010Solution:
						string projectNameForVS2008 = InPlaceDowngrade
														? taskItem.ItemSpec
														: Path.Combine(
															Path.GetDirectoryName(taskItem.ItemSpec),
															Path.GetFileNameWithoutExtension(taskItem.ItemSpec) + "-vs2008" +
															Path.GetExtension(taskItem.ItemSpec));
						newProjectToOldProjectMapping[taskItem.ItemSpec] = projectNameForVS2008;
						break;
				}
			}

			foreach (ITaskItem taskItem in this.Projects) {
				switch (GetClassification(taskItem)) {
					case ProjectClassification.VS2010Project:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading project \"{0}\".", taskItem.ItemSpec);
						var project = new Project();
						project.Load(taskItem.ItemSpec, ProjectLoadSettings.IgnoreMissingImports);
						project.DefaultToolsVersion = "3.5";

						if (this.DowngradeMvc2ToMvc1) {
							string projectTypeGuids = project.GetEvaluatedProperty("ProjectTypeGuids");
							if (!string.IsNullOrEmpty(projectTypeGuids)) {
								projectTypeGuids = projectTypeGuids.Replace("{F85E285D-A4E0-4152-9332-AB1D724D3325}", "{603c0e0b-db56-11dc-be95-000d561079b0}");
								project.SetProperty("ProjectTypeGuids", projectTypeGuids);
							}
						}

						// MSBuild v3.5 doesn't support the GetDirectoryNameOfFileAbove function
						var enlistmentInfoImports = project.Imports.Cast<Import>().Where(i => i.ProjectPath.IndexOf("[MSBuild]::GetDirectoryNameOfFileAbove", StringComparison.OrdinalIgnoreCase) >= 0);
						enlistmentInfoImports.ToList().ForEach(i => project.Imports.RemoveImport(i));

						// Web projects usually have an import that includes these substrings));)
						foreach (Import import in project.Imports) {
							import.ProjectPath = import.ProjectPath
								.Replace("$(MSBuildExtensionsPath32)", "$(MSBuildExtensionsPath)")
								.Replace("VisualStudio\\v10.0", "VisualStudio\\v9.0");
						}

						// VS2010 won't let you have a System.Core reference, but VS2008 requires it.
						BuildItemGroup references = project.GetEvaluatedItemsByName("Reference");
						if (!references.Cast<BuildItem>().Any(item => item.FinalItemSpec.StartsWith("System.Core", StringComparison.OrdinalIgnoreCase))) {
							project.AddNewItem("Reference", "System.Core");
						}

						// Rewrite ProjectReferences to other renamed projects.
						BuildItemGroup projectReferences = project.GetEvaluatedItemsByName("ProjectReference");
						foreach (var mapping in newProjectToOldProjectMapping) {
							string oldName = Path.GetFileName(mapping.Key);
							string newName = Path.GetFileName(mapping.Value);
							foreach (BuildItem projectReference in projectReferences) {
								projectReference.Include = Regex.Replace(projectReference.Include, oldName, newName, RegexOptions.IgnoreCase);
							}
						}

						project.Save(newProjectToOldProjectMapping[taskItem.ItemSpec]);
						createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
						break;
					case ProjectClassification.VS2010Solution:
						this.Log.LogMessage(MessageImportance.Low, "Downgrading solution \"{0}\".", taskItem.ItemSpec);
						string[] contents = File.ReadAllLines(taskItem.ItemSpec);
						if (contents[1] != "Microsoft Visual Studio Solution File, Format Version 11.00" ||
							contents[2] != "# Visual Studio 2010") {
							this.Log.LogError("Unrecognized solution file header in \"{0}\".", taskItem.ItemSpec);
							break;
						}

						contents[1] = "Microsoft Visual Studio Solution File, Format Version 10.00";
						contents[2] = "# Visual Studio 2008";

						for (int i = 3; i < contents.Length; i++) {
							contents[i] = contents[i].Replace("TargetFrameworkMoniker = \".NETFramework,Version%3Dv", "TargetFramework = \"");
						}

						foreach (var mapping in newProjectToOldProjectMapping) {
							string oldName = Path.GetFileName(mapping.Key);
							string newName = Path.GetFileName(mapping.Value);
							for (int i = 0; i < contents.Length; i++) {
								contents[i] = Regex.Replace(contents[i], oldName, newName, RegexOptions.IgnoreCase);
							}
						}

						File.WriteAllLines(newProjectToOldProjectMapping[taskItem.ItemSpec], contents);
						createdProjectFiles.Add(new TaskItem(taskItem) { ItemSpec = newProjectToOldProjectMapping[taskItem.ItemSpec] });
						break;
					default:
						this.Log.LogWarning("Unrecognized project type for \"{0}\".", taskItem.ItemSpec);
						break;
				}
			}
//.........这里部分代码省略.........
开发者ID:Balamir,项目名称:DotNetOpenAuth,代码行数:101,代码来源:DowngradeProjects.cs

示例9: SetPropertySetName_Empty

 public void SetPropertySetName_Empty()
 {
     Project p = new Project();
     p.SetProperty(String.Empty, "v");
 }
开发者ID:nikson,项目名称:msbuild,代码行数:5,代码来源:Project_Tests.cs

示例10: SetPropertySetName_Null

 public void SetPropertySetName_Null()
 {
     Project p = new Project();
     string name = null;
     p.SetProperty(name, "v");
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例11: SetPropertySetExisting

 public void SetPropertySetExisting()
 {
     Project p = new Project();
     p.SetProperty("property_name", "v");
     p.SetProperty("property_name", "v2");
     Assertion.AssertEquals("v2", p.GetEvaluatedProperty("property_name"));
     Assertion.AssertEquals(true, p.Xml.Contains("property_name"));
     Assertion.AssertEquals(true, p.IsDirty);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:9,代码来源:Project_Tests.cs

示例12: SetPropertyCondition_False

 public void SetPropertyCondition_False()
 {
     Project p = new Project();
     p.SetProperty("n", "v", "false");
     Assertion.AssertNull(p.GetEvaluatedProperty("n"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例13: SetPropertyCondition_True

 public void SetPropertyCondition_True()
 {
     Project p = new Project();
     p.SetProperty("n", "v", "1 == 1");
     Assertion.AssertEquals("v", p.GetEvaluatedProperty("n"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例14: SetPropertyCondition_Empty

 public void SetPropertyCondition_Empty()
 {
     Project p = new Project();
     p.SetProperty("n", "v", String.Empty);
     Assertion.AssertEquals("v", p.GetEvaluatedProperty("n"));
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs

示例15: SetPropertySet_ValueNull

 public void SetPropertySet_ValueNull()
 {
     Project p = new Project();
     string value = null;
     p.SetProperty("n", value);
 }
开发者ID:nikson,项目名称:msbuild,代码行数:6,代码来源:Project_Tests.cs


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