如何通过命令行检查Visual Studio更新?

10
为了简化我的虚拟环境设置,我正在使用Chocolatey自动化我的VM。
因为我可以运行cinst命令来安装Visual Studio。
c:\> cinst VisualStudio2012Professional

安装完成后,我想知道是否有命令行开关可以在Visual Studio中检查更新(并随后“安装”更新)?

类似于以下内容...

"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe" /InstallUpdates

这也应该扩展到与VS一起安装的任何扩展。

3个回答

12

有一种方法可以检查,但它并不直接。Visual Studio更新是通过一个ATOM源发布的,该源目前托管在此处:

http://go.microsoft.com/fwlink/?LinkID=251032

该URL可以在以下位置找到:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Platform\Shell\Microsoft.VisualStudio.ExtensionManager.Implementation.pkgdef

在[$RootKey$\ExtensionManager\Repositories{52943709-1abb-4abe-b413-41e8bb6d0462}]键下。

上述URL不应更改任何版本的Visual Studio,但这并不是保证。如果你检查http://go.microsoft.com/fwlink/?LinkID=290886的响应,你将获得以下响应:

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text"></title>
  <id>uuid:99B94631-1B1A-45A0-9C34-54F75988DD54;id=1</id>
  <updated>2013-02-12T20:00:00-07:00</updated>  
  <entry>
    <id>8EAF6C8E-1283-4EEE-AB6E-F0F087BFCBFF</id>
    <title type="text">Visual Studio 2012 Update 3</title>
    <summary type="text">Includes security updates, other critical updates, hotfixes, and feature packs that have been issued since the product was released.</summary>
    <published>2012-12-01T21:00:00-07:00</published>
    <updated>2012-12-01T21:00:00-07:00</updated>
    <author>
      <name>Microsoft Corp.</name>
    </author>
    <link rel="alternate" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=257044&amp;clcid=0x409"/>
    <link rel="releasenotes" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=257045&amp;clcid=0x409"/>
    <link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=302339"/>
    <!-- icon should be 32 x 32 pixels -->
    <link rel="icon" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_32x.png"/>
    <!-- preview image should be 200 x 200 pixels -->
    <link rel="previewimage" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_200x.png"/>
    <Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/developer/vsx-syndication-schema/2010">
      <Id>8EAF6C8E-1283-4EEE-AB6E-F0F087BFCBFD</Id>
      <Version>11.0.60610.01</Version>
      <References />
    </Vsix>
  </entry>
  <entry>
    <id>28743233-1A36-4e67-8747-F072F8C76D1F</id>
    <title type="text">Visual Studio Extensions for Windows Library for JavaScript</title>
    <summary type="text">This release updates the development resources for the controls, CSS styles, and helper functions that are included in the Windows Library for JavaScript.</summary>
    <published>2013-08-08T20:00:00-07:00</published>
    <updated>2013-08-08T20:00:00-07:00</updated>
    <author>
      <name>Microsoft Corp.</name>
    </author>
    <link rel="alternate" type="text/html" href="http://go.microsoft.com/fwlink/?LinkId=260891&amp;clcid=0x409"/>
    <link rel="releasenotes" type="text/html" href="http://go.microsoft.com/fwlink/?LinkID=260892&amp;clcid=0x409"/>
    <link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=260893"/>
    <link rel="icon" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_32x.png"/>
    <link rel="previewimage" type="text" href="http://visualstudiogallery.msdn.microsoft.com/Content/VisualStudio/VSDownload_200x.png"/>
    <Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.microsoft.com/developer/vsx-syndication-schema/2010">
      <Id>Microsoft.WinJS</Id>
      <Version>1.0.9200.20789</Version>
      <References />
    </Vsix>
  </entry>
</feed>
请注意,此源中有两个条目,您所感兴趣的是标题以“Visual Studio 2012 Update”开头的那个。
如果此文件中指定的版本(此处为11.0.60610.01)大于您计算机上的版本:
(Get-Item "${env:ProgramFiles(x86)}\Microsoft Visual Studio 11.0\common7\ide\devenv.exe").VersionInfo.ProductVersion

然后您需要下载并安装链接/@Update节点中的URL:

<link rel="update" type="text" href="http://go.microsoft.com/fwlink/?LinkID=302339"/>

该网址应重定向到包含更新的MSI文件。


这是一个不错但有些hacky的解决问题的方法。如果想要在devenv.exe命令行开关中包含所有内容,应该向谁/哪里发送功能请求?如果这是一个“永远不会发生”的情况,我可能会考虑构建一个EXE来实现这一点,并将其推送到#Chocolatey。 - Chase Florell
1
是的,可能不是你所期望的API :) 有一个uservoice网站可以提交vs功能请求,但我怀疑它不会排在很高的位置。我也在想,创建一个巧克力自动更新程序会很酷。虽然你可以找到巧克力包来更新,但对于包生产者和消费者来说都很麻烦。 - Matt Wrock

1
根据位于Devenv命令行开关 MSDN文档中的信息,目前没有办法调用命令行开关以检查/安装Visual Studio的更新。然而,Matt Wrock在他的回答中展示了一个不错的解决方法。

0

@Matt的回答已经过时了。对于VS2019,请按照以下方式进行:

  1. https://aka.ms/vs/16/release/channel下载文件(它将是一个名为'VisualStudio.16.Release.chman' 的普通JSON文件)
  2. 检查节点:info->productDisplayVersion(或buildVersion)-它们提供足够的信息。

我已经更新了标签以反映该问题是关于Visual Studio 2012提出的。 - Chase Florell

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接