The imported project Microsoft.WebApplications.targets was not found
Visual StudioTfsVisual Studio Problem Overview
I have this error when configuring continuous integration in TFS server, but found the answer already. Maybe this will help others:
The imported project "C:\Program Files (x86)\
MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\
Microsoft.WebApplications.targets" was not found.
Visual Studio Solutions
Solution 1 - Visual Studio
You need to either...
- Install Visual Studio on your build machine, or
- Manually copy the contents of the
MSBuild\Visual Studio\v10.0\WebApplications folder to the same location on your build machine.
Solution 2 - Visual Studio
<!--<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v9.0\WebApplications\Microsoft.WebApplication.targets" />-->
Comment above line in .CSproj. Seems like bug with Microsoft which do not remove or comment while updating project from visual studio 2008 to 2010.
Solution 3 - Visual Studio
I saw the same error when setting up continuous integration with Jenkins. I was able to add a command-line argument to MSBUILD: /p:VisualStudioVersion=12.0
because I had Visual Studio 2012 installed on my build server.
Solution 4 - Visual Studio
I experienced something similar.
I had written this in our Autobuild.targets
file run as part of a build. It defines MSWebApplicationTargets
:
<MSWebApplicationTargets>$(SolutionDirectory)\packages\MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3</MSWebApplicationTargets>
Then in a .csproj
file that is part of the project and used in the build it had:
<Import
Project="$(MSWebApplicationTargets)/tools/VSToolsPath/WebApplications/Microsoft.WebApplication.targets" />
Now our problem was that when we opened the project in Visual Studio it said that c:/tools/VSToolsPath/WebApplications/Microsoft.WebApplication.targets
doesn't exist (because VS considered MSWebApplicationTargets
to be undefined and so seemed to default it to c:\
). You don't provide enough information though perhaps that is what caused your problem also.
All I had to do to solve this was add a condition:
<Import
Project="$(MSWebApplicationTargets)/tools/VSToolsPath/WebApplications/Microsoft.WebApplication.targets"
Condition="'$(MSWebApplicationTargets)' != ''" />
Microsoft.WebApplication.targets
Why do this with As part of some futher discussion, I did this with Microsoft.WebApplication.targets
so we didn't have to rely on Visual Studio being installed on the build servers. I added it as a dependency:
- In Visual Studio right-click on the project and go to
manage nuget packages
. This created apackages.config
file that listedMSBuild.Microsoft.VisualStudio.Web.targets
as a dependency. - I then added
nuget.exe restore
to the start of the build script so that the dependencies are downloaded.
Solution 5 - Visual Studio
Download & install Microsoft Visual Studio 2013 Shell (Isolated) Redistributable Package. Or use the direct link to vs_isoshell.exe. I intend to make an NuGet package for this at a later date.
The advantage I see to this approach is it removes any doubt on copyright issues.
Solution 6 - Visual Studio
And if you already have Visual Studio installed? Perhaps you have Visual Studio 2012 installed (and 10.0 indicates VS 2010)? If that's the case, you can just search your .csproj file for "10.0" and replace that with "11.0" and you'll then be able to open the project just fine.
Solution 7 - Visual Studio
I had this problem as well except that this files were already there. After a lot of troubleshooting the answer turned out to be frustratingly simple: restart the build agent service. In my case it was: "Visual Studio Team Foundation Build Service Host 2013"
Solution 8 - Visual Studio
If you don't deploy from the build server, then just turn off the Microsoft.WebApplication.targets
on the build server. See my answer here: https://stackoverflow.com/a/35781566/4955344
Solution 9 - Visual Studio
I also met this error on VS2017; then i comment out below two items:
<!--<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /><Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />-->
reopen the solution , the project can be load successfully again. (i don't know how this happen, because this project can be load normally before, maybe i had added some new feature through 'vs-installer.exe' recently)
Solution 10 - Visual Studio
Here's some PowerShell that fixed this issue for me by adding in the missing reference in MSBuild.exe.config on my Build server. Adjust paths to your VS version / targets path.
[xml]$msbuild_config = Get-Content -Path "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe.config"
$webApplicationTarget = $msbuild_config.configuration.msbuildToolsets.toolset.property[0].Clone()
$webApplicationTarget.name = "MSWebApplicationTargets"
$webApplicationTarget.value = "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications"
$msbuild_config.configuration.msbuildToolsets.toolset.AppendChild($webApplicationTarget)
$msbuild_config.save("C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe.config")```
Solution 11 - Visual Studio
Here is what I did to solve this problem in vs19. I navigated to this path:-
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
and noticed that \vxx.0
(the particular directory vs was complaining about was not present). In my case vs was looking for \v16.0
which was not there although \v15.0
, \v14.0
and \v12.0
were there. So I manually created a v16.0
folder and copied WebApplications\Microsoft.WebApplications.targets
from v14.0
to the v16.0
folder and the issue was fixed, however I am not sure if this was the best way to fix this problem, it seemed kinda hacky. And I was unable to change this path in the .csproj
file because the path was probably stored in a variable like $(MSBuildBinPath)
and it was not hard coded there.