无法在 Rider (Mint/Ubuntu) 中启动 Azure Function 项目

问题描述 投票:0回答:1

我有一个大型解决方案,其中包含在 Ubuntu / Mint Linux 环境中的 Rider 中运行的所有

.net8
代码。

API 运行正常,但函数无法启动。当我运行它们时,我收到以下消息...

/home/{myname}/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.72.0/func host start --pause-on-error
dotnet sdk is required for dotnet based functions. Please install
Press any key to continue....

我通过

dotnet-install
脚本安装了 .net8 SDK(否则其他几个项目将无法工作)。

我在这里缺少什么?

运行

dotnet --list-sdks
给我以下结果...

6.0.410 [/home/{myname}/.dotnet/sdk]
7.0.304 [/home/{myname}/.dotnet/sdk]
8.0.100 [/home/{myname}/.dotnet/sdk]
8.0.204 [/home/{myname}/.dotnet/sdk]

注意: 更新到最新的 net 8 版本,看看是否有任何区别(没有)。

这是 *.csproj (如果有帮助的话)

<Project Sdk="Microsoft.NET.Sdk">
  
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <AzureFunctionsVersion>v4</AzureFunctionsVersion>
    <OutputType>Exe</OutputType>
    <UserSecretsId>parity-portfolioplus-brain-function</UserSecretsId>
  </PropertyGroup>
  
  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.21.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.CosmosDB" Version="4.8.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.1" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.17.2" />
    <PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.22.0" />
    <PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.2.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.20.1" />
  </ItemGroup>
  
  <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>
  
  <ItemGroup>
    <Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
  </ItemGroup>
  
</Project>

我的

host.json
......

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            },
            "enableLiveMetricsFilters": true
        }
    }
}

我的

local.settings.json
...

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "APPLICATIONINSIGHTS_CONNECTION_STRING": "",
    "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
  }
}

我已经有运行 Azurite 和 Cosmos 的 Docker 容器 - Cosmos 运行良好,但 Azurite 容器上的配置可能不正确,但感觉我在执行链上还没有那么远。

如果我尝试在调试消息中运行它,我会在 Rider 中收到一条弹出消息,这可能会有所帮助...

Azure Functions host did not return isolated worker process id. Could not attach the debugger. Check the process output for more information.

该函数最初是在 Visual Studio 中创建的,因此我尝试通过在 Rider 中创建一个空的函数应用程序来进行测试来排除任何本地环境差异,并且使用基本的计时器触发器得到了完全相同的结果。

我尝试在函数 root 中创建一个 shell 脚本来运行以下命令并在命令行上执行...

/home/keith/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.72.0/func host start --pause-on-error --verbose

这确实有效,这表明骑手方面有些问题。

c# docker azure-functions rider azurite
1个回答
0
投票

我相信我已经找到了 Rider 无法启动功能的根本原因(双关语不是故意的)。

如果我使用

sudo
而不是我自己在命令行上执行,那么我会得到同样的错误。

sudo /home/{myname}/.AzureToolsForIntelliJ/AzureFunctionsCoreTools/v4/4.72.0/func host start --pause-on-error --verbose   
[sudo] password for {myname}:         
dotnet sdk is required for dotnet based functions. Please install https://microsoft.com/net
Press any key to continue....

在这种情况下,它不起作用,因为使用

dotnet-install.sh
脚本在我的用户配置文件中为我安装了 dotnet SDK。

Rider 显然试图以提升的权限执行该函数,因为我没有将 dotnet 8 SDK 安装为“机器范围”的东西,所以失败是可以理解的。

sudo dotnet --list-sdks      
sudo: dotnet: command not found

似乎是使用

dotnet-install.sh
脚本出现了问题,或者是默认安装 SDK 的位置出现了问题。我直接安装了 6 和 8 SDK 软件包(这在某些发行版上可能不是一个可行的选择 - 我之前来自 Arch,AUR dotnet 软件包不是最可靠的)...

sudo apt-get install dotnet-sdk-6.0
sudo apt-get install dotnet-sdk-8.0

然后我不得不经历一些奇怪的步骤 - 安装后我在我的主目录中安装了本地用户副本...

dotnet --list-sdks

8.0.203 [/home/{myname}/.dotet/sdk

如果直接运行

sudo
,我有8.0.204,在不同的路径上运行8.0.203。我只是跟进
rm -rf ~/.dotnet
,事情就恢复正常了。

输出看起来更加符合预期:

sudo dotnet --list-sdks

6.0.421 [/usr/share/dotnet/sdk]
8.0.204 [/usr/share/dotnet/sdk]

dotnet --list-sdks

6.0.421 [/usr/share/dotnet/sdk]
8.0.204 [/usr/share/dotnet/sdk]

作为最后的清理工作,我检查了

.zshrc
(或
.bashrc
,具体取决于您选择的 shell)并更新了我的 PATH 设置以指向新路径和根...

export PATH=$PATH:/usr/share/dotnet:/usr/share/dotnet/tools
export DOTNET_ROOT="/usr/share/dotnet"
© www.soinside.com 2019 - 2024. All rights reserved.