views:

1283

answers:

2

I'm having an issue setting up one of my projects in TeamCity (v4.0), specifically when it comes to using Object Initializers.

The project builds fine normally, however it would seem that TeamCity transforms the build file into something it likes (some MSBuild mutation) and when it comes to compiling the code for a part of the solution it balks when it sees an Object Initializer.

Specifically the errors are:

[11:16:21]: ErrorView.xaml.cs(22, 187): error CS1026: ) expected
[11:16:21]: ErrorView.xaml.cs(22, 208): error CS0116: A namespace does not directly contain members such as fields or methods
[11:16:21]: ErrorView.xaml.cs(27, 16): error CS1518: Expected class, delegate, enum, interface, or struct
[11:16:21]: ErrorView.xaml.cs(35, 16): error CS1518: Expected class, delegate, enum, interface, or struct
[11:16:21]: ErrorView.xaml.cs(46, 91): error CS1031: Type expected
[11:16:21]: ErrorView.xaml.cs(46, 119): error CS0116: A namespace does not directly contain members such as fields or methods
[11:16:21]: ErrorView.xaml.cs(48, 17): error CS1022: Type or namespace definition, or end-of-file expected

When I look into this further it would seem the problem ties back to the transformation of the build file to TeamCity format using CSC from the v2.0 framework directory.

Is it possible to compile code using object initializers (a .NET 3.0 feature) with the .NET 2.0 compiler (I would assume not, though I may be missing something), and if not, does anyone know a way to force it to use the 3.0 compiler (if one exists) or the 3.5 compiler?

For those interested, the CSC command being executed is:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE 
/reference:..\..\..\build\blah.Logging.dll /reference:..\..\..\build\blah.Presentation.Interfaces.dll 
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.VisualBasic.dll /reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" 
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.dll" 
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFramework.Luna.dll" 
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Design.dll 
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll 
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Web.dll
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll 
/reference:C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll 
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\UIAutomationProvider.dll"
/reference:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll" /debug+ /debug:full /filealign:512 
/keyfile:..\..\..\resources\blah.snk /optimize- /out:obj\Debug\blah.dll 
/resource:obj\Debug\blah.UserInterface.Properties.Resources.resources
/resource:obj\Debug\blah.UserInterface.blah.exe.license /target:library 
/win32icon:blah.ico SignalStrengthIndicator.xaml.cs TrayNotifier.xaml.cs ConnectedView.xaml.cs ConnectionProgressView.xaml.cs NetworkPasswordView.xaml.cs 
TrayProgress.xaml.cs NetworkConnectionView.xaml.cs ClassFiles\NetworkTypeConverter.cs 
ClassFiles\SecurityImageConverter.cs ClassFiles\SecurityTooltipConverter.cs 
ClassFiles\SignalStrengthTooltipConverter.cs ClassFiles\SignalVisibilityConverter.cs 
ClassFiles\SynchronizedObservableCollection.cs ConnectionOption.xaml.cs 
DisconnectionProgressView.xaml.cs ErrorView.xaml.cs ..\..\..\config\assemblyversion.cs 
Properties\Resources.Designer.cs Properties\Settings.Designer.cs

Thanks!

Update: I have partially (read: I'm not happy with it) fixed the problem by changing the build runner from Nant to command runner - this just executed the Nant build file as it was intended without any manipulation, though the feedback level is different. Any other suggestions would be appreciated.

+3  A: 

Are you using the sln2005 build runner? That will use the 2.0 csc. Check your build configuration and change it to the sln2008 runner ( see http://www.jetbrains.net/confluence/display/TCD4/3.Build+Runners ). That should use the 3.5 compiler.

If you are using the MSBuild runner http://www.jetbrains.net/confluence/display/TCD4/MSBuild check that you have set the version number to 3.5 on the configuration page.

Edit: after checking up on NAnt See http://www.jetbrains.net/confluence/display/TCD4/NAnt_

where it says: "By default, NAnt msbuild task uses MSBuild 2.0 (from Microsoft .NET Framework 2.0), however you can use MSBuild 3.5 (from Microsoft .NET Framework 3.5) if you add the teamcity_dotnet_use_msbuild_v35 property with the value of true to your msbuild task in NAnt script. For example:"

<msbuild project="SimpleEcho.v35.proj">
   <!-- this property enables MSBuild 3.5 -->
   <property name="teamcity_dotnet_use_msbuild_v35" value="true"/>
   ...
 </msbuild>
Mike Two
Close - but not quote the solution :| I'm actually using a NAnt build file, but that calls some msbuild tasks for certain projects - I'll have a bit more of a look into it.Thanks
Matthew Savage
Is the path to Nant.exe that you set on the NAnt build runner in TeamCity the same path that you use when you use the command runner?
Mike Two
Never mind. I found the answer in the TeamCity docs and updated my answer.
Mike Two
Thanks Mike, this has resolve my problem :)
Matthew Savage
A: 

For NAnt script one may simply define system property teamcity_dotnet_use_msbuild_v35 in the build configuration settings ( http://www.jetbrains.net/confluence/display/TCD4/6.Properties+and+environment+variables) to make it run msbuild 3.5.

On the other hand, if NAnt target framework is set to net-3.5 (only for NAnt 0.86 beta 1) msbuild should be taken from .NET 3.5 folder.

Eugene Petrenko