本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance.GetPropertyValue方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance.GetPropertyValue方法的具体用法?C# ProjectInstance.GetPropertyValue怎么用?C# ProjectInstance.GetPropertyValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Execution.ProjectInstance
的用法示例。
在下文中一共展示了ProjectInstance.GetPropertyValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OutputPropertyExists
public void OutputPropertyExists ()
{
string project_xml = @"
<Project DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<C>False</C>
</PropertyGroup>
<Target Name='Build' DependsOnTargets='ResolveReferences' />
<Target Name='Build2' DependsOnTargets='Bar' />
<Target Name='ResolveReferences' DependsOnTargets='Foo;Bar' />
<Target Name='Foo'>
<CreateProperty Value='True'>
<Output TaskParameter='Value' PropertyName='C' />
</CreateProperty>
</Target>
<Target Name='Bar' Condition='!($(C))' DependsOnTargets='ResolveReferences'>
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader(project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
Assert.AreEqual (5, proj.Targets.Count, "#1");
var foo = proj.Targets ["Foo"];
Assert.IsNotNull (foo, "#2");
Assert.AreEqual (1, foo.Tasks.Count, "#3");
var cp = foo.Tasks.First ();
Assert.AreEqual (1, cp.Outputs.Count, "#4");
var po = cp.Outputs.First () as ProjectTaskOutputPropertyInstance;
Assert.IsNotNull (po, "#5");
Assert.AreEqual ("C", po.PropertyName, "#5");
proj.Build ("Build", null);
Assert.AreEqual (string.Empty, foo.Outputs, "#6");
Assert.AreEqual ("True", proj.GetPropertyValue ("C"), "#7");
}
示例2: GetPdtarSearchPaths
private static string[] GetPdtarSearchPaths(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(ProjectDesignTimeAssemblyResolutionSearchPaths).Trim();
string[] _pdtarSearchPaths = val.Split(';').Select(s => s.Trim()).ToArray();
return _pdtarSearchPaths;
}
示例3: GetIgnoreDefaultInstalledAssemblySubsetTables
private static bool GetIgnoreDefaultInstalledAssemblySubsetTables(ProjectInstance projectInstance)
{
bool ignoreDefaultInstalledAssemblySubsetTables = false;
string val = projectInstance.GetPropertyValue(IgnoreInstalledAssemblySubsetTables).Trim();
if (!String.IsNullOrEmpty(val))
{
if (val == Boolean.TrueString || val == Boolean.FalseString)
{
ignoreDefaultInstalledAssemblySubsetTables = Convert.ToBoolean(val, CultureInfo.InvariantCulture);
}
}
return ignoreDefaultInstalledAssemblySubsetTables;
}
示例4: GetFullTargetFrameworkSubsetNames
private static string[] GetFullTargetFrameworkSubsetNames(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(FullReferenceAssemblyNames).Trim();
string[] fullTargetFrameworkSubsetNames = val.Split(';').Select(s => s.Trim()).ToArray();
return fullTargetFrameworkSubsetNames;
}
示例5: GetTargetedRuntimeVersion
protected static string GetTargetedRuntimeVersion(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(TargetedRuntimeVersionName).Trim();
return val;
}
示例6: GetMetaprojectGlobalProperties
/// <summary>
/// Retrieves a dictionary representing the global properties which should be transferred to a metaproject.
/// </summary>
/// <param name="traversalProject">The traversal from which the global properties should be obtained.</param>
/// <returns>A dictionary of global properties.</returns>
private IDictionary<string, string> GetMetaprojectGlobalProperties(ProjectInstance traversalProject)
{
Dictionary<string, string> properties = new Dictionary<string, string>(_metaprojectGlobalProperties.Length, StringComparer.OrdinalIgnoreCase);
foreach (Tuple<string, string> property in _metaprojectGlobalProperties)
{
if (property.Item2 == null)
{
properties[property.Item1] = EscapingUtilities.Escape(traversalProject.GetPropertyValue(property.Item1));
}
else
{
properties[property.Item1] = EscapingUtilities.Escape(property.Item2);
}
}
// Now provide any which are explicitly set on the solution
foreach (ProjectPropertyInstance globalProperty in traversalProject.GlobalPropertiesDictionary)
{
properties[globalProperty.Name] = ((IProperty)globalProperty).EvaluatedValueEscaped;
}
// If we have a sub-toolset version, it will be set on the P2P from the solution metaproj, so we need
// to make sure it's set here, too, so the global properties will match.
if (traversalProject.SubToolsetVersion != null)
{
if (traversalProject.SubToolsetVersion.Equals("4.0", StringComparison.OrdinalIgnoreCase))
{
properties[Constants.SubToolsetVersionPropertyName] = traversalProject.SubToolsetVersion;
}
}
return properties;
}
示例7: GetTargetProcessorArchitecture
private static string GetTargetProcessorArchitecture(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(ProcessorArchitecture).Trim();
return val;
}
示例8: GetTargetFrameworkMonikerDisplayName
private static string GetTargetFrameworkMonikerDisplayName(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(TargetFrameworkMonikerDisplayNameName).Trim();
return val;
}
示例9: ExpandPropertyThenTrim
public void ExpandPropertyThenTrim ()
{
string test = @"A
B
C
";
string project_xml = string.Format (@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<Test>{0}</Test>
<Test2>$(TEST)</Test2>
</PropertyGroup>
<ItemGroup>
<X Include='$(TEST)' />
<X2 Include='$(TEST)z' />
</ItemGroup>
</Project>", test);
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectItemTest.ExpandPropertyThenTrim.proj";
var proj = new ProjectInstance (root);
Assert.AreEqual (test, proj.GetPropertyValue ("TEST"), "#1");
Assert.AreEqual (test, proj.GetPropertyValue ("TEST2"), "#2");
Assert.AreEqual (test.Trim (), proj.GetItems ("X").First ().EvaluatedInclude, "#3");
Assert.AreEqual (test + "z", proj.GetItems ("X2").First ().EvaluatedInclude, "#4");
}
示例10: getProjectGuid
static Guid getProjectGuid(ProjectInstance instance)
{
var projectGuid = instance.GetPropertyValue("ProjectGuid");
if (projectGuid == "")
throw new Exception("project has no Guid");
return Guid.Parse(projectGuid);
}
示例11: ItemsInTargets
[Category ("NotWorking")] // until we figure out why it fails on wrench.
public void ItemsInTargets ()
{
string project_xml = @"<Project DefaultTargets='Default' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='Default'>
<PropertyGroup>
<_ExplicitMSCorlibPath>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll</_ExplicitMSCorlibPath>
</PropertyGroup>
<ItemGroup>
<_ExplicitReference
Include='$(_ExplicitMSCorlibPath)'
Condition='Exists($(_ExplicitMSCorlibPath))'>
<Private>false</Private>
</_ExplicitReference>
</ItemGroup>
</Target>
<Import Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets' />
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
var proj = new ProjectInstance (root, null, "4.0", ProjectCollection.GlobalProjectCollection);
proj.Build ();
// make sure the property value expansion is done successfully.
Assert.IsTrue (!string.IsNullOrEmpty (proj.GetPropertyValue ("_ExplicitMSCorlibPath")), "premise: propertyValue by ToolLocationHelper func call");
var items = proj.GetItems ("_ExplicitReference");
// make sure items are stored after build.
Assert.IsTrue (items.Any (), "items.Any");
Assert.IsTrue (!string.IsNullOrEmpty (items.First ().EvaluatedInclude), "item.EvaluatedInclude");
}
示例12: PropertyOverrides
public void PropertyOverrides ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<X>x</X>
</PropertyGroup>
<PropertyGroup>
<X>y</X>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectTest.BuildCSharpTargetBuild.proj";
var proj = new ProjectInstance (root);
Assert.AreEqual ("y", proj.GetPropertyValue ("X"), "#1");
}
示例13: GetTargetFrameworkMoniker
protected static string GetTargetFrameworkMoniker(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(TargetFrameworkMonikerName).Trim();
return val;
}
示例14: GetProfileName
private static string GetProfileName(ProjectInstance projectInstance)
{
string val = projectInstance.GetPropertyValue(TargetFrameworkProfile).Trim();
return val;
}
示例15: GetSubToolsetVersion_FromConstructor
public void GetSubToolsetVersion_FromConstructor()
{
string originalVisualStudioVersion = Environment.GetEnvironmentVariable("VisualStudioVersion");
try
{
Environment.SetEnvironmentVariable("VisualStudioVersion", "ABC");
string projectContent = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<Target Name='t'>
<Message Text='Hello'/>
</Target>
</Project>";
ProjectRootElement xml = ProjectRootElement.Create(XmlReader.Create(new StringReader(projectContent)));
IDictionary<string, string> globalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
globalProperties.Add("VisualStudioVersion", "ABCD");
IDictionary<string, string> projectCollectionGlobalProperties = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
projectCollectionGlobalProperties.Add("VisualStudioVersion", "ABCDE");
ProjectInstance p = new ProjectInstance(xml, globalProperties, "4.0", "ABCDEF", new ProjectCollection(projectCollectionGlobalProperties));
Assert.Equal("4.0", p.Toolset.ToolsVersion);
Assert.Equal("ABCDEF", p.SubToolsetVersion);
Assert.Equal("ABCDEF", p.GetPropertyValue("VisualStudioVersion"));
}
finally
{
Environment.SetEnvironmentVariable("VisualStudioVersion", originalVisualStudioVersion);
}
}