25
votes

I notice when I start up Visual Studio 2019, I am unable to create a .NET Framework version of XUnit or NUnit (only MSTests). We have been mandated to use XUnit tests, but our solution is all .NET Framework. Some of the nuget packages are dependent on being .NET Framework (for Sitecore 8.2) and thus I can't add them to a .NET Core project. I cannot upgrade any of the legacy project to .NET Core or to Sitecore 9+ at this time.

How do I add in a .NET Framework XUnit project? Is there something wrong with my Visual Studio setup? Is it not supported? I have been unable to find documentation from Microsoft about this. Thanks.

2
Just create a library project. Please refer to xUnit's own docs - xunit.net/docs/getting-started/netfx/visual-studioStephen Kennedy
Matt's approach is probably easier :)Stephen Kennedy
Was still a good suggestion. :)Matt Johnson-Pint
Actually, it turns out that Matt's suggestion did not work for me; I had to create a Class Library project as the docs (and @StephenKennedy) suggested. FWIW I had a requirement to target .NET Framework 4.5.2.Vince I
@StephenKennedy i suggest you make your comment an answer. It is my prefered solution to the problem/question.LosManos

2 Answers

30
votes
  • First use the xUnit Test Project (.NET Core) project template.

  • Then go edit the .csproj file and change <TargetFramework>netcoreapp2.2</TargetFramework> to <TargetFramework>net462</TargetFramework>.

  • That's it. :)

5
votes
  • Install the xUnit Test Project Template for .net framework from here.
  • Create a new xUnit Test Project (.NET Framework) project enter image description here