@@ -75,8 +75,10 @@ it could occasionally be out of sync with extensions. In this situation,
7575running the following commands inside command-line window will reset the
7676cache:
7777
78- devenv /UpdateConfiguration
79- devenv /ClearCache
78+ ```
79+ devenv /UpdateConfiguration
80+ devenv /ClearCache
81+ ```
8082
8183VS MEF provides a detailed error report when it finds errors inside MEF
8284compositions. It always tries to keep the rest of the components working by
@@ -86,7 +88,9 @@ error report file will help to diagnose issues such as the reason why a
8688certain component is never being loaded into VS. The error report file
8789can be found at
8890
89- [User]\AppData\Local\Microsoft\VisualStudio\[Version]\ComponentModelCache\Microsoft.VisualStudio.Default.err
91+ ```
92+ %LOCALAPPDATA%\Microsoft\VisualStudio\[Version]\ComponentModelCache\Microsoft.VisualStudio.Default.err
93+ ```
9094
9195Because a MEF error may cause chains of errors in other components, one
9296should always start with investigating level 1 composition errors.
@@ -138,10 +142,10 @@ fact that the component carries the correct `AppliesTo` metadata. It is
138142important to use the correct ` AppliesTo ` metadata when defining a component.
139143Normally, the ` AppliesTo ` metadata is the new project type the component
140144supports; in the advanced scenario, ` AppliesTo ` metadata can be an expression
141- like this --
145+ like this:
142146
143147``` csharp
144- [AppliesTo (" MyLanaguageProject + DeviceProject" )]
148+ [AppliesTo (" MyLanaguageProject & DeviceProject" )]
145149```
146150
147151Also, when a component exports additional properties or methods, the
@@ -196,6 +200,36 @@ are provided by CPS and cannot be replaced by extensions. Such services
196200include the ` ConfiguredProject ` , ` UnconfiguredProject ` , ` IProjectLockService ` ,
197201etc.
198202
203+ ### Obtaining MEF components in project scopes
204+
205+ As described in [ scopes] ( scopes.md ) , MEF project-specific components instances
206+ can exist in the scope of an ` UnconfiguredProject ` or a ` ConfiguredProject ` .
207+
208+ If your component is a MEF part and in a compatible scope, then the best way
209+ to obtain an instance is just to import it using a standard MEF import.
210+
211+ However, if your component is not participating in MEF, or is in the global
212+ or ` ProjectService ` scopes, then you can obtain project-scoped components
213+ via the relevant instance of ` UnconfiguredProject ` or ` ConfiguredProject ` .
214+
215+ Note that several key CPS services are available directly on via the project's
216+ ` Services ` property. However if you need a MEF component that is not already
217+ exposed this way, you can use the project's ` ExportProvider ` as follows.
218+
219+ For example:
220+
221+ ``` csharp
222+ UnconfiguredProject unconfiguredProject = .. .;
223+ ConfiguredProject configuredProject = .. .;
224+
225+ IMyUnconfiguredComponent c1 = unconfiguredProject .Services .ExportProvider .GetExportedValue <IMyUnconfiguredComponent >();
226+
227+ IMyConfiguredComponent c2 = configuredProject .Services .ExportProvider .GetExportedValue <IMyConfiguredComponent >();
228+ ```
229+
230+ For details on obtaining an instance of ` UnconfiguredProject ` or ` ConfiguredProject ` ,
231+ see [ Finding CPS in a VS project] ( ..\automation\finding_CPS_in_a_VS_project.md )
232+
199233## MEF and C# Nullable Reference Types
200234
201235When using the C# nullable feature in your code, you may need to tweak the above
0 commit comments