Skip to content

Commit 6b60d34

Browse files
authored
Merge pull request #4935 from Forgind/patch-1
Explain need for Locator API call
2 parents 8e3ca44 + f5d1b6e commit 6b60d34

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

docs/msbuild/updating-an-existing-application.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,33 @@ Do not specify `ExcludeAssets=runtime` for the Microsoft.Build.Locator package.
7979

8080
### Register instance before calling MSBuild
8181

82-
Add a call to the Locator API before calling any method that uses MSBuild.
82+
> [!IMPORTANT]
83+
> You cannot reference any MSBuild types (from the `Microsoft.Build` namespace) in the method that calls MSBuildLocator. For example, you cannot do this:
84+
>
85+
> ```csharp
86+
> void ThisWillFail()
87+
> {
88+
> MSBuildLocator.RegisterDefaults();
89+
> Project p = new Project(SomePath); // Could be any MSBuild type
90+
> // Code that uses the MSBuild type
91+
> }
92+
> ```
93+
>
94+
> Instead, you must do this:
95+
>
96+
> ```csharp
97+
> void MethodThatDoesNotDirectlyCallMSBuild()
98+
> {
99+
> MSBuildLocator.RegisterDefaults();
100+
> MethodThatCallsMSBuild();
101+
> }
102+
>
103+
> void MethodThatCallsMSBuild()
104+
> {
105+
> Project p = new Project(SomePath);
106+
> // Code that uses the MSBuild type
107+
> }
108+
> ```
83109
84110
The simplest way to add the call to the Locator API is to add a call to
85111

0 commit comments

Comments
 (0)