本文整理汇总了C#中Microsoft.Build.Execution.ProjectInstance类的典型用法代码示例。如果您正苦于以下问题:C# ProjectInstance类的具体用法?C# ProjectInstance怎么用?C# ProjectInstance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProjectInstance类属于Microsoft.Build.Execution命名空间,在下文中一共展示了ProjectInstance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestResolveEnvironment
public void TestResolveEnvironment() {
var proj1 = new ProjectInstance(TestData.GetPath(@"TestData\Targets\Environments1.pyproj"));
Assert.IsTrue(proj1.Build("TestResolveEnvironment", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) }));
var proj2 = new ProjectInstance(TestData.GetPath(@"TestData\Targets\Environments2.pyproj"));
Assert.IsTrue(proj2.Build("TestResolveEnvironment", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) }));
}
示例2: 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");
}
示例3: BuildAsync
internal static async Task<BuildResult> BuildAsync(this BuildManager buildManager, ITestOutputHelper logger, ProjectCollection projectCollection, ProjectRootElement project, string target, IDictionary<string, string> globalProperties = null, LoggerVerbosity logVerbosity = LoggerVerbosity.Detailed, ILogger[] additionalLoggers = null)
{
Requires.NotNull(buildManager, nameof(buildManager));
Requires.NotNull(projectCollection, nameof(projectCollection));
Requires.NotNull(project, nameof(project));
globalProperties = globalProperties ?? new Dictionary<string, string>();
var projectInstance = new ProjectInstance(project, globalProperties, null, projectCollection);
var brd = new BuildRequestData(projectInstance, new[] { target }, null, BuildRequestDataFlags.ProvideProjectStateAfterBuild);
var parameters = new BuildParameters(projectCollection);
var loggers = new List<ILogger>();
loggers.Add(new ConsoleLogger(logVerbosity, s => logger.WriteLine(s.TrimEnd('\r', '\n')), null, null));
loggers.AddRange(additionalLoggers);
parameters.Loggers = loggers.ToArray();
buildManager.BeginBuild(parameters);
var result = await buildManager.BuildAsync(brd);
buildManager.EndBuild();
return result;
}
示例4: 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");
}
示例5: ExecuteAsync
/// <summary>
/// Builds a project.
/// </summary>
/// <param name="projectInstance">The project to build.</param>
/// <param name="targetsToBuild">The targets to build. If not specified, the project's default target will be invoked.</param>
/// <returns>A task whose result is the result of the build.</returns>
public static async Task<BuildResultAndLogs> ExecuteAsync(ProjectInstance projectInstance, params string[] targetsToBuild)
{
targetsToBuild = (targetsToBuild == null || targetsToBuild.Length == 0) ? projectInstance.DefaultTargets.ToArray() : targetsToBuild;
var logger = new EventLogger();
var logLines = new List<string>();
var parameters = new BuildParameters
{
Loggers = new List<ILogger>
{
new ConsoleLogger(LoggerVerbosity.Detailed, logLines.Add, null, null),
logger,
},
};
BuildResult result;
using (var buildManager = new BuildManager())
{
buildManager.BeginBuild(parameters);
try
{
var brdFlags = BuildRequestDataFlags.ProvideProjectStateAfterBuild;
var requestData = new BuildRequestData(projectInstance, targetsToBuild, null, brdFlags);
var submission = buildManager.PendBuildRequest(requestData);
result = await submission.ExecuteAsync();
}
finally
{
buildManager.EndBuild();
}
}
return new BuildResultAndLogs(result, logger.LogEvents, logLines);
}
示例6: ExplicitToolsVersion
public void ExplicitToolsVersion ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />";
var xml = XmlReader.Create (new StringReader(project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root, null, "4.0", new ProjectCollection ());
Assert.AreEqual ("4.0", proj.ToolsVersion, "#1");
}
示例7: 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);
}
示例8: BuildRequestData
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices,
BuildRequestDataFlags flags)
{
ProjectInstance = projectInstance;
TargetNames = targetsToBuild;
HostServices = hostServices;
Flags = flags;
}
示例9: ProjectItemInstance
internal ProjectItemInstance (ProjectInstance project, string itemType, IEnumerable<KeyValuePair<string,string>> metadata, string evaluatedInclude)
{
this.project = project;
this.evaluated_include = evaluatedInclude;
this.item_type = itemType;
this.metadata = new List<ProjectMetadataInstance> ();
SetMetadata (metadata);
}
示例10: DefaultTargetsEmpty
public void DefaultTargetsEmpty ()
{
string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
Assert.AreEqual (new string [0], proj.DefaultTargets, "#1");
}
示例11: GetConfigurationProperty
public virtual string GetConfigurationProperty(string propertyName, bool resetCache)
{
if (snapshot == null)
snapshot = proj.CreateProjectInstance(config, platform);
ProjectPropertyInstance property = snapshot.GetProperty(propertyName);
if (property == null)
return null;
return property.EvaluatedValue;
}
示例12: DefaultTargetsFromAttribute
public void DefaultTargetsFromAttribute ()
{
string project_xml = @"<Project DefaultTargets='Foo Bar Baz;Foo' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
</Project>";
var xml = XmlReader.Create (new StringReader (project_xml));
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
string [] expected = {"Foo Bar Baz", "Foo"};
Assert.AreEqual (expected, proj.DefaultTargets, "#1");
}
示例13: ToStringOverride
public void ToStringOverride ()
{
var xml = XmlReader.Create (new StringReader (project_xml));
string path = Path.GetFullPath ("foo.xml");
var root = ProjectRootElement.Create (xml);
var proj = new ProjectInstance (root);
var item = proj.Items.First ();
Assert.AreEqual ("M=m", item.Metadata.First ().ToString (), "#1");
Assert.AreEqual ("N==", item.Metadata.Last ().ToString (), "#2"); // haha
}
示例14: GetProjectReferencesCore
private IEnumerable<ProjectFileReference> GetProjectReferencesCore(ProjectInstance executedProject)
{
foreach (var projectReference in GetProjectReferenceItems(executedProject))
{
var filePath = projectReference.EvaluatedInclude;
var aliases = GetAliases(projectReference);
yield return new ProjectFileReference(filePath, aliases);
}
}
示例15: BuildRequestData
public BuildRequestData (ProjectInstance projectInstance, string[] targetsToBuild, HostServices hostServices,
BuildRequestDataFlags flags)
{
if (targetsToBuild == null)
throw new ArgumentNullException ("targetsToBuild");
ProjectInstance = projectInstance;
TargetNames = targetsToBuild;
HostServices = hostServices;
Flags = flags;
}