本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance.GetProperty方法的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance.GetProperty方法的具体用法?C# ProjectInstance.GetProperty怎么用?C# ProjectInstance.GetProperty使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Build.Execution.ProjectInstance
的用法示例。
在下文中一共展示了ProjectInstance.GetProperty方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ItemsAndProperties
public void ItemsAndProperties ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<ItemGroup>
<X Condition='false' Include='bar.txt' />
<X Include='foo.txt'>
<M>m</M>
<N>=</N>
</X>
</ItemGroup>
<PropertyGroup>
<P Condition='false'>void</P>
<P Condition='true'>valid</P>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader(project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
var item = proj.Items.First ();
Assert.AreEqual ("foo.txt", item.EvaluatedInclude, "#1");
var prop = proj.Properties.First (p => p.Name=="P");
Assert.AreEqual ("valid", prop.EvaluatedValue, "#2");
Assert.IsNotNull (proj.GetProperty ("MSBuildProjectDirectory"), "#3");
Assert.AreEqual ("4.0", proj.ToolsVersion, "#4");
}
示例2: AssertPropertyDoesNotExist
public static void AssertPropertyDoesNotExist(ProjectInstance projectInstance, string propertyName)
{
ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);
string value = propertyInstance == null ? null : propertyInstance.EvaluatedValue;
Assert.IsNull(propertyInstance, "Not expecting the property to exist. Property: {0}, Value: {1}", propertyName, value);
}
示例3: catch
/// <summary>
/// Add a PropertyGroup to the project for a particular Asp.Net configuration. This PropertyGroup
/// will have the correct values for all the Asp.Net properties for this project and this configuration.
/// </summary>
private void AddPropertyGroupForAspNetConfiguration
(
ProjectInstance traversalProject,
ProjectInstance metaprojectInstance,
ProjectInSolution project,
string configurationName,
AspNetCompilerParameters aspNetCompilerParameters,
string solutionFile
)
{
// If the configuration doesn't match, don't add the properties.
if (!traversalProject.EvaluateCondition(String.Format(CultureInfo.InvariantCulture, " '$(AspNetConfiguration)' == '{0}' ", EscapingUtilities.Escape(configurationName))))
{
return;
}
// Add properties into the property group for each of the AspNetCompiler properties.
// REVIEW: SetProperty takes an evaluated value. Are we doing the right thing here?
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetVirtualPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetVirtualPath));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetPhysicalPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetPhysicalPath));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetTargetPath"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetTargetPath));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetForce"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetForce));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetUpdateable"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetUpdateable));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetDebug"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetDebug));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetKeyFile"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetKeyFile));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetKeyContainer"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetKeyContainer));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetDelaySign"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetDelaySign));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetAPTCA"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetAPTCA));
metaprojectInstance.SetProperty(GenerateSafePropertyName(project, "AspNetFixedNames"), EscapingUtilities.Escape(aspNetCompilerParameters.aspNetFixedNames));
string aspNetPhysicalPath = aspNetCompilerParameters.aspNetPhysicalPath;
if (!String.IsNullOrEmpty(aspNetPhysicalPath))
{
// Trim the trailing slash if one exists.
if (
(aspNetPhysicalPath[aspNetPhysicalPath.Length - 1] == Path.AltDirectorySeparatorChar) ||
(aspNetPhysicalPath[aspNetPhysicalPath.Length - 1] == Path.DirectorySeparatorChar)
)
{
aspNetPhysicalPath = aspNetPhysicalPath.Substring(0, aspNetPhysicalPath.Length - 1);
}
// This gets us the last folder in the physical path.
string lastFolderInPhysicalPath = null;
try
{
lastFolderInPhysicalPath = Path.GetFileName(aspNetPhysicalPath);
}
catch (Exception e)
{
if (ExceptionHandling.NotExpectedException(e))
{
throw;
}
ProjectFileErrorUtilities.VerifyThrowInvalidProjectFile
(
false,
"SubCategoryForSolutionParsingErrors",
new BuildEventFileInfo(solutionFile),
e,
"SolutionParseInvalidProjectFileName",
project.RelativePath,
e.Message
);
}
if (!String.IsNullOrEmpty(lastFolderInPhysicalPath))
{
// If there is a global property called "OutDir" set, that means the caller is trying to
// override the AspNetTargetPath. What we want to do in this case is concatenate:
// $(OutDir) + "\_PublishedWebsites" + (the last portion of the folder in the AspNetPhysicalPath).
if (traversalProject.EvaluateCondition(" '$(OutDir)' != '' "))
{
string outDirValue = String.Empty;
ProjectPropertyInstance outdir = metaprojectInstance.GetProperty("OutDir");
if (outdir != null)
{
outDirValue = ProjectInstance.GetPropertyValueEscaped(outdir);
}
// Make sure the path we are appending to has no leading slash to prevent double slashes.
string publishWebsitePath = EscapingUtilities.Escape(WebProjectOverrideFolder) + Path.DirectorySeparatorChar + EscapingUtilities.Escape(lastFolderInPhysicalPath) + Path.DirectorySeparatorChar;
metaprojectInstance.SetProperty
(
GenerateSafePropertyName(project, "AspNetTargetPath"),
outDirValue + publishWebsitePath
);
}
}
}
}
示例4: AssertAnalysisTargetsAreImported
private static void AssertAnalysisTargetsAreImported(ProjectInstance projectInstance)
{
ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(DummyAnalysisTargetsMarkerProperty);
Assert.IsNotNull(propertyInstance, "Failed to import the SonarQube Analysis targets");
}
示例5: AssertAnalysisTargetsAreNotImported
private static void AssertAnalysisTargetsAreNotImported(ProjectInstance projectInstance)
{
ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(DummyAnalysisTargetsMarkerProperty);
Assert.IsNull(propertyInstance, "SonarQube Analysis targets should not have been imported");
}
示例6: GetMsBuildProperty
protected static ProjectPropertyInstance GetMsBuildProperty(ProjectInstance projectInstance, string propertyName)
{
return projectInstance.GetProperty(propertyName);
}
示例7: ConditionalExpression
public void ConditionalExpression ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
<NoCompilerStandardLib>true</NoCompilerStandardLib>
<ResolveAssemblyReferencesDependsOn>$(ResolveAssemblyReferencesDependsOn);_AddCorlibReference</ResolveAssemblyReferencesDependsOn>
</PropertyGroup>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj";
var proj = new ProjectInstance (root);
var p = proj.GetProperty ("ResolveAssemblyReferencesDependsOn");
Assert.IsNotNull (p, "#1");
Assert.AreEqual (";_AddCorlibReference", p.EvaluatedValue, "#2");
}
示例8: 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 = "ProjectInstanceTest.Choose.proj";
var proj = new ProjectInstance (root);
var p = proj.GetProperty ("DebugXXX");
Assert.IsNotNull (p, "#1");
Assert.AreEqual ("False", p.EvaluatedValue, "#2");
}
示例9: EvaluatePropertyWithQuotation
public void EvaluatePropertyWithQuotation ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<ItemGroup>
<Foo Include='abc/xxx.txt' />
</ItemGroup>
<PropertyGroup>
<B>foobar</B>
</PropertyGroup>
<Target Name='default'>
<CreateProperty Value=""@(Foo->'%(Filename)%(Extension)')"">
<Output TaskParameter='Value' PropertyName='P' />
</CreateProperty>
<CreateProperty Value='$(B)|$(P)'>
<Output TaskParameter='Value' PropertyName='Q' />
</CreateProperty>
</Target>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
root.FullPath = "ProjectInstanceTest.EvaluatePropertyWithQuotation.proj";
var proj = new ProjectInstance (root);
proj.Build ();
var p = proj.GetProperty ("P");
Assert.AreEqual ("xxx.txt", p.EvaluatedValue, "#1");
var q = proj.GetProperty ("Q");
Assert.AreEqual ("foobar|xxx.txt", q.EvaluatedValue, "#2");
}
示例10: 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);
}
}
示例11: AssertPropertyExists
public static ProjectPropertyInstance AssertPropertyExists(ProjectInstance projectInstance, string propertyName)
{
ProjectPropertyInstance propertyInstance = projectInstance.GetProperty(propertyName);
Assert.IsNotNull(propertyInstance, "The expected property does not exist: {0}", propertyName);
return propertyInstance;
}