MSBuild in TeamCity of Visual Studio 2012 solution

↘锁芯ラ 提交于 2019-11-27 10:19:23
NightOwl888

Actually, you don't need to install Visual Studio on your CI server. You only need to copy a few folders from a development machine to the same location on the CI server.

VS 2015:

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

VS 2013:

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

VS 2012:

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

VS 2010:

  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web
  • C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications

.NET 4.6:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6

.NET 4.5.2:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2

.NET 4.5.1:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1

.NET 4.5:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5

.NET 4.0.1:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0.1

.NET 4.0:

  • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0

Or, as Matt suggested, you could copy them into a subdirectory of your project and alter the <MSBuildExtensionsPath32> location in your MSBuild (typically .csproj or .vbproj) file.

Once you have done this, your project will compile. You should still set the VisualStudioVersion explicitly to the one you are using just to be sure it is set right.

NOTE: This solution works for all project types (including web projects). For a web site (that has no project file), I ended up installing the Windows SDK matching the .NET SDK version I am using, because there were missing registry keys that were causing it not to build.

BahaiResearch.com

Turns out it's really simple. To make MSBuild run VS2010 as the builder on a solution made by VS2012 in TeamCity, simply set the environment variable for the build configuration like this:

Name: env.VisualStudioVersion 
Value: 10.0

Note TeamCity does not need VS2012 installed.

Alternatively, you can copy the build targets you need from the c:\Program Files (x86)\MSBuild to a subdirectory of your project (for example .\Build) making sure to preserve structure and add the following to your csproj:

<!-- redirect msbuild path so targets can be added to source control -->
<PropertyGroup>
  <MSBuildExtensionsPath32>..\Build\</MSBuildExtensionsPath32>
</PropertyGroup>

For example, if my project root is C:\Dev\MyProjSln\MyProj

  • Create Folder C:\Dev\MyProjSln\Build\Microsoft\VisualStudio\version\WebApplications\
  • Copy Contents of C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\version>\WebApplications\ to created folder
  • Add MSBuildExtensionsPath32 element to Property Group under Project node in csproj
  • Profit!

Personally, I prefer this method of tracking build target dependencies, as it prevents build server from being dependent on having undocumented folder structure requirements, and gets your dependencies into source control

Thomas Eyde

As described here:

  • Install nuget MSBuild.Microsoft.VisualStudio.Web.targets
  • Edit the .csproj file

Replace:

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

with:

<Import Project="..\packages\MSBuild.Microsoft.VisualStudio.Web.targets.11.0.2.1\tools\VSToolsPath\WebApplications\Microsoft.WebApplication.targets" Condition="true" />

Obviously you have to make sure versions match your case both on the nuget installed and path in <Import>

I totally disagree with changing the project files because that might affect other developers. This is what worked for me since the v11.0 folder was missing on MS build folder: 1)Create v111.

  1. Create v11.0 folder on C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio
  2. Copy Web and WebApplications folders from my development box "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0"
  3. Booom! work like a charm\
  4. Note: I installed "Microsoft Visual Studio 2012 Shell (Isolated) Redistributable Package"

Firstly, TeamCity does not require presence of Visual Studio of any version to build. When a build step in the project is configured with MSBuild runner TeamCity needs to know which version of MSBuild to use. This is a setting of a build step. Proper MSBuild version must be selected in a build step configuration according to the .NET tools installed on a build machine. TeamCity will use that value to determine the location path and will set an environment variable when invokes MSBuild.

The problem with the Visual Studio 2012/2013 is that it's only supported by TeamCity starting 8.1.0. So if your TeamCity version is before 8.1. you need to upgrade to the latest 8.1.x to see a setting for MSBuild Tools 2013. Once you select a proper MSBuild version in the build step settings the problem will disappear. For more information read here: http://blog.turlov.com/2014/07/upgrade-teamcity-to-enable-support-for.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!