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
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.
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.
VSB Pro still did not build my project. I got thrown the same error above. The secret sauce was simply to copy the
WebApplications
folder inC:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0
toC:\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.
It is easy to install the 2017 build tools, with the
WebBuildTools
option already included, using chocolaty. Once choco is installed type the following at an admin command prompt:Copy
WebApplications
folder fromC:\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
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 solution to this error I found here.
In my case, the .csproj file contained the following lines:
After replacing the
v14.0
byv$(VisualStudioVersion)
in theVSToolPath
tag, the project could be loaded.I also replaced the
v14.0
byv10.0
in theVisualStudioVersion
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:
If you don't have these lines at all in your .csproj, then you have to add them manually right BEFORE this line:
In my case (slightly different error message but same problem) it was this line:
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.)
Looks you are missing the
Microsoft.VisualStudio.Workload.WebBuildTools
workload.You can install it using
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