How can I use EnvDTE within a .NET Standard project

女生的网名这么多〃 提交于 2019-12-02 00:16:27

问题


I'm porting a .net 4.7 project to .net standard, which uses T4 to generate some code. I iterate over the classes, properties and methods. This use to work perfectly, but now the return types of DTE are of type 'System.__ComObject' and I cannot cast them.

Error: Unable to cast COM object of type 'System.__ComObject' to interface type 'EnvDTE.CodeClass'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B1F42514-91CD-4D3A-8B25-A317D8032B24}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

Any ideas how to fix this?

Example:

public static bool CheckBase(CodeClass codeClass, string baseName)
{
    var bases = codeClass.Bases;
    if (bases != null)
    {
        foreach (CodeClass baseClass in bases)
        {
            if(baseClass.Name == baseName) return true;
        }
    }
    return false;
}

来源:https://stackoverflow.com/questions/46573802/how-can-i-use-envdte-within-a-net-standard-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!