Open PerMalmberg opened 9 months ago
I don't think Godot API works with the C# test frameworks. But this warning can be resolved by adding
<PropertyGroup>
<IsGodotToolsProject>true</IsGodotToolsProject>
</PropertyGroup>
To the Testing Csproj file, this disables the ScriptPathAttributeGenerator
and GodotPluginsInitializerGenerator
which can be useful when you are creating a separate library.
I'm using GDUnit4 for unit testing.
No, it might not and probably isn't intended to for good reasons. As such the generator should not run in the Test-project, or at least not emit errors.
Thanks for a possible workaround to use until a proper fix is in place, @Delsin-Yu
EDIT: did them on Godot 4.3 and Linux.
I checked the .csproj
files and noticed something, might not be as important but maybe it's a clue. There's a bunch of mismatching .NET versions:
PubSub.csproj
<Project Sdk="Godot.NET.Sdk/4.2.1">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'android' ">net7.0</TargetFramework>
<TargetFramework Condition=" '$(GodotTargetPlatform)' == 'ios' ">net8.0</TargetFramework>
<EnableDynamicLoading>true</EnableDynamicLoading>
</PropertyGroup>
</Project>
Test.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.2.0" />
<PackageReference Include="MSTest.TestFramework" Version="3.2.0" />
<PackageReference Include="coverlet.collector" Version="6.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\PubSub\PubSub.csproj" />
</ItemGroup>
</Project>
Also, I've had this experience with testing suites (and with experience gathered from @chickensoft-games testing rigs), so I added this line to the files:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
and...
at the second build it compiled.
So... try doing it twice. Here's the folder with the compiled builds. Took the precaution of doing a dotnet clean
in between. Same behaviour. Here's the project files with the compiled .dll
files so you can check for yourself. I did compile on Linux, so your mileage may vary a lot.
.NET 8.0 repro_8.0.zip
.NET 9.0 repro_9.0.zip
Tested versions
VStudio version:
System information
Godot v4.2.1.stable.mono - Windows 10.0.22631 - Vulkan (Mobile) - dedicated NVIDIA GeForce RTX 2070 SUPER (NVIDIA; 31.0.15.4617) - AMD Ryzen 7 3800XT 8-Core Processor (16 Threads)
Issue description
When adding an MSTest project to a C# solution/project created by Godot, the following error message is written to the output window when compiling the test project:
Generator 'ScriptPathAttributeGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidOperationException' with message 'Property 'GodotProjectDir' is null or empty.'
I've seen this in projects with actual content but not seen any actual issues coming from it.
Full output:
Steps to reproduce
Simply compile the attached solution.
Minimal reproduction project (MRP)
repro.zip