C# 对象初始值设定项和 v2.0 编译器错误

发布于 2024-07-10 01:48:06 字数 3517 浏览 11 评论 0原文

我在 TeamCity (v4.0) 中设置我的项目之一时遇到问题,特别是在使用对象初始值设定项时。

该项目通常构建得很好,但是 TeamCity 似乎将构建文件转换为它喜欢的东西(一些 MSBuild 突变),并且当涉及到为解决方案的一部分编译代码时,它会在看到对象初始值设定项时犹豫不决。

具体来说,错误是:

[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

当我进一步研究这个问题时,问题似乎与使用 v2.0 框架目录中的 CSC 将构建文件转换为 TeamCity 格式有关。

是否可以使用对象初始值设定项(.NET 3.0 功能)和 .NET 2.0 编译器来编译代码(我假设不能,尽管我可能会丢失某些内容),如果不能,是否有人知道强制使用它的方法3.0 编译器(如果存在)还是 3.5 编译器?

对于那些感兴趣的人,正在执行的 CSC 命令是:

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

谢谢!

更新:我已经部分(阅读:我对此不满意)通过将构建运行程序从 Nant 更改为命令运行程序来解决了问题 - 这只是按照预期执行了 Nant 构建文件,没有任何操作,尽管反馈级别是不同的。 任何其他建议将不胜感激。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

べ映画 2024-07-17 01:48:08

对于 NAnt 脚本,可以简单地在构建配置设置中定义系统属性 teamcity_dotnet_use_msbuild_v35 ( http://www.jetbrains.net/confluence/display/TCD4/6.Properties+and+environment+variables) 使其运行 msbuild 3.5。

另一方面,如果 NAnt 目标框架设置为 net-3.5(仅适用于 NAnt 0.86 beta 1),则应从 .NET 3.5 文件夹中获取 msbuild。

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.

寄意 2024-07-17 01:48:06

您使用的是 sln2005 构建运行程序吗? 这将使用 2.0 csc。 检查您的构建配置并将其更改为 sln2008 运行程序(请参阅 http:// /www.jetbrains.net/confluence/display/TCD4/3.Build+Runners )。 那应该使用3.5编译器。

如果您使用的是 MSBuild 运行程序 http://www.jetbrains.net/confluence/display /TCD4/MSBuild
检查您是否已在配置页面将版本号设置为3.5。

编辑:检查 NAnt 后
请参阅http://www.jetbrains.net/confluence/display/TCD4/NAnt_

其中显示:“默认情况下,NAnt msbuild 任务使用 MSBuild 2.0(来自 Microsoft .NET Framework 2.0),但是如果添加值为 true 的 teamcity_dotnet_use_msbuild_v35 属性,则可以使用 MSBuild 3.5(来自 Microsoft .NET Framework 3.5) NAnt 脚本中的 msbuild 任务例如:”

<msbuild project="SimpleEcho.v35.proj">
   <!-- this property enables MSBuild 3.5 -->
   <property name="teamcity_dotnet_use_msbuild_v35" value="true"/>
   ...
 </msbuild>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文