0

We have a Visual Studio 2013 project who's .csproj looks like this

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

Recently we migrated the solution to Visual Studio 2017 but somehow tool version remained same.

I am using TeamCity to build my project & on teamcity server we only have MS build version 14. If I use it to build the app, I get following error: 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 <Import> declaration is correct, and that the file exists on disk.

What is the easiest way to update the tool-version is .csproj? If I update it manually, would it cause any issues? are there any other settings/config I need to change once I make this change?

SharpCoder
  • 18,279
  • 43
  • 153
  • 249

1 Answers1

0

ToolsVersion is not the main cause of this issue I think, so you can feel free to manually change it. And for project from VS2013, its ToolsVersion should be 12.0 instead of 4.0.

VS2013=>12.0, VS2017=>15.0, VS2015=>14.0: So you now have one project migrated from VS2012 to VS2017, and now you use msbuild of VS2015 to build it. For this scenario, here're some suggestions which may help:

1.Change the ToolsVersion to 12.0(or 14.0). This actually makes a bit effect.

2.Make sure you've installed web application workload for your msbuild 14.0 in server. If your msbuild 14.0 comes from VS2015, please check if you can create new web application project in it, then you'll know if you've installed web workload in VS! (The missing targets come from the web app workload, similar issue see here.)

If you can find the missing file in C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\WebApplications, trying passing /p:VisualStudioVersion=14.0 to msbuild command when you configure it in teamcity.

3.The most recommended way is to install the msbuild from higher VS version. MSbuild has independent package for VS2017 and VS2019.(Build Tools for VS2017 or VS2019)

You can find their download link here,see Tools for VS category. You can install this package(Enable web-related workload!) in your server(you don't need to install whole VS IDE), and then you can call msbuild.exe from C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin or C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin in teamcity to build current project.

Note: MSBuild from higher VS version can always build projects from earlier VS versions, but msbuild from earlier sometimes can't recognize projects from higher vs versions. So it's recommended to use msbuild 15.0 to build projects from VS2017, instead of using msbuild 14.0.

LoLance
  • 25,666
  • 1
  • 39
  • 73
  • Thank you for the reply. I have been trying to download MSBuild from https://visualstudio.microsoft.com/downloads/ but it gives a online version. I need offline version. – SharpCoder Jan 24 '20 at 15:18
  • If you need offline version, you can get useful info from this: [VisualStudio Build Tools 2017 offline installer](https://stackoverflow.com/questions/46684230/visualstudio-build-tools-2017-offline-installer/). Let me know if it helps or not :) – LoLance Jan 27 '20 at 02:12