33// Licensed under the MIT license.
44
55using Microsoft . Build . Execution ;
6+ using System . Collections . Generic ;
7+ using System . Linq ;
68
79namespace Microsoft . Build . Utilities . ProjectCreation
810{
@@ -75,5 +77,53 @@ public ProjectCreator TryBuild(out bool result, out BuildOutput buildOutput)
7577
7678 return this ;
7779 }
80+
81+ /// <summary>
82+ /// Attempts to build the current project.
83+ /// </summary>
84+ /// <param name="target">The name of the target to build.</param>
85+ /// <param name="result">A value indicating the result of the build.</param>
86+ /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
87+ /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
88+ /// <returns>The current <see cref="ProjectCreator"/>.</returns>
89+ public ProjectCreator TryBuild ( string target , out bool result , out BuildOutput buildOutput , out IDictionary < string , TargetResult > targetOutputs )
90+ {
91+ return TryBuild ( new [ ] { target } , out result , out buildOutput , out targetOutputs ) ;
92+ }
93+
94+ /// <summary>
95+ /// Attempts to build the current project.
96+ /// </summary>
97+ /// <param name="targets">The names of the targets to build.</param>
98+ /// <param name="result">A value indicating the result of the build.</param>
99+ /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
100+ /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
101+ /// <returns>The current <see cref="ProjectCreator"/>.</returns>
102+ public ProjectCreator TryBuild ( string [ ] targets , out bool result , out BuildOutput buildOutput , out IDictionary < string , TargetResult > targetOutputs )
103+ {
104+ buildOutput = BuildOutput . Create ( ) ;
105+
106+ lock ( BuildManager . DefaultBuildManager )
107+ {
108+ ProjectInstance projectInstance = Project . CreateProjectInstance ( ) ;
109+
110+ result = projectInstance . Build ( targets , buildOutput . AsEnumerable ( ) , out targetOutputs ) ;
111+ }
112+
113+ return this ;
114+ }
115+
116+ /// <summary>
117+ /// Attempts to build the current project.
118+ /// </summary>
119+ /// <param name="targets">The names of the targets to build.</param>
120+ /// <param name="result">A value indicating the result of the build.</param>
121+ /// <param name="buildOutput">A <see cref="BuildOutput"/> object that captured the logging from the build.</param>
122+ /// <param name="targetOutputs">A <see cref="IDictionary{String,TargetResult}" /> containing the target outputs.</param>
123+ /// <returns>The current <see cref="ProjectCreator"/>.</returns>
124+ public ProjectCreator TryBuild ( IEnumerable < string > targets , out bool result , out BuildOutput buildOutput , out IDictionary < string , TargetResult > targetOutputs )
125+ {
126+ return TryBuild ( targets . ToArray ( ) , out result , out buildOutput , out targetOutputs ) ;
127+ }
78128 }
79129}
0 commit comments