Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get TeamCity working with ASP.NET MVC 3 web project

I'm currently slugging it out with TeamCity trying to get two build configuration working for an ASP.NET MVC 3 solution. My setup is pretty much identical to the guidance at http://www.troyhunt.com/2010/11/you-deploying-it-wrong-teamcity_26.html . When it builds the .sln in the first "Build & Test" build configuration, everything works great. But in the "Package & Deploy" configuration, when I'm having MSBuild build the MyWebProject.csproj file directly, it seems to be resolving core .NET references to .NET 3.5 assemblies, and not .NET 4.0 assemblies.

Accordingly, I'm getting all kinds of .NET 3.5 compilation errors, such as "{ get; set; }" properies needing bodies since they're not marked as abstract.

Additionally, what makes me think that it's picking up v3.5 assemblies, is that during the TeamCity CoreCompile - Csc build activity, it says

"[Csc] c:\Program Files\TeamCity\buildAgent\work\651adc4c97432014\packages\DataAnnotationsExtensions.1.0.2.0\lib\NETFramework40\DataAnnotationsExtensions.dll error CS1705: Assembly 'DataAnnotationsExtensions, Version=1.0.2.0, Culture=neutral, PublicKeyToken=358a5681c50fd84c' uses 'System.ComponentModel.DataAnnotations, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.ComponentModel.DataAnnotations, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'"

Now if I explicitly set the version to "Version=4.0.0.0" in the web project's .csproj file, then it starts giving me similar exceptions on other core .NET assemblies, such as System.Core.dll; i.e., it keeps trying to resolve references to v3.5 assemblies instead of v4.0. Interestingly, I know it's using the MSBuild for v4.0, because the build log states "Using user-defined MSBuild from: C:\Windows\Microsoft.NET\Framework\v4.0.30319." My command line parameters, begin passed to the MSBuild configuration, is as follows:

/P:Configuration=%env.Configuration%
/P:DeployOnBuild=True
/P:DeployTarget=MSDeployPublish
/P:MsDeployServiceUrl=https://%env.TargetServer%/MsDeploy.axd
/P:AllowUntrustedCertificate=True
/P:MSDeployPublishMethod=WMSvc
/P:CreatePackageOnPublish=True
/P:UserName=MyUsername
/P:Password=MyPassword

I've done the following on the build server: * Installed "Microsoft Windows SDK for Windows 7 and .NET Framework 4" * Installed VS 2010 (was hoping to avoid this) * Installed ASP.NET MVC 3 * Added the evn.MSBuild set to %system.DotNetFramework4.0_x86_Path%. * Added the registry key HKLM/SOFTWARE/Microsoft/.NETFramework/SDKInstallRootv2.0 to be "C:\Program Files\Microsoft SDKs\Windows\v7.1."

Thanks for any help you can provide!

Billy McCafferty

like image 342
Billy McCafferty Avatar asked Dec 12 '22 03:12

Billy McCafferty


2 Answers

What you gotta do is make sure a few things are set when you are building the project...

I typically break it into two steps

1) build the solution
In this step make sure the visual studio version is set to 2010.

enter image description here

2) Prebuild Web In this step I invoke commands to build the web project and generate the deployable, set the framework version for the msbuild step and appropriate and platform. Set the targets to "ResolveReferences;_CopyWebApplication" The build file path should be pointed to the csproj file for the mvc application

enter image description here

The last required step is to set a few build parameters.

system.Configuration => Release
system.OutputPath => C:\inetpub\wwwroot\foo\bin
system.WebProjectOutputDir => C:\inetpub\wwwroot\foo

like image 137
iamkrillin Avatar answered Dec 14 '22 16:12

iamkrillin


In your MSBuild step configuration page, you definitely have the MSBuild Version and MSBuildTools version set to 4.0?

enter image description here

like image 35
JustinP8 Avatar answered Dec 14 '22 17:12

JustinP8