2

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:

  1. Uninstalled the VS2017 ASP.NET and Web Application Development workload, then reinstalled with all of its optional components. This downloaded the missing .targets file.
  2. 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"

2
  • Using vs_buildtools__XXX.exe GUI installer fixed it for me with above recommendations. I had the following error "error MSB4057: The target "Package" does not exist in the project."
    – ChristoD
    Nov 22, 2018 at 12:10
  • @JamesFaix How's that go w/ #2? I'm using Jenkins to call MSBuild v15. Don't entirely understand where you're placing that ["MSBuildExtensionsPath32"] property?
    – fusion27
    May 10, 2019 at 16:23

1 Answer 1

1

Can I make this build run in MSBuild 14 programmatically without updating any csproj files?

MSBuildExtensionsPath32 is set internally by MSBuild. If you do not want update you .csproj file, you can try to override the value in your project file:

  <PropertyGroup>
    <MSBuildExtensionsPath32>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild</MSBuildExtensionsPath32>
  </PropertyGroup>

  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
  <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" Condition="false" />

But I'm not sure if it will introduce other error(Not tested).

Where can I get WebApplication.targets for MSBuild 15?

The path of WebApplication.targets for MSBuild 15 is:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
10
  • I know that that is the path where the targets should be, but I do not have them. The general instructions I've seen are to install Visual Studio, but I think this does not apply to the 2017 version.
    – JamesFaix
    Nov 3, 2017 at 14:37
  • 1
    @JamesFaix, since you have installed Visual Studio 2017 but not have that targets, you should also install the Workloads ASP.NET and web development by Installer.
    – Leo Liu
    Nov 3, 2017 at 14:58
  • 1
    @JamesFaix, how about this issue after install the Workloads ASP.NET and web development by Installer?
    – Leo Liu
    Nov 6, 2017 at 10:14
  • I just opened up the installer and I already have that workload. I will try removing it and re-adding.
    – JamesFaix
    Nov 6, 2017 at 23:25
  • 1
    Actually I spoke too soon, the targets file is now in the directory mentioned above (Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Microsoft\VisualStudio\15.0\WebApplications) but MSBuild is looking for the file in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v15.0\WebApplications
    – JamesFaix
    Nov 7, 2017 at 2:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.