I am working with a web application that was written using VS2015, and is being maintained using VS2017. I am trying to write another application to build the full web stack locally using the MSBuild API and other tools. In VS2015 or VS2017 the ASP.NET Web Application project will build successfully, but when running MSBuild programmatically, I keep getting this error:
The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
I have the following build packages installed in my app:
- Microsoft.Build
- Microsoft.Build.Framework
- Microsoft.Build.Tasks.Core
- Microsoft.Build.Utilities.Core
The standard advice I've seen in forums for this error is to install Visual Studio on the build server, but I am doing this locally and I do have Visual Studio installed. I've also read that MSBuild 15 does not come with the WebApplication.targets file. There is also a toolsVersion
parameter on the constructor for Microsoft.Build.Execution.BuildRequestData
that I've tried setting manually to 14.0
but it still seems like my app is trying to use MSBuild 15. (I do have MSBuild 14 installed.)
Questions:
- Can I make this build run in MSBuild 14 programmatically without updating any
csproj
files? - Where can I get
WebApplication.targets
for MSBuild 15?
Solution:
Thanks in large part to @Leo-MSFT I was able to get this working. Here's how:
- Uninstalled the VS2017 ASP.NET and Web Application Development workload, then reinstalled with all of its optional components. This downloaded the missing .targets file.
In my builder application, added this property to my instance of
BuildRequestData
to make MSBuild look in the folders used by v15, rather than using the folders used by v14.["MSBuildExtensionsPath32"] = "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild"