Nei*_*ard 8 .net-core azure-functions
我正在努力让现有的 .Net 函数应用程序在本地运行。它是在 Windows 上使用 Visual Studio 开发的,但我在 Mac(M1 CPU)上使用 VS Code。我对 .Net 还很陌生,我正在努力弄清楚需要配置什么才能让项目运行。
\n我添加了一个launch.json:
\n{\n "version": "0.2.0",\n "configurations": [\n {\n "name": "Attach to .NET Functions",\n "type": "coreclr",\n "request": "attach",\n "processId": "${command:azureFunctions.pickProcess}"\n }\n ]\n}Run Code Online (Sandbox Code Playgroud)\n和 local.settings.json:
\n{\n "IsEncrypted": false,\n "Values": {\n "AzureWebJobsStorage": "UseDevelopmentStorage=true",\n "FUNCTIONS_WORKER_RUNTIME": "dotnet"\n }\n}Run Code Online (Sandbox Code Playgroud)\n并且项目中已有一个tasks.json:
\n{\n "version": "2.0.0",\n "tasks": [\n {\n "label": "clean (functions)",\n "command": "dotnet",\n "args": [\n "clean",\n "/property:GenerateFullPaths=true",\n "/consoleloggerparameters:NoSummary"\n ],\n "type": "process",\n "problemMatcher": "$msCompile",\n "options": {\n "cwd": "${workspaceFolder}/Naboor.Statistics"\n }\n },\n {\n "label": "build (functions)",\n "command": "dotnet",\n "args": [\n "build",\n "/property:GenerateFullPaths=true",\n "/consoleloggerparameters:NoSummary"\n ],\n "type": "process",\n "dependsOn": "clean (functions)",\n "group": {\n "kind": "build",\n "isDefault": true\n },\n "problemMatcher": "$msCompile",\n "options": {\n "cwd": "${workspaceFolder}/Naboor.Statistics"\n }\n },\n {\n "label": "clean release (functions)",\n "command": "dotnet",\n "args": [\n "clean",\n "--configuration",\n "Release",\n "/property:GenerateFullPaths=true",\n "/consoleloggerparameters:NoSummary"\n ],\n "type": "process",\n "problemMatcher": "$msCompile",\n "options": {\n "cwd": "${workspaceFolder}/Naboor.Statistics"\n }\n },\n {\n "label": "publish (functions)",\n "command": "dotnet",\n "args": [\n "publish",\n "--configuration",\n "Release",\n "/property:GenerateFullPaths=true",\n "/consoleloggerparameters:NoSummary"\n ],\n "type": "process",\n "dependsOn": "clean release (functions)",\n "problemMatcher": "$msCompile",\n "options": {\n "cwd": "${workspaceFolder}/Naboor.Statistics"\n }\n },\n {\n "type": "func",\n "dependsOn": "build (functions)",\n "options": {\n "cwd": "${workspaceFolder}/Naboor.Statistics/bin/Debug/net6.0"\n },\n "command": "host start",\n "isBackground": true,\n "problemMatcher": "$func-dotnet-watch"\n }\n ]\n}Run Code Online (Sandbox Code Playgroud)\n我应该能够以某种方式从命令行运行这个项目吗?我需要指向tasks.json 中的任务吗?
\n如果我在 VS Code 中使用 F5 运行它,则会收到以下错误:
\nExecuting task: func host start\n\nCan\'t determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]\nCan\'t determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]\nCan\'t determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]\n\nAzure Functions Core Tools\nCore Tools Version: 4.0.4544 Commit hash: N/A (64-bit)\nFunction Runtime Version: 4.3.2.18186\n\nCan\'t determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]\nCan\'t determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]\n[2022-05-25T12:24:12.674Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4544/workers/python\n[2022-05-25T12:24:12.682Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.\n[2022-05-25T12:24:12.991Z] Failed to initialize worker provider for: /opt/homebrew/Cellar/azure-functions-core-tools@4/4.0.4544/workers/python\n[2022-05-25T12:24:12.991Z] Microsoft.Azure.WebJobs.Script: Architecture Arm64 is not supported for language python.\n[2022-05-25T12:24:13.118Z] A host error has occurred during startup operation \'a0f1f8a3-92f6-434a-9ab1-17055f0828f4\'.\n[2022-05-25T12:24:13.118Z] Microsoft.Azure.WebJobs.Script.WebHost: Secret initialization from Blob storage failed due to missing both an Azure Storage connection string and a SAS connection uri. For Blob Storage, please provide at least one of these. If you intend to use files for secrets, add an App Setting key \'AzureWebJobsSecretStorageType\' with value \'Files\'.\nValue cannot be null. (Parameter \'provider\')\nThe terminal process "/opt/homebrew/bin/zsh \'-c\', \'func host start\'" terminated with exit code: 1.Run Code Online (Sandbox Code Playgroud)\n我以为这就是
"FUNCTIONS_WORKER_RUNTIME": "dotnet"Run Code Online (Sandbox Code Playgroud)local.settings.json 的一部分是用来做什么的?\n我对此很陌生,有人可以指导我走上正确的道路吗?
\n谢谢
\nS\xc3\xb8ren
由于没有明确提及,多个输出错误的影响是由于缺少local.settings.json文件造成的。此答案明确针对 Visual Studio 2022 用户,而不是 Visual Studio Code!
作为参考,错误输出:
Executing task: func host start
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Azure Functions Core Tools
Core Tools Version: 4.0.4544 Commit hash: N/A (64-bit)
Function Runtime Version: 4.3.2.18186
Can't determine project language from files. Please use one of [--csharp, --javascript, --typescript, --java, --python, --powershell, --custom]
Run Code Online (Sandbox Code Playgroud)
如果您从其他源本地添加了文件(通过添加现有项目功能),Visual Studio 将保留在项目中,但不会将其复制到发布目录。此步骤通常是必要的,因为该文件位于.gitignore中,因此不会从您的存储库中提取。
在.csproj中,它将如下所示:
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
Run Code Online (Sandbox Code Playgroud)
只需删除该线
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
Run Code Online (Sandbox Code Playgroud)
确实如此。为了证明它只需func host start从命令行在项目的根目录中运行并且它将起作用,因为这适用于项目本身,而无需 Visual Studio 执行发布步骤。
也可能发生复制步骤完全丢失的情况,然后添加该步骤或使用VS 属性窗口 (F4) 中的始终复制功能。
我们在本地进行了相同的尝试,并且能够成功运行。
我相信您只是缺少本地 .
步骤如下:-
确保您的本地已安装存储模拟器Azure function runtime。Dotnet sdk如果没有,您可以从 VS CODE 扩展下载,而AZURITE不是模拟器,因为它已被弃用。
在 VS CODE 安装扩展 Azure,其中所有工具都可用,c#(您想要的任何语言)和正在安装的 Azure 功能。
task.json由于您已有现有文件,因此在完成上述操作后,无需通过运行以下命令来测试您的项目:。dotnet build一旦构建成功运行,
。func host start(如果您有现有/新项目,请不要运行,func init因为它将再创建一个.csproj文件,然后可能会失败)
有关更多信息,请参阅此MICROSOFT 文档| 在 VS Code 中创建 AZURE 函数的分步教程。
或者,如果您想学习在Macos上使用 Visual Studio 创建 Azure 函数,请参阅此微软文档。
| 归档时间: |
|
| 查看次数: |
9107 次 |
| 最近记录: |