简体   繁体   English

查找在Visual Studio运行时在系统上安装的Microsoft Office版本

[英]Finding version of Microsoft Office installed on system at runtime in Visual Studio

I need some assistance with Microsoft Office Templates in visual studio in general. 通常,我在Visual Studio中需要有关Microsoft Office模板的帮助。

My problem is that I am working on Visual Studio 2012 which is compatible or say contains templates for Microsoft Office 2010. I want to know is there any way to find out at runtime which version of MS office is installed on system and build it accordingly. 我的问题是我正在使用兼容的Visual Studio 2012,或者说它包含Microsoft Office 2010的模板。我想知道有什么方法可以在运行时找出系统上安装了哪个版本的MS Office并进行相应的构建。 That means I want to get rid of changing in .csproj file version 14.0 to 12.0 manually in case I am developing MS office 2007 solutions in Visual Studio 2012. On the similar lines, it would help me if I have MS office 2012 installed on my machine and I can use still use visual studio say 2012 or 2013 in order to work with it. 这意味着我想摆脱手动将.csproj文件版本14.0更改为12.0的情况,以防我在Visual Studio 2012中开发MS Office 2007解决方案。类似地,如果我在自己的计算机上安装了MS Office 2012,这将对我有帮助机器,我仍然可以使用Visual Studio 2012或2013来与它配合使用。

I need to manually change it here in csproj. 我需要在csproj中手动更改它。 please look at DebugInfoExeName where I changed it from 14.0 to 12.0. 请查看DebugInfoExeName,我将其从14.0更改为12.0。

 <ProjectExtensions>
    <VisualStudio>
      <FlavorProperties GUID="{BAA0C2D2-18E2-41B9-852F-F413020CAA33}">
        <ProjectProperties HostName="Excel" HostPackage="{20A848B8-E01F-4801-962E-25DB0FF57389}" OfficeVersion="14.0" VstxVersion="4.0" ApplicationType="Excel" Language="cs" TemplatesPath="" DebugInfoExeName="#Software\Microsoft\Office\***12.0***\Excel\InstallRoot\Path#excel.exe" AddItemTemplatesGuid="{51063C3A-E220-4D12-8922-BDA915ACD783}" />
        <Host Name="Excel" GeneratedCodeNamespace="SiraExcelAddIn" IconIndex="0">
          <HostItem Name="ThisAddIn" Code="ThisAddIn.cs" CanonicalName="AddIn" CanActivate="false" IconIndex="1" Blueprint="ThisAddIn.Designer.xml" GeneratedCode="ThisAddIn.Designer.cs" />
        </Host>
      </FlavorProperties>
    </VisualStudio>

I want to get rid of this window however not manually. 我想摆脱这个窗口,但不是手动的。 在此处输入图片说明

Check out this question to determine which version(s) of office are installed 签出此问题,以确定安装了哪个Office版本。

How to detect installed version of MS-Office? 如何检测已安装的MS-Office版本?

First option, maintain two different .proj and .sln files (one for version 12 and one for 14). 第一种选择是,维护两个不同的.proj和.sln文件(一个用于版本12,一个用于14)。

Second and crazy kludge approach is as follows. 第二个疯狂的方法如下。

Add a dependant console application project to the solution, then add a post-build event to that project and make it run "always", in that post-build event execute the console application. 将一个从属的控制台应用程序项目添加到解决方案,然后向该项目添加一个构建后事件,并使其始终运行,在该构建后事件中执行控制台应用程序。

Within the console application include code to check if the highest version of Office that is installed and update the project .proj files as needed (only update if there is a change, don't update if no change). 在控制台应用程序中,包含用于检查是否安装了最高版本的Office的代码,并根据需要更新项目.proj文件(仅在发生更改时更新,在没有更改时不更新)。

First build will cause the project file to be changed and visual studio will prompt as it requires reloading, the second build will build perfectly fine. 第一个版本将导致项目文件被更改,Visual Studio将在需要重新加载时提示您,第二个版本将完美构建。

This gets rid of the manual process but it still has to change the project file (which might cause havoc with your svn/git repo if you just commit all changes all the time). 这摆脱了手动过程,但仍然必须更改项目文件(如果您始终一直进行所有更改,则可能会严重破坏svn / git存储库)。

Your other option is to try installing the office 14 primary interop assemblies and see if that lets you build without having version 14 installed. 您的另一个选择是尝试安装office 14 primary interop assemblies ,看看是否可以在不安装版本14的情况下进行构建。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 运行时的 Microsoft Visual Studio 数组 - Microsoft Visual Studio Arrays at Runtime Visual Studio无法在运行时查找.dll - Visual Studio Not Finding .dll At Runtime 无法调试Word加载项项目,未安装所需的Microsoft Office版本 - Unable to debug Word addin project, required version of Microsoft Office is not Installed 无法使用Visual Studio 2017加载文件或程序集&#39;Microsoft.CodeAnalysis.LiveUnitTesting.Runtime,版本= 1.7.0.0&#39; - Could not load file or assembly 'Microsoft.CodeAnalysis.LiveUnitTesting.Runtime, version= 1.7.0.0' with visual studio 2017 如何使用已安装的Office版本在WinForms应用程序中查看Microsoft Office文档? - How can I view Microsoft Office documents in a WinForms application using the installed version of Office? Microsoft Visual Studio版本未在控制面板中更新 - Microsoft Visual Studio version not updating in Control Panel 找不到Microsoft.Office.Interop Visual Studio - Cannot find Microsoft.Office.Interop Visual Studio 如何在不使用Visual Studio的情况下开发Microsoft Office AddIn - How to develop a Microsoft Office AddIn without Visual Studio 适用于 Office 运行时的 Visual Studio 2010 工具 - 生命周期结束 - Visual Studio 2010 Tools for office runtime - end of the lifecycle 我是否需要为我的powerpoint加载项安装用于Office运行时的Microsoft Visual Studio 2010工具(x86和x64)? - Do I need to install Microsoft Visual Studio 2010 Tools for Office Runtime (x86 and x64) for my powerpoint Add-in?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM