stack247
stack247

Reputation: 5747

The imported project Microsoft.WebApplications.targets was not found

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.

Upvotes: 66

Views: 50184

Answers (13)

Mr. E
Mr. E

Reputation: 515

Simply set the env var "MSBuildSDKsPath"

MSBuildSDKsPath "C:\Program Files\dotnet\sdk\8.0.101\Sdks"

Upvotes: 0

Ben Curthoys
Ben Curthoys

Reputation: 859

If you have installed the Visual Studio Build Tools 2022, you might need to modify the installation to add Web development build tools

enter image description here

Upvotes: 1

Fakhar Ahmad Rasul
Fakhar Ahmad Rasul

Reputation: 1691

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.

Upvotes: 0

Chuenkei Sit
Chuenkei Sit

Reputation: 51

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)

Upvotes: 1

0xVox
0xVox

Reputation: 116

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")```

Upvotes: 0

HankCa
HankCa

Reputation: 9629

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)' != ''" />

Why do this with Microsoft.WebApplication.targets

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 a packages.config file that listed MSBuild.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.

Upvotes: 6

Alex R.
Alex R.

Reputation: 684

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

Upvotes: 1

TPoschel
TPoschel

Reputation: 3872

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.

Upvotes: 7

Tim Murphy
Tim Murphy

Reputation: 4932

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.

Upvotes: 3

groksrc
groksrc

Reputation: 3025

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"

Upvotes: 1

Kirk Woll
Kirk Woll

Reputation: 77556

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.

Upvotes: 1

Manoj
Manoj

Reputation: 437

<!--<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.

Upvotes: 27

Jim Lamb
Jim Lamb

Reputation: 25775

You need to either...

  1. Install Visual Studio on your build machine, or
  2. Manually copy the contents of the MSBuild\Visual Studio\v10.0\WebApplications folder to the same location on your build machine.

Upvotes: 62

Related Questions