Unit Test for .NET 5 Windows Forms?

Nicholas Piazza 546 Reputation points
2021-04-05T19:34:05.647+00:00

I recently converted a Windows Forms solution/project to .NET 5 using the try-convert application. The application builds and runs just fine. However, I tried adding a unit test project to the solution. In Solution Explorer, when I go into the unit test project Dependencies node and try to add a reference to the project I wish to test, it doesn't seem to work. The referenced project shows up with a yellow warning symbol and if I try to rebuild the solution, there are errors that show up in the unit test project saying the project I am referencing is not compatible with the unit test project. Has unit testing in Visual Studio 2019 not yet caught up to being compatible with .NET 5 Windows Forms projects? Any ideas about this problem?

Developer technologies | C#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Karen Payne MVP 35,596 Reputation points Volunteer Moderator
    2021-04-05T21:22:05.377+00:00

    A decent alternative to what you are doing now but make a project template. Templates can be test project, class projects etc.

    • Create a new project e.g. test project
    • Alter the project file alter the project file (as you are doing now) and if using C# 9 use this
    • From Visual Studio's menu select Project,
    • Select Export Template
    • Follow the prompts to export a project
    • Select the project
    • Fill in the default name for a project
    • Fill in a description
    • Finish up
    • Restart Visual Studio

    The following is one of my .NET 5/C# templates (works no different for a test project)
    Type in the name of the template e.g. my template for a class project for .NET 5 is PayneClassProject
    84618-f1.png

    Give a name for the project, done,

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.