尝试启动 .NET 控制台应用程序。更喜欢 F#,但在 C# 或 VB 中也会出现相同的错误。
Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed。当我创建新应用程序时,我会收到该警告,并在尝试构建时收到错误。
这是使用 Visual Studio 附带的默认 Hello World 模板。我希望第一次构建应用程序附带的预构建模板。使用VS 2019 16.8.5。
我搜索了 Visual Studio 项目和源目录,但找不到任何 global.json。
编辑:在 C:\users\username 找到 global.json
{
"sdk": {
"version": "3.1.300",
"rollForward": "latestMinor"
}
}
Run Code Online (Sandbox Code Playgroud)
我相当确定我已经安装了 SDK,但会仔细检查。
我很确定这是不可能的,但我想我会仔细检查一下。我想我正在尝试模仿打字稿的联合类型。
我有一个类型
type StringOrInt =
| String of string
| Int of int
Run Code Online (Sandbox Code Playgroud)
然后是一个函数
let returnSelf (x: StringOrInt) = x
Run Code Online (Sandbox Code Playgroud)
目前该函数必须像这样调用
returnSelf (String "hello")
Run Code Online (Sandbox Code Playgroud)
是否可以做
returnSelf "hello"
Run Code Online (Sandbox Code Playgroud)
并推断它是一个有效的 StringOrInt?
出于演示目的,我正在制作一个插入函数,我想返回传入类型的变量。
我是初始查询的用户 Dapper.fsharp,然后我想运行原始 SQL 查询来获取最后插入的值。
所以我有这样的东西用于演示目的
let Insert<'a> asyncQuery =
asyncQuery
|> connection.InsertAsync<'a>
|> RunSynchronously
|> ignore
(*This is a Dapper.fsharp query. Running this returns the number of rows inserted (int) *)
let table = asyncQuery.Table (*This is a string*)
let result =
connection.Query<'a>($"""Select * From {table} Where id = (select last_insert_id())""") (*Should return an IENumerable of type 'a*)
|> EnumerableToArray
result |> first
Run Code Online (Sandbox Code Playgroud)
然后这就是所谓的
let newSession =
insert {
table "sessions"
value newSession
} |> Insert
Run Code Online (Sandbox Code Playgroud)
其中 newSession 是会话类型 …
我对代码表示歉意,它处于我正在积极使用的状态。
在 Konva JS 中,我正在创建标签。它基本上是一个组,它具有形状和文本元素。形状是从数据库动态绘制的,每个数据库行都有坐标、形状(方形、圆形等)、大小和旋转。这些值乘以取决于屏幕尺寸的比例。我有一个可行的解决方案,我已经使用了几周,但我也有一个可以改变形状的函数。所以我按下一个按钮,它会更新数据库(例如将正方形更改为圆形),然后重新绘制画布。因为从正方形到圆形从从左上角绘制的形状变为从中心绘制的形状,所以它会弄乱坐标。我决定改用宽度/2 的偏移量绘制矩形,以便也从中心绘制矩形。
随后我不断地进一步打破它,现在我根本无法让文本居中。无论形状、大小或旋转如何,我都需要文本居中。
当前代码
//Gets table array from SQL
tables = callPhpFunction('getTablesInRoom', room);
tables = JSON.parse(tables);
numberOfTables = tables.length;
index = 0;
tableLayer = new Konva.Layer();
tableLayer.add(transformer);
//For every table
while(index < numberOfTables){
tableNumber = tables[index]['tablenumber'];
offset_x = 0;
offset_y = 0;
pos_x = parseInt(tables[index]['posx']) * scale;
pos_y = parseInt(tables[index]['posy']) * scale;
shape = tables[index]['shape'];
tableWidth = parseInt(tables[index]['width']) * scale;
tableHeight = parseInt(tables[index]['height']) * scale;
rotation = parseInt(tables[index]['rotation']);
fillColor = "gray";
strokeColor = "black";
var …Run Code Online (Sandbox Code Playgroud) 我想开始在一个项目上使用 F# 而不是 Javascript(该项目已经建立并完成了后端,但除了 HTML 和 CSS 之外还没有前端)。
我对 Node 的了解相对较少,对 .NET 的了解也很少,但我以前开发过表单应用程序。目前,我已经用 F# 编写了许多控制台应用程序,但我讨厌使用和开发命令行应用程序,我喜欢 GUI,所以我非常想在实际项目中开始使用 F#,但我就是无法让它工作。我进行了多次尝试,其中 SAFE 堆栈在运行应用程序时失败(没有代码更改)并拒绝重建,但 .NET 到目前为止一直很稳定。不过,我想从这个项目中得到的是一个简单的 F# 到 JS 的复杂化。我按照寓言网站上的说明生成了一个项目模板,完成npm install并成功构建,但npm start总是失败,找不到命令。
c:\fable>npm start
> SimpleFableApp@1.0.0 start c:\fable
> dotnet fable watch src --run webpack-dev-server
Could not execute because the specified command or file was not found.
Run Code Online (Sandbox Code Playgroud)
我只想编写一个 FSX 文件(或 FSProj),然后将其编译为可以包含在 html 中的 Javascript 文件。我只是将其插入到我现有的 PHP 项目中。
所以我开始一个新的 .fsx 文件,放一些简单的东西,比如
let x=10
然后我想将其编译为 Javascript 源代码,我认为我只需要基本指令。我想我已经安装了寓言编译器,npm-install fable-compiler它确实给出了结果+fable-compiler@2.13.0(不确定这是否是最新的)。 …