3

我試圖讓我的擴展程序在新版本推送到Visual Studio庫時自動更新自身。關於如何實現這一目標,有幾條指南,但是它們已經有幾年了,可能不適用。自動更新Visual Studio擴展

對於初學者來說,我想查詢IVsExtensionRepository如下:

var _extensionRepository = (IVsExtensionRepository)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsExtensionRepository)); 

var query = _extensionRepository.CreateQuery<VSGalleryEntry>(false, true) 
       .OrderByDescending(n => n.Ranking) 
       .Skip(0) 
       .Take(25) as IVsExtensionRepositoryQuery<VSGalleryEntry>; 

query.ExecuteCompleted += Query_ExecuteCompleted; 
query.ExecuteAsync(); 

Query_ExecuteCompleted我收到來自服務器異常:「遠程服務器返回錯誤:(400)錯誤的請求「。提供

棧跟蹤:

服務器堆棧跟蹤: 在System.Runtime.AsyncResult.End [TAsyncResult](IAsyncResult的結果) 在System.ServiceModel.Channels.ServiceChannel.SendAsyncResult.End(SendAsyncResult結果) 在System.ServiceModel.Channels.ServiceChannel.EndCall(字符串動作,對象[]奏,IAsyncResult的結果) 在System.ServiceModel.Channels.ServiceChannelProxy.InvokeEndService(IMethodCallMessage包括methodCall,ProxyOperationRuntime操作) 在System.ServiceModel.Channels。 ServiceChannelProxy.Invoke(IMessage消息)

該服務的託管在:https://visualstudiogallery.msdn.microsoft.com/services/dev12/extension.svc

有誰知道我怎麼能創建一個Visual Studio擴展,從Visual Studio庫自動更新自己?通過IVsExtensionRepository或手動?

+0

嗯,你可能必須建立一個數據包跟蹤,看看發送的查詢是無效的。 – JaredPar 2014-09-23 22:02:49

+0

是的,我想我會試試看。它遍佈SSL,但我認爲這仍然是可能的,這需要我花一些時間來學習如何。 – JoshVarty 2014-09-23 22:07:15

回答

2

編輯:現在在Visual Studio 2015擴展程序自動下載。

所以我完全放棄了查詢IVsExtensionRepository。我不確定爲什麼,但是它構建的查詢必然存在內部問題。我使用ErikEJ的建議項目查詢了相同的服務,並且它運行良好。

但是,我不想像SQLCeToolbox所做的那樣從WSDL構建服務。相反,我使用IVsExtensionRepository,但避免了CreateQuery()方法。

附加是我的方法來更新我的VSPackage。您需要用您的軟件包信息替換任何GUID或軟件包特定名稱。

注意有一個疑難雜症」下面的代碼:

注意CodeConnectRepositoryEntry只實現DownloadUrl。更新VSPackage時,這是所有人必須擔心的,因爲它允許我們下載新的軟件包。該URL可以在VGackage的VSGallery頁面上找到。

然而:您必須修剪網址如下:

http://visualstudiogallery.msdn.microsoft.com/c0c2ad47-957c-4e07-89fc-20996595b6dd/file/140793/4/CodeConnectAlpha.vsix

到:

http://visualstudiogallery.msdn.microsoft.com/c0c2ad47-957c-4e07-89fc-20996595b6dd/file/140793/

上面,/ 4 /代表第四上傳。通過完全刪除它,Visual Studio Gallery將下載最新版本。

internal class CodeConnectUpdater 
{ 
    IVsExtensionManager _extensionManager; 

    IVsExtensionRepository _extensionRepository; 

    //We need only supply the download URL. 
    //This can be retrieved from the "Download" button on your extension's page. 
    private class CodeConnectRepositoryEntry : IRepositoryEntry 
    { 
     public string DownloadUpdateUrl 
     { 
      get; set; 
     } 

     public string DownloadUrl 
     { 
      get 
      { 
       //NOTE: YOU MUST TRIM THE DOWNLOAD URL 
       //TO NOT CONTAIN A VERSION. THIS FORCES 
       //THE GALLERY TO DOWNLOAD THE LATEST VERSION 
       return "http://visualstudiogallery.msdn.microsoft.com/c0c2ad47-957c-4e07-89fc-20996595b6dd/file/140793/"; 
      } 
      set 
      { 
       throw new NotImplementedException("Don't overwrite this."); 
      } 
     } 

     public string VsixReferences 
     { 
      get; set; 
     } 
    } 

    //I have been calling this from the VSPackage's Initilize, passing in the component model 
    public bool CheckForUpdates(IComponentModel componentModel) 
    { 
     _extensionRepository = (IVsExtensionRepository)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsExtensionRepository)); 
     _extensionManager = (IVsExtensionManager)Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(SVsExtensionManager)); 
     //Find the extension you're after. 
     var extension = _extensionManager.GetInstalledExtensions().Where(n => n.Header.Name == "Code Connect Alpha").SingleOrDefault(); 

     return CheckAndInstallNewVersion(extension); 
    } 

    private bool CheckAndInstallNewVersion(IInstalledExtension myExtension) 
    { 
     var needsRestart = false; 
     var entry = new CodeConnectRepositoryEntry(); 
     var newVersion = FetchIfUpdated(myExtension, entry); 
     if (newVersion != null) 
     { 
      Install(myExtension, newVersion); 
      needsRestart = true; 
     } 

     return needsRestart; 
    } 

    //Checks the version of the extension on the VS Gallery and downloads it if necessary. 
    private IInstallableExtension FetchIfUpdated(IInstalledExtension extension, CodeConnectRepositoryEntry entry) 
    { 
     var version = extension.Header.Version; 
     var strNewVersion = _extensionRepository.GetCurrentExtensionVersions("ExtensionManagerQuery", new List<string>() { "6767f237-b6e4-4d95-9982-c9e898f72502" }, 1033).Single(); 
     var newVersion = Version.Parse(strNewVersion); 

     if (newVersion > version) 
     { 
      var newestVersion = _extensionRepository.Download(entry); 
      return newestVersion; 
     } 

     return null; 
    } 

    private RestartReason Install(IInstalledExtension currentExtension, IInstallableExtension updatedExtension) 
    { 
     //Uninstall old extension 
     _extensionManager.Disable(currentExtension); 
     _extensionManager.Uninstall(currentExtension); 

     //Install new version 
     var restartReason = _extensionManager.Install(updatedExtension, false); 

     //Enable the newly installed version of the extension 
     var newlyInstalledVersion = _extensionManager.GetInstalledExtension(updatedExtension.Header.Identifier); 
     if (newlyInstalledVersion != null) 
     { 
      _extensionManager.Enable(newlyInstalledVersion); 
     } 

     return restartReason; 
    } 
} 
1

我有一些代碼來訪問服務,並從這裏產生一個RSS源:sqlcetoolbox.codeplex.com/SourceControl/latest - 在NuGetDownloadfedd.zip文件(與Nuget無關!) - 還包括版本號:

foundItem.Project.Metadata.TryGetValue("VsixVersion", out version); 

事實上,我已經託管一個RSS提要服務,讓我知道如果你想使用它。

+0

你知道FeedHandler.cs中LCID爲1033的意義嗎? (如果不是很好,我只是不知道它代表什麼) – JoshVarty 2014-09-29 18:59:34

+1

你假裝你從英文版的Visual Studio調用Web服務... – ErikEJ 2014-09-29 19:50:09