10
votes

We recently installed a new development environment (Windows 10) from scratch with Visual Studio 2017 but we cannot manage to make msbuild compile a Microsoft Office Addin for Word (vsto). Within the Visual Studio installer we made sure to include the required components for Office Development.

It throws the following error (german translated to english)

error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" was not found. Also, tried to find "OfficeTools\Microsoft.VisualStudio.Tools.Office.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" [...]

However, the project builds fine within Visual Studio.

On the old system, everything works fine, and i cannot remember having to configure anything at all.

4
are you running the msbuild on your machine or in the tfs server?Zinov
I'm working through the same problem right now. It looks like the Office Tools installation doesn't really add any of it's assemblies to the GACs3raph86
@Zinov "my machine". Lets call it a custom compile server. Not directly invovled with TFS. All it does is start msbuild on a regular basis for a few csproj files.CSharpie
@CSharpie do you have the Visual Studio installed on that machine? or the Microsoft Build Tools 2015? microsoft.com/en-us/download/details.aspx?id=48159Zinov
@Zinov Visual StudioCSharpie

4 Answers

6
votes

You need to install Office build tools when installing Build Tools for Visual Studio 2017

enter image description here

2
votes

In my case, I managed to get around the issue by copying the folder

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio

from the development environment (the old environment in your case) to

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio

on the build environment (the new environment in your case). I would have thought that one should be able to simply get the relevant targets from the Build Tools for Visual Studio 2017 but that appears not to be the case.

1
votes

After reinstalling everything it works now. I guess back then when we set up this machine, the build tools setup was bugged or something.

Now we could install everything we needed for the buildtools using the visual studio installer and it works like a charm.

0
votes

Okay, so I've worked through this one now. The problem was caused by me using Windows\Microsoft.NET\Framework64\v4...\Msbuild.exe.

It looks as though running msbuild from this location results in it not being able to implicitly locate many of the assemblies and build utilities required to build a VSTO project.

I resolved the problem by switching to using C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe