Godot: Build Does Not Detect C# Extensions (or any .cs files that do not contain nodes)

Created on 22 Dec 2017  路  11Comments  路  Source: godotengine/godot

Godot version:
3.0 beta 2

OS/device including version:
Windows

Issue description:
When you make an extension method in another .cs class, build fails because it cannot find the extension you are attempting to reference.

Steps to reproduce:

  1. Create a .cs file with an extension to any node or whatever.
  2. In a node script, reference the extension. Note that VS Code sees this as valid.
  3. In the editor, play the game.

EDIT: I did more research and it looks like that Godot neglects to include .cs files in the solution that do not contain nodes. This is undesirable.

bug mono

Most helpful comment

I can't say I've tested this, but a workaround for this, although kinda hacky, is to add the following line before the </Project> in your .csproj file:

<ItemGroup>
  <Compile="**\*.cs" />
</ItemGroup>

This should make msbuild automatically compile all .cs files without having to manually add them to the .csproj, so kinda like a .NET Core project.

You can also Make it only do specific directories by making <Compile> entries for specific folders, probably: <Compile="src\**\*.cs" />

All 11 comments

I assume you created it from VS Code, which does not update the csproj. Godot cannot assume the file is part of the game csproj (you could have other C# projects). Godot only makes this assumption when creating the script from the Godot editor, when the script is attached to a node and when the script is used as an AutoLoad (this last one is pending :smile:).

You must either create the script from Godot or use an IDE like MonoDevelop or Visual Studio. _EDIT: Found this VS Code extension: https://marketplace.visualstudio.com/items?itemName=lucasazzola.vscode-csproj_

BTW, I plan to add a panel to view and edit includes and references in the game project, in order to make it friendlier than editing the project file. This will happen after 3.0 though.

We have now entered release freeze for Godot 3.0 and want to focus only on release critical issues for that milestone. Therefore, we're moving this issue to the 3.1 milestone, though a fix may be made available for a 3.0.x maintenance release after it has been tested in the master branch during 3.1 development. If you consider that this issue is critical enough to warrant blocking the 3.0 release until fixed, please comment so that we can assess it more in-depth.

The VS code extension is a decent workaround until then, although not perfect. I can wait.

Are there any updates on this issue?

@neikeq can you update the title of this issue to reflect the actual issue since c# extensions actually work fine with godot. This is a file being included in the csproj file issue w/ vscode/godot editor. Which is a non issue in most IDE's.

I can't say I've tested this, but a workaround for this, although kinda hacky, is to add the following line before the </Project> in your .csproj file:

<ItemGroup>
  <Compile="**\*.cs" />
</ItemGroup>

This should make msbuild automatically compile all .cs files without having to manually add them to the .csproj, so kinda like a .NET Core project.

You can also Make it only do specific directories by making <Compile> entries for specific folders, probably: <Compile="src\**\*.cs" />

I guess the best will be to watch the project directory for source files added or removed outside the Godot editor and show a dialog asking for confirmation from the user to apply these actions to the project.

Related to #12917.

Might be worth adding some sort of Godot option to generate the csproj with the wildcard to grab all C# files. I know i've been struggling with my csproj sometimes missing files, i'd have certainly opted for something more automated if given the option.

Unity does that thing where it rebuilds the csproj when it detects a new script in the project dir, maybe Godot doesn't need to go that far though.

I can't say I've tested this, but a workaround for this, although kinda hacky, is to add the following line before the </Project> in your .csproj file:

<ItemGroup>
  <Compile="**\*.cs" />
</ItemGroup>

This should make msbuild automatically compile all .cs files without having to manually add them to the .csproj, so kinda like a .NET Core project.

You can also Make it only do specific directories by making <Compile> entries for specific folders, probably: <Compile="src\**\*.cs" />

Worked great for me :) But had to change it to following to get the project to compile.

<ItemGroup>
    <Compile Include="**\*.cs" />
</ItemGroup>

Please re-test with Godot 3.2.3 and/or the master branch. Both of these use the new C# project format, so issues related to the csproj file might just not exist anymore. Also, check if you have the latest Mono and .NET Core.

As of Godot 3.2.3, using this as your csproj should automatically include every C# file:

<Project Sdk="Godot.NET.Sdk/3.2.3">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
  </PropertyGroup>
</Project>

If this issue does still exist for you, then you will need to include a minimal reproduction project.

Was this page helpful?
0 / 5 - 0 ratings