如何在命令行工具中从EnvDTE自动化Nuget服务管理器?

时间:2016-05-24 10:15:42

标签: visual-studio-2013 envdte

我正在构建一个命令行工具,我可以使用Nuget Package Manager自动进行Nuget升级。

根据http://sammyageil.com/post/create-visual-studio-solution-and-add-project-using-codehttp://docs.nuget.org/create/invoking-nuget-services-from-inside-visual-studio的建议,到目前为止我得到了什么 this

static void Main(string[] args)
{
    var dte = (DTE) Activator.CreateInstance(Type.GetTypeFromProgID("VisualStudio.DTE.12.0", true), true);
    try
    {
        Console.WriteLine("Working with {0},{1} edition", dte.FullName, dte.Edition);
        dte.SuppressUI = false;
        dte.UserControl = false;

        IServiceProvider provider = ServiceProvider.CreateFromSetSite((Microsoft.VisualStudio.OLE.Interop.IServiceProvider)dte);
        var componentModel = (IComponentModel)provider.GetService(typeof(SComponentModel));
        IVsPackageInstallerServices installerServices = componentModel.GetService<IVsPackageInstallerServices>();
    }
    catch (Exception e)
    {
        Console.Error.Write(e);
    }
    dte.Quit();
}

我遇到的问题是,当我使用IComponentModel接口转换从provider.GetService接收的对象时,它会抛出以下异常,我不知道它的含义。

Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.VisualStudio.ComponentModelHost.IComponentModel'. 
This operation failed because the QueryInterface call on the COM component for the 
interface with IID '{605AF649-8844-3F09-9982-1258074BE833}' 
failed due to the following error: No such interface supported 
(Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

有人可以帮助我理解它所说的内容,也可能建议我走上正确的道路。

0 个答案:

没有答案