Question

I need some assistance with Microsoft Office Templates in visual studio in general.

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. 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.

I need to manually change it here in csproj. please look at DebugInfoExeName where I changed it from 14.0 to 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. enter image description here

Was it helpful?

Solution

First option, maintain two different .proj and .sln files (one for version 12 and one for 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).

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.

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).

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.

OTHER TIPS

Check out this question to determine which version(s) of office are installed

How to detect installed version of MS-Office?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top