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.
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.
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.
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:
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.
You need to install Office build tools when installing Build Tools for Visual Studio 2017
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With