v11.0\WebApplications\Microsoft.WebApplication.targets was not found when file actually references v10

72,381

Solution 1

I ran into the same issue with Visual Studio 2013. It turns out that I was using the old version of MSBuild--the one that ships with the .NET Framework--from the command line. Microsoft is now releasing MSBuild as part of Visual Studio itself and also as a separate installer (http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx).

The solution was to use the new version of MSBuild.exe located in C:\Program Files (x86)\MSBuild\12.0\Bin. Once I did that, all the targets errors disappeared.

EDIT 1

As mentioned in the comments, each new version of MSBuild brings with it a new directory. For Visual Studio 2015, use C:\Program Files (x86)\MSBuild\14.0\Bin.

EDIT 2

As mentioned in the comments, for Visual Studio 2017, use C:\Program Files (x86)\Microsoft Visual Studio\2017\<Edition>\MSBuild\15.0\Bin\MSBuild.exe.

Solution 2

If you have a build server that does not have VS2012 installed, you can fix this by

a) installing the MSBuild.Microsoft.VisualStudio.Web.targets package to your solution, and

b) replacing this line in the .csproj file:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />

With this line pointing to the nuget package

<Import Project="..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath\WebApplications\Microsoft.WebApplication.targets" Condition="true" />

EDIT

As @joedragons points out the version in the updated line should match the nuget package version, i.e. replace targets.11.0.2.1 with targets.x.x.x.x for the current version.

Solution 3

A simple solution to this problem:

Go to the following path:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio

You will see the latest version V10.0, v11.0, v12.0 depending on your Visual Studio 2010, 2012 or 2013 install.

Copy WebApplications folder from either of latest version directory and paste to other.

Your issues should be resolved.

Solution 4

I've found that installing the free Visual Studio 2012 Shell (Isolated) installs the WebApplications v11 MSBuild files. Lighter than a full install of Visual Studio 2012 and no licensing concerns.

Solution 5

Wow. We just saw the same thing happen on our build machine. We use VS2010 and target .NET 4.0. Our project files explicitly import the v10.0 version of these targets. With no changes to the code, yesterday the build was fine and today it's failing with a complaint about a missing v11.0 version. The .NET Framework 4.5.1 got installed/updated last night on this build machine as an automatic update. We're going to force v10.0 with the parameter (or env. variable), but this certainly took us by surprise...

UPDATE: What's even more weird, is that it seems to be the case that today's version of msbuild seems to be using the first line of the sln file to determine which VisualStudioVersion to use by default, whereas yesterday's version did not:

Format Version 12.00

We tested manually changing this to 11.00 and the build started working again.

In our case, even though we're targeting and building everything for 2010/4.0, some devs have been getting ready for VS2012 (since MS claimed that the project files are compatible), and this particular solution was last saved (months ago) in VS2012. Before today, that wasn't causing a problem.

Share:
72,381

Related videos on Youtube

drs9222
Author by

drs9222

Software Engineer in Rochester, NY

Updated on August 22, 2020

Comments

  • drs9222
    drs9222 almost 4 years

    First some background. At the end of 2012 we migrated our vs2008 solution to vs2010 but we still target .NET 3.5. (I know nothing but the latest and greatest here!)

    We hadn't had any issues with this setup until a few weeks ago when people started getting these errors:

    "foo.csproj" (Rebuild target) (16:5) ->
      C:\...\foo.csproj(142,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
    

    The interesting thing is that if you look at the project file it references v10 which makes sense because we don't use Visual Studio 2012.

    This error hit several of us at once and even on older code branches that haven't changed in months.

    I suspect some update got pushed onto our machines that confused things but I don't know what to do about it.

    The short term solution has been to install VS 2012 and not use it but I'm hoping for something a little cleaner than that.

    • drs9222
      drs9222 almost 11 years
      I've found that adding "/p:VisualStudioVersion=10.0" to the MSBuild command line makes this go away but it still feels like a hack.
  • David Peden
    David Peden over 10 years
    I posted a request on the TeamCity forum to incorporate the new path (a la how NuGet settings are handled). Hopefully they tackle this quickly.
  • David Peden
    David Peden over 10 years
    The direct link in the blog post to the separate tools download is no longer valid. The correct link is: microsoft.com/en-us/download/details.aspx?id=40760.
  • David Peden
    David Peden over 10 years
    And, just like that, Jetbrains comes to the rescue with version 8.0.5. Official blog post: teamcitydev.blogspot.com/2013/11/…
  • MordechayS
    MordechayS over 10 years
    If you've got local Powershell build scripts, you can simply add to your path: $env:Path = $env:Path + ";C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications" and use v4 msbuild (You could do this on your build box too)
  • Josh M.
    Josh M. about 10 years
    Yes! Thank you - this is the proper solution.
  • drs9222
    drs9222 almost 10 years
    I know this is pretty old but our original situation hasn't changed and this doesn't really apply to my original question. We are still using vs2010 but have this problem when we don't have vs2012 installed.
  • LambdaCruiser
    LambdaCruiser almost 10 years
    This helped me much more than the highest voted answer which seems to be about an entirely different situation.
  • wal
    wal almost 10 years
    Same here @LambdaCruiser this answer helped a great deal. I looked at the history of my .sln file and altho the 2nd line read # Visual Studio 2010 the first line ended with Format Version 12.00 as at some stage I had upgraded to vs2012 but switch back and forth to vs2010. Like Wayne this problem occurred after running windows update on the CI server
  • wal
    wal almost 10 years
    @drs9222 what happened if you tried Waynes answer ?
  • drs9222
    drs9222 almost 10 years
    I've never tried that one. I know some people are using vs2012 and I assumed that it would just be changed back if I try it.
  • Kevin Obee
    Kevin Obee about 9 years
    Likewise, great advice!
  • gideon
    gideon almost 9 years
    This IMO is the best and simple solution :)
  • Pavel
    Pavel almost 9 years
    Thanks, great solution
  • joedragons
    joedragons almost 9 years
    Maybe obvious but the line you replace with should contain the version of the package you install. The one I installed was 12.0.4 so when I put in the replacement import, I got the same error. When I switched to ...Web.targets.12.0.4\...all good=) Thanks so much!
  • hendrikswan
    hendrikswan over 8 years
    I would recommend adding the correct MSBuild directory to your path, so that you can just invoke MSBuild.exe from your scripts, instead of providing the full path.
  • Dave
    Dave over 8 years
    Of course, it requires that you actually have access to do this on the build server.
  • menkow
    menkow about 8 years
    Solved! For VS2015 works with "C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe"
  • Enny
    Enny about 8 years
    with VS2015 you shopuld use "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"
  • Dan
    Dan about 8 years
    This works w/2015, you just need to update the version folder - as of this date, 14 (as mentioned above)
  • Piotr Kula
    Piotr Kula over 7 years
    ...but why do we have to do this manually? Thanks.. this fixed it for me in VS21017 (For me it was fresh install with VS2017 only - Now I think it was because I have not installed IIS yet)
  • bbodenmiller
    bbodenmiller about 7 years
    You no longer need part b of this answer. For some reason SO has rejected my edit to remove the unnecessary details.
  • Yepeekai
    Yepeekai about 7 years
    For vs2017, it is no longer found in the "program files (x86)\msbuild" folder (15 folder is there but without the exe). It is now at this location: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe Note that you have to replace "Enterprise" with the version of VS you have
  • rdans
    rdans almost 7 years
    "use the new version of MSBuild.exe" - how do you do this exactly? How do you tell visual studio to use the one you want?
  • Uwe Keim
    Uwe Keim almost 7 years
    Works also when copying to V14.0.
  • Ahmed Samir
    Ahmed Samir over 6 years
    thanks I did the same with the last version MSBuild.Microsoft.VisualStudio.Web.targets.14.0.0.3
  • Gedas Kutka
    Gedas Kutka over 6 years
    Perfect answer - eliminates the need to monkey with csproj file or copying things around on build server. Worked across multiple versions of Visual Studio and MSBuild 2017. I've removed "WebApplication.targets" line manually though - nuget did not remove it automatically.
  • XDS
    XDS about 6 years
    HEADSUP: If you have upgraded to VS17+ then using the aforementioned nuget package is bound to SILENTLY break your publishing mechanism (nothing will be generated in the target folder - yet no error will be printed either). This might be because the nuget package in question hasn't been updated as of the time of this writing to support VS17 / MSBuild 15.5.
  • Laser42
    Laser42 almost 4 years
    Cannot find "Edit Build Definition..." in VS2019