Skip to main content

How to Build Visual Studio 2010 Office Development Projects with TFS Team Build 2010

Introduction

This whitepaper explains how to build and publish Office solutions by using Team Foundation Server (TFS) Team Build 2010 without installing Visual Studio. Developers can create and build projects for Microsoft Office 2007 and Microsoft Office 2010 by using Visual Studio 2010. Later, these projects can be checked into TFS for source control, and then built and published with TFS Team Build without Visual Studio installed on the build computer. The steps described in the whitepaper are not needed if Visual Studio 2010 is already installed on the build computer.

Prepare the Build System

You can use Team Build 2010 to build and publish Office projects created in Visual Studio 2010. To configure Team Build 2010, you must copy additional files and create registry keys that are required to build these projects. These files are always present on a machine with Visual Studio but are not present on a machine which has only the Team Build SKU installed.

Installing Pre-requisites:

.NET Framework

If you want to build projects targeting .NET Framework 3.5 and .NET Framework 4, make sure your Team Build System has both versions installed. You can download both versions of the .NET Framework from the .NET Framework Developer center: http://msdn.microsoft.com/en-us/netframework/default.aspx

Windows SDK for .NET Framework 4

Windows SDK is required to be installed for tools like GACUtil and SignTool. GACUtil will be used to install the Office development assemblies on the build system. SignTool is used to sign the deployment packages generated when you publish the Office project.
You can download the Windows SDK from the Windows Developer Center: http://msdn.microsoft.com/en-us/windows/bb980924.aspx

Visual Studio Tools for Office 2010 Runtime

The Visual Studio Tools for Office 2010 Runtime redistributable is required to build any Office development project developed in Visual Studio 2010.

You can download Visual Studio Tools for Office 2010 Runtime here: http://msdn.microsoft.com/en-us/library/bb608603(VS.100).aspx

Script for automating the Team Build System Configuration

Sample scripts are available to help automate the process of copying the appropriate DLLs and creating the registry keys described in the instructions below. To use the scripts, you will need a computer with Visual Studio 2010 Professional or higher installed on it.

You can find the scripts and information on how to use the scripts here: http://go.microsoft.com/fwlink/?LinkId=188066

Install Custom Build Tasks

Office projects define their own custom build tasks in addition to the ones available in MSBuild. The following assemblies for the build tasks must be installed to the GAC on the build system in order to build the projects.

  • Microsoft.VisualStudio.Tools.Office.BuildTasks.dll (v10.0)
  • Microsoft.VisualStudio.Tools.Applications.BuildTasks.dll (v10.0)

You can copy these DLLs from a system which has Visual Studio 2010 installed. The DLLscan be found under: “%Windows%\Microsoft.NET\assembly\GAC_MSIL”.
For information about using GACutil to install the DLLs to the GAC on the Team Build system, see: http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.80).aspx.

Copy Custom Build Targets

Office Projects define their own custom targets file: Microsoft.VisualStudio.Tools.Office.targets
The file can be found on a computer with Visual Studio 2010 at the following location:

%ProgramFiles(x86)%\MSBuild\Microsoft\VisualStudio\v10.0\OfficeTools\

Copy the file to the same location on the Team Build computer. Additionally if you want to use MSBuild 64-bit to build Office projects then you can copy the targets files to the 64-bit Program Files directory:

%ProgramFiles%\MSBuild\Microsoft\VisualStudio\v10.0\OfficeTools\”

Copy Visual Studio Tools for Office 2010 Runtime Reference Assemblies

Copy all DLLsfrom the following Reference Assemblies locations on a computer with Visual Studio 2010 to the Team Build system.

  • %Program Files%\Reference Assemblies\Microsoft\VSTA30\*.dll
  • %Program Files%\Reference Assemblies\Microsoft\VST040\*.dll

Copy Office 2007 and Office 2010 Primary Interop Assemblies

Copy the Office Primary Interop Assembly DLLs from the following location on a computer with Visual Studio 2010 to the Team Build system.

  • %ProgramFiles(x86)%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\*.dll

Copy Bootstrapper Packages (Optional)

If you want the Team Build system to generate a setup.exe capable of installing pre-requisites, you can copy all files from the following location on a computer with Visual Studio 2010 to the same location on the Team Build system.

  • %ProgramFiles%\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\VSTOR40\*

Configure Registry Keys

The following registry keys are required to build projects targeting .NET 3.5 on the team build system. Create these sub-keys under the following registry key:

For 32-bit machines:

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx]

For 64-bit machines:

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework\ v2.0.50727\AssemblyFoldersEx]

Subkey nameDefault value
VS10VSTOCommonPIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Common\\"
VS10VSTOOffice12PIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Office12\\"
VS10VSTOOffice14PIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Office14\\"
VSTA 3.0 v10.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTA30\\v10.0\\"
VSTA 3.0 v9.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTA30\\v9.0\\"
VSTO 4.0 v10.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTO40\\v10.0\\"
VSTO 4.0 v9.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTO40\\v9.0\\"

The following registry keys are required to build projects targeting .NET 3.5 on the team build system. Add Sub-keys Under the following registry key:

 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx]

Subkey nameDefault value
VS10VSTOCommonPIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Common\\"
VS10VSTOOffice12PIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Office12\\"
VS10VSTOOffice14PIA"C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Visual Studio Tools for Office\\PIA\\Office14\\"
VSTA 3.0 v10.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTA30\\v10.0\\"
VSTA 3.0 v9.0 Reference Assemblies"C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTA30\\v9.0\\"
VSTA 3.0 v8.0 Reference Assemblies@="C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTA30\\v8.0\\"
VSTO 4.0 Reference Assemblies@="C:\\Program Files\\Reference Assemblies\\Microsoft\\VSTO40\\v4.0.Framework\\"

 

Build an Office project

These are the minimum configuration options that must be set in order to build and publish an Office Project.

Project Settings
If you build or publish a project from Visual Studio 2010 at least once, these settings are automatically applied to the .vbproj or .csproj project file. However if you haven't published your project once before trying to build it on the team build computer, you must set the following project properties manually.

  1. On the Signing Page - Check the option to Sign ClickOnce Manifests
  2. Select an existing signing certificate or create a new test certificate
  3. On the publish page make sure publish folder location is set to some value - you could leave it at the default "publish\" if you want to

For more details on these properties, see http://go.microsoft.com/fwlink/?LinkId=183196

If the signing certificate selected in step 2) is password protected you may see an error:
“Cannot import the following key file: The key file may be password protected. To correct this, try to import the certificate again or import the certificate manually into the current user’s personal certificate store.”

MSBuild cannot automatically import the certificate into the certificate store on the Team Build computer. Instead, the certificate must be imported manually before you can use it for signing.
To import the certificate manually on the Team Build computer:

  • Login to the build machine with the credentials of the account used to build the solution
  • Double click on the certificate file (usually .pfx) this will launch a certificate import wizard
  • Run through the wizard specifying the password when prompted
  • Choose to import the certificate into the "Personal" certificate store
  • After the certificate is successfully imported you will be able to build the solution

After the project properties are configured, the solution can be checked into TFS source control and a new build definition can be created for that project.

Create new build definitions

  • In Team Explorer, right click the Builds node and click New Build Definition.
  • Type a Build Definition Name and Description.
  • Choose the trigger for the Build Definition. See http://go.microsoft.com/fwlink/?LinkId=183199 for more info on this property.
  • Select Appropriate Workspace. See http://go.microsoft.com/fwlink/?LinkId=183199 for more information.
  • On the Process tab, choose Projects to Build and include the Add the VSTO project file that will be built to the build definition.
  • You can specify additional configuration options as needed (see http://go.microsoft.com/fwlink/?LinkId=187921). If you want to get the publish output of the VSTO solution instead of the regular build output then you can specify this additional setting. The publish output is the payload that Visual Studio generates when using the publish wizard or publish properties page.

    Under the Advanced settings MSBuild Arguments add to arguments to the msbuild commandline./target:publish   /property:PublishDir="MyServer\Drops\VSTOSolution\Publish\\" 

  • /target:publish  Will call the publish target for the VSTO project to generate the publish package

    /property:PublishDir=

    "MyServer\Drops\

    VSTOSolution\Publish\\" 

    Specifies the directory where the publish output will be copied after it has been generated.

    Important Note: Make sure the directory path specified ends with a trailing "\\"


    The build definition is now configured. Whenever this build definition is triggered it will build the solution drop the build output to the drop location and the publish output of the solution to the PublishDir location if it is specified in the MSBuild arguments.

Appendix: Setting up Team Build for Office projects on TFS 2010

Steps 
1Install Team Build software
2Install Windows SDK to get GACUTIL and SignTool.
3Install Visual Studio Tools for Office 2010 Runtime
4

Install Custom Build Tasks and Targets

  • Microsoft.VisualStudio.Tools.Office.BuildTasks.dll (v10.0)
  • Microsoft.VisualStudio.Tools.Applications.BuildTasks.dll (v10.0)
  • Microsoft.VisualStudio.Tools.Office.targets
5

Copy Reference Assemblies

  • %Program Files%\Reference Assemblies\Microsoft\VSTA30\*.dll
  • %Program Files%\Reference Assemblies\Microsoft\VST040\*.dll
6

Copy Primary Interop Assemblies

  • %Program Files(x86)%\Microsoft Visual Studio 10.0\Visual Studio Tools for Office\PIA\*.dll
7

Copy Bootstrapper Packages

  • %Program Files%\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\VSTOR40\*
  • %Program Files%\Microsoft SDKs\Windows\v7.0A\Bootstrapper\Packages\Office2007PIARedist\*
8

Add registry keys under

  • [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v2.0.50727\AssemblyFoldersEx]
  • [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework v4.0.30319\AssemblyFoldersEx]
9

Specify the following MSBuild Arguments in the Build definition to publish the Office Project:

/target:publish   /property:PublishDir="MyServer\Drops\ Publish\\"