无法构建 Godot mono 项目“命名空间名称‘Godot’”找不到”

发布于 2025-01-15 04:51:21 字数 328 浏览 1 评论 0原文

我正在尝试构建一个 Godot mono 项目,该项目是我刚刚从我的存储库中克隆的,可以在我的另一台机器上运行。

当我尝试在 Visual Studio 中构建时,出现错误,

 error CS0246: The type or namespace name 'Godot' could not be found (are you missing a using directive or an assembly reference?)

我可以通过在 Godot 中创建一个基本的空场景项目并在 Visual Studio 中打开新解决方案并尝试构建来复制此错误。

I'm trying to build a Godot mono project that I've just cloned from my repo that works on my other machine.

When I try to build in Visual Studio I get the error

 error CS0246: The type or namespace name 'Godot' could not be found (are you missing a using directive or an assembly reference?)

I can replicate this by creating a basic empty scene project in Godot and opening the new solution in Visual Studio and trying to build.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2025-01-22 04:51:21

在以下几种情况下,可能会出现此问题:

  • 从项目在其他地方构建但在这台新机器上没有构建的存储库进行克隆
  • 尝试新的 IDE:Visual Studio、Rider、VS Code
  • 新团队成员加入
  • 在持续集成系统上

解决方案位于 KellyThomas 对 Github 问题的回复 此处

godot mono 程序集放置在您的项目中
构建过程中的 .mono/assemblies 目录
项目。

场景(播放按钮位于 godot 窗口的左上角)或
单击单声道面板上的构建按钮(与输出、调试器等位于同一堆栈的中心底部)。

  1. 运行您的项目/场景(播放按钮位于
    戈多窗口)或
  2. 单击单声道面板上的构建按钮(与输出、调试器等位于同一堆栈的中心底部)。

因此,项目未构建的原因是您的 IDE 或构建系统没有所需的 dll,当您从那里运行构建时,通常由 Godot 程序本身将其放置在那里。

对于本地开发机器,解决方案是在 Godot 中构建或运行项目一次,它将把 dll 放置在正确的文件夹中,该文件夹将保留允许其他应用程序(即 Visual Studio 或 Rider)创建构建(如果您使用 Rider) Godot 插件我相信它会为你创建 dll)。

方法有点不同,因为我们每次都从头开始,当我们可以使用 MSBuild 之类的东西时,我们不一定要运行 Godot Build。

我的解决方案是在工作目录之外存储所需 DLL 的副本,并在运行 MSBuild 步骤之前将其复制到构建文件夹中。

在撰写本文时,构建 Godot 3.4.4 Mono 项目所需的 DLL 是 GodotSharp.dll。我怀疑每次升级 Godot 时你都必须复制这个 DLL 的新版本。

手动构建一次 Godot 项目来生成 DLL(基本的 hello world 就可以了)。在 Godot 应用程序中构建项目后,DLL 存储在项目的解决方案文件 (.sln) 旁边的文件夹中。该文件夹取决于您的构建的配置。

.mono/assemblies/Debug
.mono/assemblies/Release

在 OSX 中,.mono 文件夹是隐藏的,按 cmd + shift + . 可在查找器中查看该文件夹。

这就是我使用 yaml 管道将文件复制到 Azure Devops 上正确文件夹的方法。

- task: CopyFiles@2
      inputs:
        SourceFolder: $(Agent.BuildDirectory)/GodotDlls/3.4.3
        Contents: '**'
        TargetFolder: $(binariesPath)/.mono/assemblies/Release

There are a few scenarios where this issue can present itself:

  • Cloning from a repo where the project builds elsewhere but on this new machine it doesn't
  • Trying a new IDE: Visual Studio, Rider, VS Code
  • New team members joining
  • On continuous integration systems

The solution is in a response from KellyThomas on a Github issue here

The godot mono assemblies are placed in your project's
.mono/assemblies directory during the process of building your
project.

scene (play buttons are in top left corner of the godot window) or
clicking the build button on the mono panel (center-bottom in the same stack as output, debugger etc).

  1. running your project / scene (play buttons are in top left corner of
    the godot window) or
  2. clicking the build button on the mono panel (center-bottom in the same stack as output, debugger etc).

So the reason the project isn't building is that your IDE or build system doesn't have the required dll that is normally put there by the Godot program itself when you run a build from there.

For a local Dev machine the solution is to build or run the project in Godot once and it will place the dll in the correct folder where it will remain allowing builds to be created by other applications ie Visual Studio or Rider(if you use the Rider plugin for Godot I believe it will create the dll for you).

lovely red circles

On a CI the approach is a bit different as we're starting fresh every time and we don't necessarily want to run Godot Build when we can use something like MSBuild.

My solution to this is to store a copy of the required DLL outside the working directory and copy it to the build folder before the MSBuild step is run.

The required DLL for building Godot 3.4.4 Mono projects at the time of writing is GodotSharp.dll. I suspect you will have to copy a new version of this DLL every time you upgrade Godot.

Do a manual one time build of a Godot project to generate the DLL (basic hello world is fine). After building the project in the Godot Application the DLL is stored in a folder next to the solution file (.sln) for the project. The folder depends on the configuration of your build.

.mono/assemblies/Debug
.mono/assemblies/Release

In OSX the .mono folder is hidden, press cmd + shift + . to see the folder in the finder.

This is how I get the file copied to the correct folder on Azure Devops using a yaml pipeline.

- task: CopyFiles@2
      inputs:
        SourceFolder: $(Agent.BuildDirectory)/GodotDlls/3.4.3
        Contents: '**'
        TargetFolder: $(binariesPath)/.mono/assemblies/Release
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文