Please observe CPS project locking rules by not retaining any references to MSBuild objects beyond the scope of the lock and only using these objects while not on the UI thread. Violating this exposes your code and other project-related code to the risk of multithread-related IDE crashes, even if you're just reading the project.
Note that importing any CPS related service moves your MEF part from the
VS default MEF catalog into a CPS catalog "sub-scope". Import properties
are only 'satisfied' when MEF activated your type (not simply by new
ing
up an instance of your object).
[Import]
IProjectLockService ProjectLockService { get; set; }
IProjectService projectService;
IProjectLockService projectLockService = projectService.Services.ProjectLockService;
Initialize the projectService
variable as described here.
IVsBrowseObjectContext context;
IProjectLockService projectLockService = context.UnconfiguredProject.ProjectService.Services.ProjectLockService;
Initialize the context
variable as described here.