C7-Game / Prototype

An early-stage, open-source 4X strategy game
https://c7-game.github.io/
MIT License
34 stars 9 forks source link

Fix the unit tests not compiling with net6.0 #269

Closed QuintillusCFC closed 2 years ago

QuintillusCFC commented 2 years ago

For some reason they need an explicit reference to C7GameData with net6.0, which they didn't with net4.7.2. No idea why that changed, someone at MSFT must have thought it was a good idea.

WildWeazel commented 2 years ago

Are you building with .NET 6? This also worked for me on Linux already...

QuintillusCFC commented 2 years ago

My dotnet --version returns 6.0.201, so I believe I am.

To check, I ran dotnet test from the same command prompt that gave that version, in the engine project. It gave me a warning about how C7Engine is still on net4.7.2 and how that may cause problems:

image

I admit I don't follow why the tests are on net6.0 but everything else is on net472. If I go to dev and change the tests to net472, they work perfectly for me. I see in your commit https://github.com/C7-Game/Prototype/commit/57b5250677e1d416dc267bc410e4034c10f11b62 , you mentioned changing the tests to net6.0 made them pass, but for me they work with net472 and fail with net6.0 (unless I add the changes made here).

(And yes, I do find minor cross-platform or cross-dot-net issues annoying)

QuintillusCFC commented 2 years ago

In the terminal case it makes sense why it works on Linux already but not Windows, the Windows terminal has never been as advanced as the Linux one (though I hear WSL is pretty nice nowadays). In this case though I think the Windows behavior in some ways makes more sense - everything should just work if the framework versions are the same, meaning net472 in this case. So I guess I'm curious what error was being thrown on Linux when the tests were set to net472.

(I'm also very slowly progressing towards getting a working-but-not-super-slow Linux VM up. I've decided my Bionic VM is a lost cause, so I downloaded and installed OpenSUSE. Really I should probably just install it natively on my old 80 GB SSD as I think the VM and modern Linux graphics don't play nice, but I'd need to buy another SATA cable to get that working. At least I'm only using 5 of my 6 SATA ports on the mobo...)

WildWeazel commented 2 years ago

My dotnet --version returns 6.0.201, so I believe I am.

To check, I ran dotnet test from the same command prompt that gave that version, in the engine project. It gave me a warning about how C7Engine is still on net4.7.2 and how that may cause problems:

Interesting... here's what I get on Development. Looks like the same warnings, but no errors. That is indeed annoying.

c7dev@ubuntu:~/workspace/Prototype/C7$ dotnet test
  Determining projects to restore...
/home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj : warning NU1701: Package 'ini-parser 3.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/C7/C7.sln]
/home/c7dev/workspace/Prototype/C7GameDataTests/C7GameDataTests.csproj : warning NU1701: Package 'ini-parser 3.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/C7/C7.sln]
  Restored /home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj (in 185 ms).
  Restored /home/c7dev/workspace/Prototype/_Console/BuildDevSave/BuildDevSave.csproj (in 186 ms).
  Restored /home/c7dev/workspace/Prototype/C7GameData/C7GameData.csproj (in 29 ms).
  Restored /home/c7dev/workspace/Prototype/C7/C7.csproj (in 6 ms).
  Restored /home/c7dev/workspace/Prototype/C7Engine/C7Engine.csproj (in 24 ms).
  Restored /home/c7dev/workspace/Prototype/C7GameDataTests/C7GameDataTests.csproj (in 266 ms).
  Restored /home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj (in 297 ms).
  2 of 9 projects are up-to-date for restore.
/home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj : warning NU1701: Package 'ini-parser 3.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
/home/c7dev/workspace/Prototype/C7GameDataTests/C7GameDataTests.csproj : warning NU1701: Package 'ini-parser 3.4.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework 'net6.0'. This package may not be fully compatible with your project.
/usr/share/dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1806,5): warning NU1702: ProjectReference '/home/c7dev/workspace/Prototype/C7GameData/C7GameData.csproj' was resolved using '.NETFramework,Version=v4.7.2' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/C7GameDataTests/C7GameDataTests.csproj]
/usr/share/dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1806,5): warning NU1702: ProjectReference '/home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj' was resolved using '.NETFramework,Version=v4.7.2' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/C7GameDataTests/C7GameDataTests.csproj]
  Blast -> /home/c7dev/workspace/Prototype/Blast/bin/Debug/netstandard2.0/Blast.dll
/usr/share/dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1806,5): warning NU1702: ProjectReference '/home/c7dev/workspace/Prototype/C7Engine/C7Engine.csproj' was resolved using '.NETFramework,Version=v4.7.2' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj]
/usr/share/dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1806,5): warning NU1702: ProjectReference '/home/c7dev/workspace/Prototype/C7GameData/C7GameData.csproj' was resolved using '.NETFramework,Version=v4.7.2' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj]
/usr/share/dotnet/sdk/6.0.300/Microsoft.Common.CurrentVersion.targets(1806,5): warning NU1702: ProjectReference '/home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj' was resolved using '.NETFramework,Version=v4.7.2' instead of the project target framework '.NETCoreApp,Version=v6.0'. This project may not be fully compatible with your project. [/home/c7dev/workspace/Prototype/EngineTests/EngineTests.csproj]
/home/c7dev/workspace/Prototype/QueryCiv3/Biq.cs(542,29): warning CS0162: Unreachable code detected [/home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj]
/home/c7dev/workspace/Prototype/QueryCiv3/Util.cs(15,21): warning CS0649: Field 'IntBitmap.Flags' is never assigned to, and will always have its default value 0 [/home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj]
/home/c7dev/workspace/Prototype/QueryCiv3/Util.cs(10,22): warning CS0649: Field 'ByteBitmap.Flags' is never assigned to, and will always have its default value 0 [/home/c7dev/workspace/Prototype/QueryCiv3/QueryCiv3.csproj]
  QueryCiv3 -> /home/c7dev/workspace/Prototype/QueryCiv3/bin/Debug/net472/QueryCiv3.dll
  C7GameData -> /home/c7dev/workspace/Prototype/C7GameData/bin/Debug/net472/C7GameData.dll
/home/c7dev/workspace/Prototype/C7Engine/C7Settings.cs(17,27): warning CS0168: The variable 'ex' is declared but never used [/home/c7dev/workspace/Prototype/C7Engine/C7Engine.csproj]
  C7Engine -> /home/c7dev/workspace/Prototype/C7Engine/bin/Debug/net472/C7Engine.dll
  C7GameDataTests -> /home/c7dev/workspace/Prototype/C7GameDataTests/bin/Debug/net6.0/C7GameDataTests.dll
Test run for /home/c7dev/workspace/Prototype/C7GameDataTests/bin/Debug/net6.0/C7GameDataTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     2, Skipped:     0, Total:     2, Duration: 3 ms - /home/c7dev/workspace/Prototype/C7GameDataTests/bin/Debug/net6.0/C7GameDataTests.dll (net6.0)
  EngineTests -> /home/c7dev/workspace/Prototype/EngineTests/bin/Debug/net6.0/EngineTests.dll
Test run for /home/c7dev/workspace/Prototype/EngineTests/bin/Debug/net6.0/EngineTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.2.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: < 1 ms - /home/c7dev/workspace/Prototype/EngineTests/bin/Debug/net6.0/EngineTests.dll (net6.0)
c7dev@ubuntu:~/workspace/Prototype/C7$ dotnet --version
6.0.300

Don't spend too much time on a Linux VM if it's just for this project. I started a new one with 22.04 LTS that I'm setting up with our dependencies so all you have to do is enter your credentials and check out.

QuintillusCFC commented 2 years ago

Huh, I agree, those are the same warnings, but without causing an error. :dunno: I think I'd rather add logging to all projects than figure out the root cause of that difference, though.

Thanks for the Linux VM reminder, that would save some time, and it was pretty much just for this project. I think my machine's getting old; back in the day it would run any old Linux VM well, now it likes XFCE but isn't so snappy elsewhere. Maybe 22.04 will be better than 18.04 though.