Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msbuild fails to compile vsto project

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.

like image 579
CSharpie Avatar asked Mar 08 '17 16:03

CSharpie


People also ask

Why does MSBuild build the Helloworld csproj file?

Type msbuild. Although a project file is not specified, MSBuild builds the helloworld.csproj file because there is only one project file in the current folder. This causes the MSBuildSample application to be created in the \Bin\ folder. To verify that the \Bin\ folder contains the MSBuildSample application, type dir Bin.

Where is MSBuild Exe located in Visual Studio 2013?

Starting in Visual Studio 2013, you can find MSBuild.exe in the MSBuild folder (%ProgramFiles%MSBuild on a 32-bit operating system, or %ProgramFiles(x86)%MSBuild on a 64-bit operating system). At the command prompt, type set PATH=%PATH%;%ProgramFiles%MSBuild or set PATH=%PATH%;%ProgramFiles(x86)%MSBuild.

Can I create a basic project file incrementally with MSBuild?

This tutorial works only with .NET Framework 4.x and earlier, not .NET Core or .NET 5 and later. For information about creating a project file for a C++ project, see MSBuild (C++). This walkthrough shows how to create a basic project file incrementally, by using only a text editor. The walkthrough follows these steps:

Why does MSBuild run the default build target?

Because you did not use the -t switch to explicitly set the target, MSBuild runs the default Build target. The -p switch overrides the AssemblyName property and gives it the new value, Greetings. This causes a new application, Greetings.exe, to be created in the \Bin\ folder.


2 Answers

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

enter image description here

like image 99
Troopers Avatar answered Sep 28 '22 13:09

Troopers


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.

like image 26
fuglede Avatar answered Sep 28 '22 15:09

fuglede