问题
I am building a custom code refactoring provider as an extension to Visual Studio 2017 and I want it to access the DTE
service. To get it I use the ImportingConstructorAttribute
and declare the service a parameter:
[ExportCodeRefactoringProvider( LanguageNames.CSharp, Name = nameof( MyCodeRefactoringProvider ) )]
[Shared]
internal class MyCodeRefactoringProvider : CodeRefactoringProvider {
private readonly DTE m_dte;
[ImportingConstructor]
public MyCodeRefactoringProvider( DTE dte ) {
m_dte = dte;
}
public sealed override async Task ComputeRefactoringsAsync( CodeRefactoringContext context ) {
//...
}
}
However, when I run the provider in the Visual Studio experimental instance, the provider is not instantiated.
The refactoring provider works fine if I don't try to import the service provider. The same issue occurs if I use the ImportAttribute
on a property instead of the ImportingConstructorAttribute
.
There was also nothing in the ActivityLog.xml of Visual Studio.
How can I import DTE
through MEF?
来源:https://stackoverflow.com/questions/53860813/exception-during-initialization-of-a-coderefactoringprovider-when-trying-to-impo