Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add netstandard2.0 support to allow using Testura.Code within a Roslyn source generator project #112

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

asyncmeow
Copy link

@asyncmeow asyncmeow commented May 6, 2024

I'm working on making some source generators I use in my own projects into it's own project, later to be published on NuGet, and I saw this project while I was cleaning up the code a bit and looking for a way to make my code generation a bit nicer. I decided to try and port this project to the .NET version required for source generators.

  • Add netstandard2.0 target to Testura.Code and Testura.Code.Tests
  • Add PolySharp dependency to Testura.Code to polyfill features from newer C# versions into netstandard2.0 builds
    • This is a source generator only dependency, so it should not be a transitive dependency pulled in by projects depending on Testura.Code, and the source generator only adds code when targeting newer C# versions with older target frameworks.
  • Fix code that relies on non-polyfilled C# features within Testura.Code until the project builds
  • Make test project build
  • Make sure tests succeed

Will update in comments on my current progress so far on this.

@asyncmeow
Copy link
Author

Current progress on getting tests to build - the NUnit3TestAdapter project is being restored using .NETFramework4.x.x packages, instead of any specific netstandard2.0 packages. Looking into finding a solution for this.

1>Testura.Code.Tests.csproj: Error NU1701 : Warning As Error: Package 'NUnit3TestAdapter 4.3.1' 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, .NETFramework,Version=v4.8.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project.

…` to build test project against new `Testura.Code` target framework
@asyncmeow
Copy link
Author

asyncmeow commented May 6, 2024

So, I have the tests building with my change now, but I cannot actually run them - even on unmodified sources from this repository instead of my fork, the tests don't pass. At a glance, it looks like your tests don't actually support running on non-Windows systems, and my primary development system is a MacOS system. Specifically, I get errors like this from the failing tests that I looked at briefly:

System.IO.FileNotFoundException : Could not find a part of the path '/Users/pearl/code/Testura.Code/src/Testura.Code.Tests/bin/Debug/net6.0/C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\/mscorlib.dll'.

which seems to be a mix of a MacOS and a Windows path.

Would one of you guys be able to run the unit tests for me and let me know if all of the tests pass? Keep in mind that I'm not sure if Visual Studio actually supports running anything except the newest framework version's tests natively - you may have to use the dotnet test command line tool to run it. I usually handle running tests on multi-targeted projects by running them in JetBrains Rider, which has a dropdown to select which target frameworks to run a test for.

@asyncmeow
Copy link
Author

After running the tests on another machine and finding out it hard-requires .net 4.5, I'm skipping the tests and marking the PR as ready for review, since there's no reasonable way to run the tests as the tests require a long-unsupported .NET version to run.

@asyncmeow asyncmeow marked this pull request as ready for review May 6, 2024 20:29
@asyncmeow asyncmeow changed the title [WIP] Add netstandard2.0 support to allow using Testura.Code within a Roslyn source generator project Add netstandard2.0 support to allow using Testura.Code within a Roslyn source generator project May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant