Tuesday, August 7, 2018

Microsoft.WebApplication.targets not found with MSBuild for Build Tools for Visual Studio 2017

Was working with Jenkins integration and was using MSBuild for Build Tools for Visual Studio 2017(which by default gets installed into C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0). While building a web application developed with framework 4.7.1 (in my case). Class library was getting build successfully but was getting following error for web application.
error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Also, tried to find "WebApplications\Microsoft.WebApplication.targets" in the fallback search path(s) for $(VSToolsPath) - "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.
Resolution-

In my case I have downloaded Build Tools for Visual Studio 2017 from https://visualstudio.microsoft.com/downloads/#build-tools-for-visual-studio-2017(search inside All downloads). Downloaded exe will have name like vs_buildtools__1674480101.1516182736.exe.
But while installing build tool I have not selected the following option(Web development build tools)-



Steps:
  • Download build tools from above and rename it to vs_buildtools.exe
  • Open command prompt and CD to the same folder where vs_buildtools.exe is
  • Run the following command- vs_buildtools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools
This command will mark Web development build tools preselected in the installation window. Complete the installation and you should get the issue resolved.

No comments:

Post a Comment