11

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.

CSharpie
  • 9,195
  • 4
  • 44
  • 71
  • are you running the msbuild on your machine or in the tfs server? – Zinov Mar 28 '17 at 15:14
  • 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 GAC – s3raph86 Mar 28 '17 at 23:20
  • @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 Apr 03 '17 at 16:00
  • @CSharpie do you have the Visual Studio installed on that machine? or the Microsoft Build Tools 2015? https://www.microsoft.com/en-us/download/details.aspx?id=48159 – Zinov Apr 04 '17 at 13:20
  • @Zinov Visual Studio – CSharpie Apr 04 '17 at 15:03
  • Try to install the Microsoft Build Tools 2015 and run it again, take a look on the difference between the msbuild and the devenv here http://stackoverflow.com/questions/9604511/msbuild-vs-devenv-for-command-line-builds – Zinov Apr 04 '17 at 17:13
  • Have you had any luck in resolving this issue? – Professor of programming Jun 22 '17 at 15:10
  • @Bonner웃 nope, sadly not. We are currently using visual studio to build theese projects on that machine. – CSharpie Jun 22 '17 at 17:43
  • I found that the vsto installation was unsuccessful, so I uninstalled Visual Studio 2017 and logged in using the machine Administrator account and reinstalled Visual Studio with the components for Office Development selected and this resolved the issue for us. – Professor of programming Jun 22 '17 at 22:28

4 Answers4

8

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

enter image description here

Troopers
  • 5,127
  • 1
  • 37
  • 64
2

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.

fuglede
  • 17,388
  • 2
  • 54
  • 99
1

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.

CSharpie
  • 9,195
  • 4
  • 44
  • 71
0

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

s3raph86
  • 556
  • 4
  • 17