本文整理汇总了C#中Microsoft.Build.BuildEngine.BuildPropertyGroup.SetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# BuildPropertyGroup.SetProperty方法的具体用法?C# BuildPropertyGroup.SetProperty怎么用?C# BuildPropertyGroup.SetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.BuildEngine.BuildPropertyGroup
的用法示例。
在下文中一共展示了BuildPropertyGroup.SetProperty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Metadata
public void Metadata()
{
string content = @"
<i Include='i1' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<m>$(p)</m>
<n>n1</n>
</i>";
XmlDocument doc = new XmlDocument();
doc.LoadXml(content);
BuildItem item = CreateBuildItemFromXmlDocument(doc);
Assertion.AssertEquals("i", item.Name);
BuildPropertyGroup properties = new BuildPropertyGroup();
properties.SetProperty("p", "p1");
// Evaluated
Expander expander = new Expander(properties, null, ExpanderOptions.ExpandAll);
item.EvaluateAllItemMetadata(expander, ParserOptions.AllowPropertiesAndItemLists, null, null);
Assertion.AssertEquals("p1", item.GetEvaluatedMetadata("m"));
// Unevaluated
Assertion.AssertEquals("$(p)", item.GetMetadata("m"));
Assertion.AssertEquals("n1", item.GetMetadata("n"));
// All custom metadata
ArrayList metadataNames = new ArrayList(item.CustomMetadataNames);
Assertion.Assert(metadataNames.Contains("n"));
Assertion.Assert(metadataNames.Contains("m"));
// Custom metadata count only
Assertion.AssertEquals(2, item.CustomMetadataCount);
// All metadata count
Assertion.AssertEquals(2 + FileUtilities.ItemSpecModifiers.All.Length, item.MetadataCount);
}
示例2: Build
public static bool Build(Project pProj, OutputWindowPane pPane, string pTarget, NameValueCollection pParams)
{
Microsoft.Build.BuildEngine.Engine buildEngine = new Microsoft.Build.BuildEngine.Engine();
BuildExecutor executor = new BuildExecutor(pPane);
RegistryKey key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\.NETFramework", false);
if (key == null) {
throw new Exception("Failed to determine .NET Framework install root - no .NETFramework key");
}
string installRoot = key.GetValue("InstallRoot") as string;
if (installRoot == null) {
throw new Exception("Failed to determine .NET Framework install root - no InstallRoot value");
}
key.Close();
buildEngine.BinPath = Path.Combine(installRoot, string.Format("v{0}.{1}.{2}", Environment.Version.Major, Environment.Version.Minor, Environment.Version.Build));
buildEngine.RegisterLogger(executor);
executor.Verbosity = LoggerVerbosity.Normal;
BuildPropertyGroup properties = new BuildPropertyGroup();
foreach (string propKey in pParams.Keys) {
string val = pParams[propKey];
properties.SetProperty(propKey, val, true);
}
return buildEngine.BuildProjectFile(pProj.FileName, new string[]{pTarget}, properties);
}
示例3: CantModifyThroughEnumerator
public void CantModifyThroughEnumerator()
{
BuildPropertyGroup pg = new BuildPropertyGroup();
// Only NormalProperties are modifiable anyway
BuildProperty p1 = new BuildProperty("name1", "value1", PropertyType.NormalProperty);
pg.SetProperty(p1);
BuildPropertyGroupProxy proxy = new BuildPropertyGroupProxy(pg);
Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
// Get the one property
foreach (DictionaryEntry prop in proxy)
{
list.Add(prop.Key, prop.Value);
}
// Change the property
Assertion.Assert((string)list["name1"] == "value1");
list["name1"] = "newValue";
Assertion.Assert((string)list["name1"] == "newValue");
// Get the property again
list = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry prop in proxy)
{
list.Add(prop.Key, prop.Value);
}
// Property value hasn't changed
Assertion.Assert((string)list["name1"] == "value1");
}
示例4: SimpleAddAndRetrieveProject
public void SimpleAddAndRetrieveProject()
{
// Initialize engine.
Engine engine = new Engine(@"c:\");
// Instantiate new project manager.
ProjectManager projectManager = new ProjectManager();
// Set up variables that represent the information we would be getting from
// the "MSBuild" task.
string fullPath = @"c:\rajeev\temp\myapp.proj";
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
globalProperties.SetProperty("Configuration", "Debug");
// Create a new project that matches the information that we're pretending
// to receive from the MSBuild task.
Project project1 = new Project(engine);
project1.FullFileName = fullPath;
project1.GlobalProperties = globalProperties;
// Add the new project to the ProjectManager.
projectManager.AddProject(project1);
// Try and retrieve the project from the ProjectManager based on the fullpath + globalprops,
// and make sure we get back the same project we added.
Assertion.AssertEquals(project1, projectManager.GetProject(fullPath, globalProperties, null));
}
示例5: BasicProxying
public void BasicProxying()
{
BuildPropertyGroup pg = new BuildPropertyGroup();
BuildProperty p1 = new BuildProperty("name1", "value1", PropertyType.EnvironmentProperty);
BuildProperty p2 = new BuildProperty("name2", "value2", PropertyType.GlobalProperty);
pg.SetProperty(p1);
pg.SetProperty(p2);
BuildPropertyGroupProxy proxy = new BuildPropertyGroupProxy(pg);
Hashtable list = new Hashtable(StringComparer.OrdinalIgnoreCase);
foreach (DictionaryEntry prop in proxy)
{
list.Add(prop.Key, prop.Value);
}
Assertion.Assert(list.Count == 2);
Assertion.Assert((string)list["name1"] == "value1");
Assertion.Assert((string)list["name2"] == "value2");
}
示例6: SetupMembers
private void SetupMembers()
{
pg1 = new BuildPropertyGroup();
pg1.SetProperty("foo", "bar");
pg1.SetProperty("abc", "true");
pg1.SetProperty("Unit", "inches");
pg2 = new BuildPropertyGroup();
pg2.SetProperty("foo", "bar");
pg2.SetProperty("abc", "true");
pg3 = new BuildPropertyGroup();
// These Choose objects are only suitable for
// holding a place in the GroupingCollection.
choose1 = new Choose();
choose2 = new Choose();
choose3 = new Choose();
ig1 = new BuildItemGroup();
ig1.AddNewItem("x", "x1");
ig1.AddNewItem("x", "x2");
ig1.AddNewItem("y", "y1");
ig1.AddNewItem("y", "y2");
ig1.AddNewItem("y", "y3");
ig1.AddNewItem("y", "y4");
ig2 = new BuildItemGroup();
ig2.AddNewItem("jacksonfive", "germaine");
ig2.AddNewItem("jacksonfive", "tito");
ig2.AddNewItem("jacksonfive", "michael");
ig2.AddNewItem("jacksonfive", "latoya");
ig2.AddNewItem("jacksonfive", "janet");
ig3 = new BuildItemGroup();
}
示例7: DoBuild
public bool DoBuild(BuildJob job, ILogger logger)
{
engine.RegisterLogger(logger);
Program.Log("Building target '" + job.Target + "' in " + job.ProjectFileName);
string[] targets = job.Target.Split(';');
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
foreach (var pair in job.Properties) {
globalProperties.SetProperty(pair.Key, pair.Value, true);
}
try {
return engine.BuildProjectFile(job.ProjectFileName, targets, globalProperties);
} finally {
engine.UnregisterAllLoggers();
}
}
示例8: ImportOutputProperties
public void ImportOutputProperties()
{
BuildPropertyGroup pg = new BuildPropertyGroup();
pg.SetProperty("foo", "fooval");
pg.SetProperty(new BuildProperty("bar", "barval", PropertyType.EnvironmentProperty));
pg.SetProperty(new BuildProperty("baz", "bazval", PropertyType.GlobalProperty));
pg.SetProperty(new BuildProperty("caz", "cazval", PropertyType.ImportedProperty));
pg.SetProperty(new BuildProperty("barb", "barbval", PropertyType.OutputProperty));
BuildPropertyGroup pgo = new BuildPropertyGroup();
pgo.SetProperty(new BuildProperty("foo", "fooout", PropertyType.OutputProperty));
pgo.SetProperty(new BuildProperty("bar", "barout", PropertyType.OutputProperty));
pgo.SetProperty(new BuildProperty("baz", "bazout", PropertyType.OutputProperty));
pgo.SetProperty(new BuildProperty("caz", "cazout", PropertyType.OutputProperty));
pgo.SetProperty(new BuildProperty("barb", "barbout", PropertyType.OutputProperty));
pgo.SetProperty(new BuildProperty("gaz", "gazout", PropertyType.OutputProperty));
pg.ImportProperties(pgo);
Assertion.AssertEquals(6, pg.Count);
Assertion.AssertEquals("fooout", pg["foo"].FinalValueEscaped);
Assertion.AssertEquals("barout", pg["bar"].FinalValueEscaped);
Assertion.AssertEquals("bazout", pg["baz"].FinalValueEscaped);
Assertion.AssertEquals("cazout", pg["caz"].FinalValueEscaped);
Assertion.AssertEquals("barbout", pg["barb"].FinalValueEscaped);
Assertion.AssertEquals("gazout", pg["gaz"].FinalValueEscaped);
pg.SetProperty(new BuildProperty("foo", "fooout2", PropertyType.OutputProperty));
pg.SetProperty(new BuildProperty("gaz", "gazout2", PropertyType.OutputProperty));
Assertion.AssertEquals("fooout2", pg["foo"].FinalValueEscaped);
Assertion.AssertEquals("gazout2", pg["gaz"].FinalValueEscaped);
pg.RemoveProperty("baz");
pg.RevertAllOutputProperties();
Assertion.AssertEquals(3, pg.Count);
Assertion.AssertEquals("fooval", pg["foo"].FinalValueEscaped);
Assertion.AssertEquals("barval", pg["bar"].FinalValueEscaped);
Assertion.AssertNull(pg["baz"]);
Assertion.AssertEquals("cazval", pg["caz"].FinalValueEscaped);
Assertion.AssertNull(pg["barb"]);
}
示例9: TestConstructor1andProperties
public void TestConstructor1andProperties()
{
int nodeProxyId = 1;
string projectFileName = "ProjectFileName";
string[] targetNames = new string[] { "Build" };
BuildPropertyGroup globalProperties = null;
int requestId = 1;
BuildRequest firstConstructorRequest = new BuildRequest(nodeProxyId, projectFileName, targetNames, globalProperties, null, requestId, false, false);
Assert.AreEqual(1, firstConstructorRequest.HandleId, "Expected firstConstructorRequest.NodeProxyId to be 1");
firstConstructorRequest.HandleId = 2;
Assert.AreEqual(2, firstConstructorRequest.HandleId, "Expected firstConstructorRequest.NodeProxyId to be 2");
Assert.AreEqual(1, firstConstructorRequest.RequestId, "Expected firstConstructorRequest.RequestId to be 1");
firstConstructorRequest.RequestId = 2;
Assert.AreEqual(2, firstConstructorRequest.RequestId, "Expected firstConstructorRequest.RequestId to be 2");
Assert.IsNull(firstConstructorRequest.GlobalProperties, "Expected firstConstructorRequest.GlobalProperties to be null");
firstConstructorRequest.GlobalProperties = new BuildPropertyGroup();
Assert.IsNotNull(firstConstructorRequest.GlobalProperties, "Expected firstConstructorRequest.GlobalProperties to not be null");
Assert.IsTrue((firstConstructorRequest.TargetNames.Length == 1) && (string.Compare("Build", firstConstructorRequest.TargetNames[0], StringComparison.OrdinalIgnoreCase) == 0), "Expected to have one target with a value of Build in firstConstructorRequest.TargetNames");
Assert.IsTrue(string.Compare("ProjectFileName", firstConstructorRequest.ProjectFileName, StringComparison.OrdinalIgnoreCase) == 0, "Expected firstConstructorRequest.ProjectFileName to be called ProjecFileName");
globalProperties = new BuildPropertyGroup();
BuildProperty propertyToAdd = new BuildProperty("PropertyName", "Value");
globalProperties.SetProperty(propertyToAdd);
firstConstructorRequest = new BuildRequest(nodeProxyId, projectFileName, targetNames, globalProperties, null, requestId, false, false);
Assert.IsNotNull(firstConstructorRequest.GlobalPropertiesPassedByTask, "Expected GlobalPropertiesPassedByTask to not be null");
Assert.IsNotNull(firstConstructorRequest.GlobalProperties, "Expected GlobalPropertiesPassedByTask to not be null");
Assert.IsTrue(string.Compare(firstConstructorRequest.GlobalProperties["PropertyName"].Value, "Value", StringComparison.OrdinalIgnoreCase) == 0, "Expected GlobalProperties, propertyname to be equal to value");
string buildProperty = ((Hashtable)firstConstructorRequest.GlobalPropertiesPassedByTask)["PropertyName"] as string;
Assert.IsTrue(string.Compare(buildProperty, "Value", StringComparison.OrdinalIgnoreCase) == 0, "Expected hashtable to contain a property group with a value of value");
Assert.IsTrue((firstConstructorRequest.TargetNames.Length == 1) && (string.Compare("Build", firstConstructorRequest.TargetNames[0], StringComparison.OrdinalIgnoreCase) == 0), "Expected to have one target with a value of Build");
Assert.IsTrue(string.Compare("ProjectFileName", firstConstructorRequest.ProjectFileName, StringComparison.OrdinalIgnoreCase) == 0, "Expected project file to be called ProjecFileName");
}
示例10: TestForDuplicatesInProjectTable
public void TestForDuplicatesInProjectTable()
{
ProjectManager projectManager = new ProjectManager();
string fullPath = @"c:\foo\bar.proj";
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
globalProperties.SetProperty("p1", "v1");
Project p = new Project(new Engine());
p.FullFileName = fullPath;
p.GlobalProperties = globalProperties;
p.ToolsVersion = "4.0";
// Add the new project to the ProjectManager, twice
Hashtable table = new Hashtable(StringComparer.OrdinalIgnoreCase);
ProjectManager.AddProject(table, p);
ProjectManager.AddProject(table, p);
Assertion.AssertEquals(1, ((ArrayList)table[fullPath]).Count); // Didn't add a duplicate
// Add a second, slightly different project, and ensure it DOES get added
Project p2 = new Project(new Engine());
p2.FullFileName = fullPath;
p2.GlobalProperties = globalProperties;
p2.ToolsVersion = "2.0";
ProjectManager.AddProject(table, p2);
Project p3 = new Project(new Engine());
p3.FullFileName = fullPath;
p3.GlobalProperties = new BuildPropertyGroup();
p3.ToolsVersion = "2.0";
ProjectManager.AddProject(table, p3);
Assertion.AssertEquals(3, ((ArrayList)table[fullPath]).Count);
}
示例11: ResetBuildStatusForAllProjects
public void ResetBuildStatusForAllProjects()
{
// Initialize engine. Need two separate engines because we don't allow two
// projects with the same full path to be loaded in the same Engine.
Engine engine1 = new Engine(@"c:\");
Engine engine2 = new Engine(@"c:\");
// Instantiate new project manager.
ProjectManager projectManager = new ProjectManager();
// Set up a global property group.
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
globalProperties.SetProperty("Configuration", "Release");
// Create a few new projects.
Project project1 = new Project(engine1);
project1.FullFileName = @"c:\rajeev\temp\myapp.proj";
project1.GlobalProperties = globalProperties;
Project project2 = new Project(engine1);
project2.FullFileName = @"c:\blah\foo.proj";
project2.GlobalProperties = globalProperties;
Project project3 = new Project(engine2);
project3.FullFileName = @"c:\blah\foo.proj";
globalProperties.SetProperty("Configuration", "Debug");
project3.GlobalProperties = globalProperties;
// Add the new projects to the ProjectManager.
projectManager.AddProject(project1);
projectManager.AddProject(project2);
projectManager.AddProject(project3);
// Put all the projects in a non-reset state.
project1.IsReset = false;
project2.IsReset = false;
project3.IsReset = false;
// Call ResetAllProjects.
projectManager.ResetBuildStatusForAllProjects();
// Make sure they all got reset.
Assertion.Assert(project1.IsReset);
Assertion.Assert(project2.IsReset);
Assertion.Assert(project3.IsReset);
}
示例12: SimpleAddAndRetrieveProjectWithDifferentFullPath
public void SimpleAddAndRetrieveProjectWithDifferentFullPath()
{
// Initialize engine.
Engine engine = new Engine(@"c:\");
// Instantiate new project manager.
ProjectManager projectManager = new ProjectManager();
// Set up variables that represent the information we would be getting from
// the "MSBuild" task.
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
globalProperties.SetProperty("Configuration", "Release");
// Create a new project that matches the information that we're pretending
// to receive from the MSBuild task.
Project project1 = new Project(engine);
project1.FullFileName = @"c:\rajeev\temp\myapp.proj";
project1.GlobalProperties = globalProperties;
// Add the new project to the ProjectManager.
projectManager.AddProject(project1);
// Now search for a project with a different full path but same set of global
// properties. We expect to get back null, because no such project exists.
Assertion.AssertNull(projectManager.GetProject(@"c:\blah\wrong.proj", globalProperties, null));
}
示例13: TestForDuplicatesInProjectEntryTable
public void TestForDuplicatesInProjectEntryTable()
{
ProjectManager projectManager = new ProjectManager();
string fullPath = @"c:\foo\bar.proj";
BuildPropertyGroup globalProperties = new BuildPropertyGroup();
globalProperties.SetProperty("p1", "v1");
string toolsVersion = "3.5";
// Add the new project entry to the ProjectManager, twice
Hashtable table = new Hashtable(StringComparer.OrdinalIgnoreCase);
ProjectManager.AddProjectEntry(table, fullPath, globalProperties, toolsVersion, 0);
ProjectManager.AddProjectEntry(table, fullPath, globalProperties, toolsVersion, 0);
Assertion.AssertEquals(1, ((ArrayList)table[fullPath]).Count); // Didn't add a duplicate
// Add a second, slightly different project entry, and ensure it DOES get added
ProjectManager.AddProjectEntry(table, fullPath, globalProperties, "2.0", 0);
ProjectManager.AddProjectEntry(table, fullPath, new BuildPropertyGroup(), "2.0", 0);
Assertion.AssertEquals(3, ((ArrayList)table[fullPath]).Count);
}
示例14: Create
//.........这里部分代码省略.........
projectInstance.GetItems("ProjectReference")
.Select(p => p.GetMetadataValue("FullPath"))
.ToList();
projectFileInfo.Analyzers =
projectInstance.GetItems("Analyzer")
.Select(p => p.GetMetadataValue("FullPath"))
.ToList();
var allowUnsafe = projectInstance.GetPropertyValue("AllowUnsafeBlocks");
if (!string.IsNullOrWhiteSpace(allowUnsafe))
{
projectFileInfo.AllowUnsafe = Convert.ToBoolean(allowUnsafe);
}
var defineConstants = projectInstance.GetPropertyValue("DefineConstants");
if (!string.IsNullOrWhiteSpace(defineConstants))
{
projectFileInfo.DefineConstants = defineConstants.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries).Distinct().ToList();
}
}
else
{
// On mono we need to use this API since the ProjectCollection
// isn't fully implemented
#pragma warning disable CS0618
var engine = Engine.GlobalEngine;
engine.DefaultToolsVersion = "4.0";
#pragma warning restore CS0618
// engine.RegisterLogger(new ConsoleLogger());
engine.RegisterLogger(new MSBuildLogForwarder(logger, diagnostics));
var propertyGroup = new BuildPropertyGroup();
propertyGroup.SetProperty("DesignTimeBuild", "true");
propertyGroup.SetProperty("BuildProjectReferences", "false");
// Dump entire assembly reference closure
propertyGroup.SetProperty("_ResolveReferenceDependencies", "true");
propertyGroup.SetProperty("SolutionDir", solutionDirectory + Path.DirectorySeparatorChar);
// propertyGroup.SetProperty("MSBUILDENABLEALLPROPERTYFUNCTIONS", "1");
engine.GlobalProperties = propertyGroup;
var project = engine.CreateNewProject();
project.Load(projectFilePath);
var buildResult = engine.BuildProjectFile(projectFilePath, new[] { "ResolveReferences" }, propertyGroup, null, BuildSettings.None, null);
if (!buildResult)
{
return null;
}
var itemsLookup = project.EvaluatedItems.OfType<BuildItem>()
.ToLookup(g => g.Name);
var properties = project.EvaluatedProperties.OfType<BuildProperty>()
.ToDictionary(p => p.Name);
projectFileInfo.AssemblyName = properties["AssemblyName"].FinalValue;
projectFileInfo.Name = Path.GetFileNameWithoutExtension(projectFilePath);
projectFileInfo.TargetFramework = new FrameworkName(properties["TargetFrameworkMoniker"].FinalValue);
if (properties.ContainsKey("LangVersion"))
{
projectFileInfo.SpecifiedLanguageVersion = ToLanguageVersion(properties["LangVersion"].FinalValue);
}
projectFileInfo.ProjectId = new Guid(properties["ProjectGuid"].FinalValue.TrimStart('{').TrimEnd('}'));
示例15: TestSetProperty2
public void TestSetProperty2 ()
{
BuildPropertyGroup bpg = new BuildPropertyGroup ();
bpg.SetProperty ("name", null);
}