0
votes

I am trying run nuget restore mySolution.sln in a docker container.

For the most part it seems to work just fine. The packages seem to restore fine, but before they do, it shows this error:

C:\src\myProject\mySolution.csproj(317,11): 
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.

From what I read, this means I need the nuget package MSBuild.Microsoft.VisualStudio.Web.targets. I did a nuget install of that, but the error does not go away. (It just drops it where ever I run it. I tried putting it with my solution and in the packages folder. Neither had any effect.)

How can I fix this error using command line tools? (No GUI because this is a docker container).

1
I don't think it's a package that you are missing. You are missing the SDK/targets that are required to build that web project. You are missing the web workload.imps

1 Answers

2
votes

I assume what you're trying to build is a web-application, but you haven't installed corresponding workloads in your build tools package.And that's the cause of this issue. (Agree with imps)

Open the Visual Studio Installer in Start menu and you can modify the workloads of your msbuild package:

enter image description here

I only use the msbuild build tools package to build C++ desktop projects in server, so I only install the Visual C++ build tools workload. For you, you have to install the build tools for Web applications so that you can get the necessary files to build web-applications.

Update:

error: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. 

After I install the Web development build tools, I now get the newly created WebApplications folder in path C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0.