Skip to content

Trying to get a simple example to work using Microsoft.Build, but can't #10256

Discussion options

You must be logged in to vote

@amine-aboufirass, note this text in the documentation:

You can't reference any MSBuild types (from the Microsoft.Build namespace) in the method that calls MSBuildLocator.

In your code, the Project proj = new Project(projectFilePath); statement seems to be in the same method as the MSBuildLocator.RegisterDefaults() call. You should move it to a second method, so that things can proceed in this order:

  1. The .NET Runtime compiles the first method. Because the first method does not reference MSBuild types such as Project, the .NET Runtime does not need to find the definitions of those types yet.
  2. The first method starts running, and calls MSBuildLocator.RegisterDefaults(), which makes the MS…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@amine-aboufirass
Comment options

@KalleOlaviNiemitalo
Comment options

Answer selected by amine-aboufirass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants