我想出了如何做到这一点:
1. 按照https://www.microsoft.com/net/core#macos上的说明安装dotnet
2. 在练习的文件夹中运行
dotnet new --lang f#
3. 将 Program.fs
重命名为练习名称,例如:HelloWorld.fs
4. 修改 project.json
为
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"compilerName": "fsc",
"compile": {
"includeFiles": [
"HelloWorld.fs",
"HelloWorldTest.fs"
]
}
},
"dependencies": {
"NUnit": "3.4.1",
"dotnet-test-nunit": "3.4.0-beta-2"
},
"tools": {
"dotnet-compile-fsc": "1.0.0-preview2-*"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "portable-net45+win8",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"Microsoft.FSharp.Core.netcore": "1.0.0-alpha-160629"
}
}
},
"testRunner": "nunit"
}
这包括 nunit
依赖项。
请注意 includeFiles
,应该包括练习的源代码文件和测试文件。例如,HelloWorld.fs
和 HelloWorldTest.fs
。
5. 通过执行命令安装所需的软件包
dotnet restore
6. 将您的代码添加到先前重命名的源文件中,例如 HelloWorld.fs
7. 最后,通过执行测试来验证
dotnet test