MSBuild in TeamCity of Visual Studio 2012 solution
I have a VS 2012 web project /sln that I am trying to build in TeamCity. it uses .NET 4.5 which is installed on TeamCity.
The TeamCity server has VS 2010 installed only .
I get this error when the build runs:
C:BuildAgentworkd5bc4e1b8005d077CUSAAdmin.WebCUSAAdmin.Web.csproj(799, 3):
error MSB4019:
The imported project
"C:Program Files (x86)MSBuildMicrosoftVisualStudiov11.0WebApplicationsMicrosoft.WebApplication.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk. Project CUSAAdmin.WebCUSAAdmin.Web.csproj failed.
Project CUSAAdmin.sln failed.
It is trying to use Visual Studio 2012 (v11.0) to build.
I have set the VisualStudioVersion to be 10 in the build.xml though??
<Target Name="BuildPackage">
<MSBuild Projects="CUSAAdmin.sln" ContinueOnError="false"
Targets="Rebuild"
Properties="Configuration=$(Configuration); VisualStudioVersion=10.0" />
As well inside the project it is defaulting to VS2010
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath
Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
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:
VS 2013:
VS 2012:
VS 2010:
.NET 4.6:
.NET 4.5.2:
.NET 4.5.1:
.NET 4.5:
.NET 4.0.1:
.NET 4.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.
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:DevMyProjSlnMyProj
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
链接地址: http://www.djcxy.com/p/81628.html