How to fix: MSBuild error MSB4226: The imported project was not found

 

When you get the MSBuild error:

“WebService.csproj” (Rebuild target) (1) ->

WebService.csproj(193,11): error MSB4226: The imported project

“C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.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\v16.0” . These search paths are defined in “C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\MSBuild.exe.Config”. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk in one of the search paths.

 

Make sure you have installed the same components during the Visual Studio setup as during de MSBuild tools setup:

 

 

Both should match, if you want MSBUILD to be able to build the same project files as Visual Studio.