title: C# Object Initializers and v2.0 compiler error
body: <p>I'm having an issue setting up one of my projects in TeamCity (v4.0), specifically when it comes to using Object Initializers.</p>
  
  <p>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.</p>
  
  <p>Specifically the errors are:</p>
  
  <pre><code>[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
  </code></pre>
  
  <p>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.</p>
  
  <p>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?</p>
  
  <p>For those interested, the CSC command being executed is:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>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.</p>