33// Licensed under the MIT license.
44
55using Microsoft . Build . Evaluation ;
6+ using Microsoft . Build . Evaluation . Context ;
7+ using Microsoft . Build . Execution ;
68using System ;
79using System . Collections . Generic ;
810
@@ -20,6 +22,11 @@ public partial class ProjectCreator
2022 /// </summary>
2123 private Project _project ;
2224
25+ /// <summary>
26+ /// Stores the <see cref="ProjectInstance" /> for the current project.
27+ /// </summary>
28+ private ProjectInstance _projectInstance ;
29+
2330 /// <summary>
2431 /// Gets the <see cref="Project"/> instance for the current project. The project is re-evaluated if necessary every time this property is accessed.
2532 /// </summary>
@@ -38,6 +45,11 @@ public Project Project
3845 }
3946 }
4047
48+ /// <summary>
49+ /// Gets the <see cref="ProjectInstance" /> for the current project.
50+ /// </summary>
51+ public ProjectInstance ProjectInstance => _projectInstance ?? ( _projectInstance = Project . CreateProjectInstance ( ) ) ;
52+
4153 /// <summary>
4254 /// Gets a <see cref="Project"/> instance from the current project.
4355 /// </summary>
@@ -97,5 +109,22 @@ public ProjectCreator TryGetProject(
97109
98110 return this ;
99111 }
112+
113+ /// <summary>
114+ /// Gets a <see cref="ProjectInstance" /> from the current project.
115+ /// </summary>
116+ /// <param name="projectInstance">Receives the <see cref="ProjectInstance" />.</param>
117+ /// <param name="projectInstanceSettings">Optional <see cref="ProjectInstanceSettings" /> to use when creating the project instance.</param>
118+ /// <param name="evaluationContext">Optional <see cref="EvaluationContext" /> to use when creating the project instance.</param>
119+ /// <returns>The current <see cref="ProjectCreator"/>.</returns>
120+ public ProjectCreator TryGetProjectInstance (
121+ out ProjectInstance projectInstance ,
122+ ProjectInstanceSettings projectInstanceSettings = ProjectInstanceSettings . None ,
123+ EvaluationContext evaluationContext = null )
124+ {
125+ projectInstance = Project . CreateProjectInstance ( projectInstanceSettings , evaluationContext ) ;
126+
127+ return this ;
128+ }
100129 }
101130}
0 commit comments