gpt4 book ai didi

c# - 引用多个 C# 项目时 Firebase 函数构建错误

转载 作者:行者123 更新时间:2023-12-02 18:37:44 25 4
gpt4 key购买 nike

我能够毫无问题地部署我的 firebase c# 函数,但是,当我引用另一个 c# 项目以便我可以利用另一个对象时,我收到错误消息,指出项目不存在。

因此能够毫无问题地部署以下内容:

namespace CloudFunctions
{
public class Login : IHttpFunction
{
public async Task HandleAsync(HttpContext context) {
await context.Response.WriteAsync("Hello World!");
}
}
}

此类位于一个名为 CloudFunctions 的项目中。我添加了对名为 Services 的项目的项目引用,以便我可以调用登录服务,但出现以下错误:

The referenced project '../Services/Services.csproj' does not exist

这就是我的部署方式:

gcloud functions deploy login --entry-point CloudFunctions.Login --runtime dotnet3 --trigger-http --allow-unauthenticated

我无法想象我们需要将所有内容都放在一个项目中才能进行部署?

最佳答案

您需要使所有项目可供构建包使用(即从父目录部署),但也使用 GOOGLE_BUILDABLE 指定包含入口点的项目。构建时环境变量。

来自deployment documentation in the Functions Framework GitHub repo :

Real world functions are often part of a larger application which will usually contain common code for data types and common business logic. If your function depends on another project via a local project reference (a <ProjectReference> element in your .csproj file), the source code for that project must also be included when deploying to Google Cloud Functions. Additionally, you need to specify which project contains the function you wish to deploy.

In a typical directory structure where all projects sit side-by-side within one top-level directory, this will mean you need to deploy from that top-level directory instead of from the function's project directory. You also need to use the --set-build-env-vars command line flag to specify the GOOGLE_BUILDABLE build-time environment variable. This tells the Google Cloud Functions deployment process which project to build and deploy. Note that the GOOGLE_BUILDABLE environment variable value is case-sensitive, and should match the directory and file names used.

When deploying a function with multiple projects, it's important to make sure you have a suitable .gcloudignore file, so that you only upload the code that you want to. In particular, you should almost always include bin/ and obj/ in the .gcloudignore file so that you don't upload your locally-built binaries.

来自 examples 的示例部署命令行目录:

gcloud functions deploy multi-project \
--runtime dotnet3 \
--trigger-http \
--entry-point=Google.Cloud.Functions.Examples.MultiProjectFunction.Function \
--set-build-env-vars=GOOGLE_BUILDABLE=Google.Cloud.Functions.Examples.MultiProjectFunction

关于c# - 引用多个 C# 项目时 Firebase 函数构建错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68523074/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com