【发布时间】:2020-08-14 10:33:34
【问题描述】:
在 Windows 上使用 Mono csc 编译器创建的二进制文件时遇到了一些问题。这是一个用于 Framework 4.0 的基本 CLI 项目,带有一些内部程序集。以前,我们使用 xbuild 构建这个工具,结果可以在任何地方使用。现在不能使用 xbuild(内部政策原因),所以我添加了一个直接调用 csc 命令的脚本。 .exe 仍然可以在 Mono 中运行,但在 Windows 上我得到:
找不到方法:“System.String System.String.TrimEnd(Char)”。 在……
这令人惊讶。当我在代码中调查该函数调用时,就像:
subDirectory.Replace('/', Path.DirectorySeparatorChar).TrimEnd(Path.DirectorySeparatorChar)
因此,该签名在 .NET 中不可用,但 .TrimEnd(params Char[]) 可用。并且编译器通常应该在单个参数和参数数组之间进行转换。
我的 csc 命令行如下所示:
csc /debug:full /debug:portable /optimize- /define:"DEBUG;TRACE" /langversion:最新的 .v4.0.AssemblyAttribute.cs /out:bin/Debug/myproject.exe /target:exe *.cs /.cs /r:bin/Debug/some_custom_depencency.dll /r:bin/Debug/some_other_custom_dependency.dll … /nostdlib /r:System.dll /r:System.Xml.Linq.dll /r:System.Data.DataSetExtensions.dll /r:System.Data.dll /r:System.Xml.dll /r:System.Core.dll /r:mscorlib.dll /warn:4
与 msbuild 的作用差不多,只是使用了 shell 的通配符扩展。 .v4.0.AssemblyAttribute.cs 文件是我从 xbuild 临时文件中获取的文件(它定义了 .NET Framework 版本)。
我在 dotPeek 中检查了新旧 exe(msbuild 和自定义调用),除了签名之外,一切看起来都一样。文件可以通过 Mono 本身运行。
我的想法已经不多了,有人可以提出一些尝试或更改的建议或立即知道原因吗?
【问题讨论】:
-
对于 .NET Framework 4.0 项目,您应该使用 .NET Framework 4.0 附带的 MSBuild 4.0(Windows 8 及更高版本的一部分),blog.lextudio.com/the-rough-history-of-msbuild-cc72a217fa98 调用 csc 并希望“它或多或少相同msbuild 做了什么”不会让你走在正确的轨道上。
-
让我重复一遍:“现在不能使用 xbuild(内部政策原因)”(显然它在单声道世界中的替代品,msbuild)。