.net 如何将Dafny代码与C#程序集链接
我正在尝试建立和运行一个新的系统。我在Mac上使用的是.net 如何将Dafny代码与C#程序集链接,.net,.net-assembly,dafny,.net,.net Assembly,Dafny,我正在尝试建立和运行一个新的系统。我在Mac上使用的是mono。该答案中的build命令不适用于我: $ dafny fileiotest.dfy fileionative.cs Dafny 3.0.0.20820 Dafny program verifier finished with 4 verified, 0 errors Compiled program written to fileiotest.cs Errors compiling program into fileiotest
mono
。该答案中的build命令不适用于我:
$ dafny fileiotest.dfy fileionative.cs
Dafny 3.0.0.20820
Dafny program verifier finished with 4 verified, 0 errors
Compiled program written to fileiotest.cs
Errors compiling program into fileiotest
(8,24): error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
(9,26): error CS0234: The type or namespace name 'Net' does not exist in the namespace 'System' (are you missing an assembly reference?)
(28,28): error CS0012: The type 'TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
(43,28): error CS0012: The type 'TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
(58,28): error CS0012: The type 'TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
(73,28): error CS0012: The type 'TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
(87,28): error CS0012: The type 'TextWriter' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime.Extensions, Version=4.2.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
(1858,18): error CS0117: 'FileStream' does not contain a definition for 'Open'
(1870,23): error CS1061: 'FileStream' does not contain a definition for 'Write' and no accessible extension method 'Write' accepting a first argument of type 'FileStream' could be found (are you missing a using directive or an assembly reference?)
如何“添加对程序集的引用”?可以在
dafny
命令行上完成吗?我认为文件示例不需要System.Net导入,因此您可以从fileionactive.cs
文件中删除这些包含
我不确定是否存在TextWriter
错误,但如果您能找出所需的程序集引用,可以通过手动运行csc
将其添加到命令行。这就是我的机器上的工作原理:
dafny fileiotest.dfy /spillTargetCode:3 /compile:0
csc fileionative.cs fileiotest.cs /r:System.Core.dll /r:System.dll /r:System.Collections.Immutable.dll /r:System.Runtime.dll /r:System.Numerics.dll
/spillTargetCode:3
参数告诉Dafny输出fileiotest.cs
文件。/compile:0
行告诉它跳过最后的编译步骤,因此您可以手动执行
最后,针对最后两个错误:
(1858,18): error CS0117: 'FileStream' does not contain a definition for 'Open'
(1870,23): error CS1061: 'FileStream' does not contain a definition for 'Write' and no accessible extension method 'Write' accepting a first argument of type 'FileStream' could be found (are you missing a using directive or an assembly reference?)
我认为这是一个与Dafny生成的C#代码预期的约定不匹配的Dafny版本。另一个堆栈溢出答案中的
fileioactive.cs
使用名为\u default
的命名空间,但生成的Dafnyfileiotest.cs
使用名为\u module
的命名空间。因此,您只需更改fileionactive.cs
即可使用正确的命名空间\u module
。谢谢!哇,这里真的有几个问题。我还是不能编译这个。我收到一条消息“您必须添加对程序集'nestandard,Version=2.0.0.0…'的引用”。但是/r:netstandard.dll
导致“错误CS0006:找不到元数据文件'netstandard.dll'。dotnet
所做的只是为所有dll提供绝对路径,并且默认情况下,它在命令行中包含对netstandard.dll的引用。因此,这可能对我有用,但我现在没有时间尝试。不幸的是,这超出了我对C#/.net/mono的了解,抱歉:\