31

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.

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
Ross Gustafson
  • 1,182
  • 3
  • 16
  • 32

2 Answers2

40
  • 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. :)

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
  • 2
    Nice workaround, I miss the old-fashioned, "just pick this option when creating the project". – Vince I Jan 03 '20 at 16:40
  • 1
    An official list of target framework monikers is available [here](https://learn.microsoft.com/en-us/dotnet/standard/frameworks) – AJ Dhaliwal Jun 28 '21 at 09:37
10
  • Install the xUnit Test Project Template for .net framework from here.
  • Create a new xUnit Test Project (.NET Framework) project enter image description here
Frank Liu
  • 1,466
  • 3
  • 23
  • 36
  • This is the real answer as of today. No hack required like editing the project file. – RBT Jan 20 '23 at 08:45
  • 1
    @RBT, I don't consider a hack, I believe installing a special template for an older tech, that is not easily upgradable, is more of a hack. This is coming from someone who still works with 4.8 and appreciates the Framework support in most of the new DotNet ecosystem. – MarcWeintraub Jun 06 '23 at 17:57