the story

I have a running build built on an agent that is somehow quite aged, so i wanted to install a fresh one on a “windows server core” and script that with a bit of powershell. After i’ve sone some setup an old and legacy webapp complains:

the error

error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\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\Enterprise\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.

so i looked and Microsoft.WebApplication.targets was indeed missing, although i had installed the “buildtools” workload Microsoft.VisualStudio.Workload.WebBuildTools.

just for reference (and me searching the internet finding my own blog): another component id i put here for reference is: Microsoft.VisualStudio.Component.Wcf.Tooling when the file Microsoft.VisualStudio.ServiceModel.targets is missing :)

some research

ok, well ddg and google werent of much help (this is why i’m finally writing this). Everybody was just suggesting to install VS using the installer, but they did not exactly point out what workload / workload ID i had to use. so the question “How to install Microsoft.WebApplication.targets using a quiet, unattended Visual Studio setup?” arised.

i decided to check myself what workload it could be and tried some workloads i found on ms docs for build tools component ids, this is well documented, it couldn’t be that hard, right?

problem with all of them was: everything with “web” in it wouldnt install the targets file…

so i finally figured out i had to use a intaller of a “higher” edition of vs, like professional or enterprise, so i tried using the vs_enterprise installer and the component ids of vs enterprise

the fix

finally this component id resulted in success: Microsoft.VisualStudio.Component.Web.

for an automated build agent setup use this command line: vs_enterprise.exe --quiet --add "Microsoft.VisualStudio.Component.Web"

it does not work, what now?

if this does not work and the installer exists shortly after you started it you may have to update VS itself first (this is advisable generally). You can achieve that using this command:

C:\temp\buildPrerequisites\vs_enterprise.exe update --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise" --quiet --wait --norestart

after that (you can monitor if it finished in the task manager: see if all processes exited) restart the computer and try to install your missing component again.