MS-Build 2017 "Microsoft.WebApplication.targets " is missing
Asked Answered
Q

12

114

I'm trying to upgrade our buildserver (jenkins) from Visual Studio 2015 to 2017. We're building via MS-Build. I've downloaded and installed MS-Buld tools as described in this answer. If I compile my projects I get an error that Microsoft.WebApplication.targets was not found.

Detailed error:

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

I performed a find in the MS-Build directory:

PS C:\Program Files (x86)\MSBuild> dir -Recurse -Filter "Microsoft.WebApplication.targets"


    Directory: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       11.01.2012     00:23          19654 Microsoft.WebApplication.targets                                                                                                                                                                                


    Directory: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\WebApplications


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       22.07.2013     01:25          19995 Microsoft.WebApplication.targets                                                                                                                                                                                


    Directory: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       06.07.2015     21:55          20118 Microsoft.WebApplication.targets                                                                                                                                                                                


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


Mode                LastWriteTime         Length Name                                                                                                                                                                                                            
----                -------------         ------ ----                                                                                                                                                                                                            
-a----       22.07.2013     01:25          19995 Microsoft.WebApplication.targets

As can be seen the file exists for old compiler versions, but for v15.0 it is missing.

I also have installed Visual Studio 2017 on the build-server. The project succeeds to build if I compile with Visual Studio 2017.

Any hints how to solve this problem? One possible solution is to generate a symbolic link from C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications point to the old v14.0 files (located under C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications).

Thx

Quadrivium answered 19/5, 2017 at 5:13 Comment(2)
Strongly related: Microsoft.WebApplication.targets was not found, on the build server. What's your solution?.Amiamiable
I had this issue with a project using VS 2019. How I fixed it was by opening the csproj file, identifying the line <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0\WebApplications\Microsoft.WebApplication.targets" /> and replacing with <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\WebApplications\Microsoft.WebApplication.targets" />Fodder
C
169

Looks like you are missing the workload for "Web development build tools": Microsoft.VisualStudio.Workload.WebBuildTools.

You can install it by downloading the build tools installer from here (VS2017) or here (VS2019) then running

vs_buildtools.exe --add Microsoft.VisualStudio.Workload.WebBuildTools

or opening vs_buildtools.exe and selecting the "Web development build tools" component in the GUI:

screenshot from GUI

Chetnik answered 19/5, 2017 at 7:52 Comment(8)
how can i run this command its giving 'vs_buildtools.exe' is not recognized as an internal or external command error in developer tool 2017Directional
If you already have downloaded the "Build Tools for Visual Studio 2017" installer (visualstudio.com/thank-you-downloading-visual-studio/…), then you can launch that installer, hit Modify and tick the "Web development build tasks" workload module checkbox. Then click the Modify button and let the installer finish.Liman
Yes, you need to use command line above to install. You cannot find it on the GUI.Dulla
I installed Build Tools for Visual Studio 2017 with Web development build tasks from the link provided however it still does not create C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications folder..i also dont see vs_buildtools.exe..i searched the whole `c:`Roddie
the 2017 version does not install into a global msbulid location. Look in %programfiles(x86)%\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin for the version of msbuild.exe you need to useChetnik
thanks..looks like from VS 2017 the value of $(MSBuildExtensionsPath) was changed to C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild #47077650 thatRoddie
@Martin - I've taken the liberty of expanding your answer a bit. Feel free to revert if you feel that I've gone too far.Amiamiable
@Dulla - it is entirely possible to do this from the GUI - see the screenshot that I included above, or the screenshot in this answer.Amiamiable
P
97

The accepted answer above is technically correct just incomplete, a bit confusing, at least for me, and needed one extra step to get Visual Build Professional working.

  1. vs_buildtools.exe does not technically exist. I had to create a question asking where that file was. It was not obvious that vs_buildtools.exe is vs_buildtools_*******.exe and is the actual installation program. Additionally the the "-add ***" mentioned above is just a shorthand. One can go to the GUI and check both workflow tasks. That does the same thing. I wound up having the vs_buildtools file, though not needing it.

  2. VSB Pro still did not build my project. I got thrown the same error above. The secret sauce was simply to copy the WebApplicationsfolder in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0 to C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0. I then rebuilt the project and all was fine. I placed the WebApplication.targets file at the expected location.

Why Microsoft could not have done that is beyond me. Also, why the separate installation. VS17 installs an enormous amount of stuff. Build Tools is implied, like always. Whatever.

I am posting this answer as hopefully it will help others. I fell into the trap and lost quite a bit of time with my project not building. I hope that this answer clarifies things a bit.

Persuade answered 27/7, 2017 at 14:56 Comment(3)
Confirmed that "Build Tools for Visual Studio 2017" actually copies targets to C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0 while msbuild actually tries to locate the targets at C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0, so I have to copy folders over. Apparently the first one is used by IDE and the 2nd one is used by stand alone msbuild. Strange.Radiopaque
You shouldn't copy anything manually. vs_buildtools.exe is just Visual Studio Installer. It helps you to install Build Tools or Visual Studio. For both, you can install different workloads and components. If you'd like to install workload for Visual Studio, you need to click "Modify" button for it. In such way you can install required components.Crumb
Sure, but the problem is the Visual Studio installer doesn't seem to reliably put the WebApplications folder in both the locations it's needed. Manual copying, as Sarah suggested, is the only way I've managed to reliably get builds working on my dev machine.Ambiguity
A
25

I had a similar issue after having upgraded from Visual Studio 2015 to 2017. When I try to load the web application project, it throwed me the error message:

The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v14.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:\Users\xxx\AppData\Local\Microsoft\VisualStudio\15.0_558e146f\devenv.exe.config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.

The solution to this error I found here.

In my case, the .csproj file contained the following lines:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v14.0</VSToolsPath>
</PropertyGroup>

After replacing the v14.0 by v$(VisualStudioVersion) in the VSToolPath tag, the project could be loaded.

I also replaced the v14.0 by v10.0 in the VisualStudioVersion tag, as the solution in the above link shows. But for me it also worked by leaving it at 14.0.

Here is how these lines should look in the end:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

If you don't have these lines at all in your .csproj, then you have to add them manually right BEFORE this line:

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

In my case (slightly different error message but same problem) it was this line:

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

It seems that projects created with Visual Studio versions since 2011 contain the lines with the VSToolsPath redefinition, while older files did not. Visual Studio never added them automatically when upgrading to a newer VS version, which is why you should add them if they are not there.

Source of this information: https://developercommunity.visualstudio.com/content/problem/27735/project-fails-to-load-with-error-regarding-microso.html?childToView=123664#comment-123664 (click on Show more comments to see the full discussion thread - unfortunately I cannot directly link to comments in this "more" section.)

Approve answered 22/2, 2018 at 10:22 Comment(0)
P
13

It is easy to install the 2017 build tools, with the WebBuildTools option already included, using chocolatey. Once you have installed it, type the following in an admin command prompt:

choco install visualstudio2017buildtools -y

For VS 2019, it's similar:

choco install visualstudio2019buildtools -y
Pharmacognosy answered 28/7, 2017 at 11:4 Comment(3)
You don't have to install a specific version, you can install it this way using Chocolatey and incorporate the accepted answer: cinst visualstudio2017buildtools -params '--add Microsoft.VisualStudio.Workload.WebBuildTools' -y ; cinst microsoft-build-tools -yHitchcock
If I'm on an Azure CI pipeline, I know I can add a task that does this choco command. but.. is there a server expectation or vmImage flag that would also accomplish this?Frazzle
Using AWS CodeBuild, the choco approach worked for us. - choco feature enable -n allowGlobalConfirmation - choco install visualstudio2017-workload-webbuildtoolsNiko
R
10

For VS 2019, I fixed this by copying:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0

to

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

Renn answered 4/3, 2020 at 2:37 Comment(2)
How to get C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0 for VS2019Juniper
My destination folder was C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0Logorrhea
C
9

Copy WebApplications folder from

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0

to

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0

Or in your build script add the following line before compiling

Copy-Item "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications" "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications" -Recurse -Force

Be sure to run it with elevated permissions

Cerveny answered 23/10, 2017 at 15:54 Comment(0)
A
3

how to create VS 2017 pro, asp.net MVC application and build it with Jenkins?

use vs 2017 pro in both dev machine and build server

Check that VisualStudio is set to 15
Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" Condition="false"

set the msbuild tool
to C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe in jenkins global configuration manager

With jenkins, execute windows command batch:
retore nugets: "C:\Program Files (x86)\Jenkins\tools\nuget\NuGet.exe" restore "C:\Program Files (x86)\Jenkins\workspace\theapp_build\theapp.sln"

With jenkins, execute windows command batch:
MSBuild Build File: theapp.sln
Command Line Arguments: /nologo /t:restore /t:rebuild /p:Configuration="Debug" /p:VisualStudioVersion=15.0

Addlebrained answered 28/7, 2017 at 7:50 Comment(0)
D
1

There can be multiple issues that cause this error, but it is generally due to missing files (example of my error below).

Invalid project `C:\xxxxx\Web.Mvc.csproj`. The imported project "C:\Program Files\dotnet\sdk\5.0.403\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the expression in the Import declaration "C:\Program Files\dotnet\sdk\5.0.403\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" is correct, and that the file exists on disk.  

For myself, I am building a .NET 4.8 solution via powershell using the dotnet command, running against VS2019. The failing projects where created in VS2010/15/17.

As such to address the missing files, I simply created a symlink between the files it was looking for and the location it expected.

mklink /J "C:\Program Files\dotnet\sdk\5.0.403\Microsoft\VisualStudio" "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VisualStudio"

This resolved the issue and now I can build solutions programmatically (this should also work for other instances, providing you use the correct file paths to make the symlink).

Dauphine answered 17/11, 2021 at 7:2 Comment(0)
D
0

For Visual Studio 2022 use the following commands with chocolatey:

choco install visualstudio2022buildtools
choco install visualstudio2022-workload-webbuildtools

see also: https://community.chocolatey.org/packages/visualstudio2022-workload-webbuildtools

Dionnadionne answered 28/12, 2022 at 13:27 Comment(0)
Y
0

For VS2022 I was getting the same error with v16:

C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\v16.0\WebApplications\Microsoft.WebApplication.targets" was not found

In VS2022 you need to Modify the Visual Studio Build Tools 2019:

enter image description here

Install the Web Development Build Tools:

enter image description here

Ylangylang answered 12/2 at 5:27 Comment(0)
S
-1

Install the Nuget package: MSBuild.Microsoft.VisualStudio.Web.targets

I found that info here: https://www.primordialcode.com/blog/post/microsoft-webapplication-targets-not-found

Surveillance answered 16/8, 2023 at 2:4 Comment(0)
D
-3

I just use Visual Studio Installer to update Visual Studio Community 2017, then the problem is solved.

Dhow answered 11/12, 2019 at 2:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.