ProjectRootElement.TryOpen Method

Definition

Gets the project root in the global project collection that was loaded into memory from the specified file path. or null if it is not currently in memory.

Overloads

TryOpen(String)

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the global project collection.

TryOpen(String, ProjectCollection)

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the specified project collection.

TryOpen(String, ProjectCollection, Nullable<Boolean>)

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the specified project collection.

TryOpen(String)

Source:
ProjectRootElement.cs

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the global project collection.

C#
public static Microsoft.Build.Construction.ProjectRootElement TryOpen(string path);

Parameters

path
String

The path of the ProjectRootElement, cannot be null.

Returns

The loaded ProjectRootElement, or null if it is not currently in memory.

Remarks

It is possible for ProjectRootElements to be brought into memory and discarded due to memory pressure. Therefore this method returning false does not indicate that it has never been loaded, only that it is not currently in memory.

Applies to

MSBuild 17 およびその他のバージョン
製品 バージョン
MSBuild 15, 16, 17
MSBuild (.NET Core) 15, 16, 17

TryOpen(String, ProjectCollection)

Source:
ProjectRootElement.cs

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the specified project collection.

C#
public static Microsoft.Build.Construction.ProjectRootElement TryOpen(string path, Microsoft.Build.Evaluation.ProjectCollection projectCollection);

Parameters

path
String

The path of the ProjectRootElement, cannot be null.

projectCollection
ProjectCollection

The ProjectCollection to load the project into.

Returns

The loaded ProjectRootElement, or null if it is not currently in memory.

Remarks

It is possible for ProjectRootElements to be brought into memory and discarded due to memory pressure. Therefore this method returning false does not indicate that it has never been loaded, only that it is not currently in memory.

Applies to

MSBuild 17 およびその他のバージョン
製品 バージョン
MSBuild 15, 16, 17
MSBuild (.NET Core) 15, 16, 17

TryOpen(String, ProjectCollection, Nullable<Boolean>)

Source:
ProjectRootElement.cs

Returns the ProjectRootElement for the given path if it has been loaded, or null if it is not currently in memory. Uses the specified project collection.

C#
public static Microsoft.Build.Construction.ProjectRootElement TryOpen(string path, Microsoft.Build.Evaluation.ProjectCollection projectCollection, bool? preserveFormatting);

Parameters

path
String

The path of the ProjectRootElement, cannot be null.

projectCollection
ProjectCollection

The ProjectCollection to load the project into.

preserveFormatting
Nullable<Boolean>

The formatting to open with. Must match the formatting in the collection to succeed.

Returns

The loaded ProjectRootElement, or null if it is not currently in memory.

Remarks

It is possible for ProjectRootElements to be brought into memory and discarded due to memory pressure. Therefore this method returning false does not indicate that it has never been loaded, only that it is not currently in memory.

Applies to

MSBuild 17 およびその他のバージョン
製品 バージョン
MSBuild 15, 16, 17
MSBuild (.NET Core) 15, 16, 17