【问题标题】:Compiling C# 7 code containing ValueTuple with Mono 5使用 Mono 5 编译包含 ValueTuple 的 C# 7 代码
【发布时间】:2017-07-10 14:49:09
【问题描述】:

我正在尝试使用 Mono 5 在 Linux 构建服务器上编译我的新 C# 7 代码。不幸的是,当我使用新的 ValueTuple 语法时项目失败:

MyClass.cs(100,38): 错误 CS1003: 语法错误,'(' 预期 [/path/to/My.csproj]

我的项目文件中有以下包引用:

<PackageReference Include="System.ValueTuple" Version="4.3.0" />

我在我的快速构建脚本中使用了以下命令:

# msbuild My.sln /t:restore
# msbuild My.sln /p:Configuration=Release /p:Platform="Any CPU"

MSBuild 日志指示语言版本为 7,并显示对 System.ValueTuple.dll 的引用:

核心编译:

/usr/lib/mono/4.5/csc.exe /noconfig /unsafe- /checked- /nowarn:1701,1702,1705,1701,1702 /langversion:7 /nostdlib+ /errorreport :prompt /warn:4 /doc:bin/Release/net461/My.xml /define:TRACE;RELEASE;NET461 /highentropyva+ ... /reference:/root/.nuget/packages/system.valuetuple/4.3 .0/lib/netstandard1.0/System.ValueTuple.dll ... /debug- /debug:portable /filealign:512 /nologo /optimize+ /out:obj/Release/net461/My.dll /subsystemversion :6.00 /target:library /warnaserror- /utf8output /deterministic+ My.cs "/tmp/.NETFramework,Version=v4.6.1.AssemblyAttributes.cs" obj/Release/net461/My.AssemblyInfo.cs

有没有人使用 Mono 5 在 Linux 上使用新的 ValueTuple 语法成功编译 C#?它只是起作用了,还是您需要调整环境才能使其起作用?

我的构建服务器运行的是 Ubuntu 16.04,并且安装了 mono-devel 5.0.1.1-0xamarin5+ubuntu1604b1。

【问题讨论】:

  • 也许this可以帮助你。
  • @DdarkSideE 谢谢!我已经通过我的 csproj 文件中的相应 &lt;PackageReference /&gt; 元素安装了 NuGet 包。我将编辑问题以包含该信息。 MSBuild 在对 csc.exe 的调用中正确引用了 NuGet 包缓存中的 System.ValueTuple.dll。
  • 此错误似乎是由于从 MSBuild 运行或 sln 或 csproj 文件中的设置所致。我刚刚创建了一个简单的测试并使用 csc 手动编译(并从 4.3.0 NuGet 包中引用相同的 System.TupleValue.dll)。简单的测试编译并运行没有错误。我会尝试找到解决方案并发布答案。

标签: c# linux mono c#-7.0


【解决方案1】:

我卸载了稳定的 mono-devel 5.0.1.1-0xamarin5+ubuntu1604b1 并将其替换为 beta mono-devel 5.2.0.196-0xamarin7+ubuntu1604b1。该项目现在编译没有错误。

我认为 mono 中的一个错误已经修复,可以解决这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-05
    • 1970-01-01
    相关资源
    最近更新 更多