User control with test project will not build (framework and netcore mismatch?)

iLens 6 Reputation points
2022-05-04T10:30:16.467+00:00

I am using VS 2019 to create a user control and a test project, but the resulting soluton fails to build with the message..
Project '..\xxx.vbproj' targets 'netcoreapp3.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.7.2'.

This is how I created the solution...

  1. open Visual Studio
  2. click "new project"
  3. select "Windows Forms Control library" (Visual Basic)
  4. click "Next" and select a name (HTMLeditor) and location - click "Create"
  5. accept the default of ".net core 3.1 (Long-term support)"
  6. drag a Button control onto the control surface
  7. build solution(successfully)
  8. right-click the solution and select "Add" and "New project"
  9. select "Windows Forms App (.Net Framework)" 10. click "Next" and select a name (HTMLeditor_Testing) and location
    accept the default of ".NET framework 4.7.2" - click "Create" 11. build solution(successfully) 12. right-click on "References" in "HTMLeditor_Testing" project in Solution Explorer and select "Add reference" 13. select "Projects" and "Solution" and select "HTMLeditor" - click "OK" 14. build solution - get
    Project '..\HTMLEditor\HTMLEditor.vbproj' targets 'netcoreapp3.1'. It cannot be referenced by a project that targets '.NETFramework,Version=v4.7.2'. HTMLeditor_Testing

What am I doing wrong?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,659 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 114.5K Reputation points
    2022-05-04T11:09:19.163+00:00

    Try a "Windows Forms App" instead of "Windows Forms App (.NET Framework)".

    Or create a "Windows Forms Control Library (.NET Framework)" instead of "Windows Forms Control Library".

    0 comments No comments

  2. Jiachen Li-MSFT 28,941 Reputation points Microsoft Vendor
    2022-05-18T06:07:56.293+00:00

    Hi @iLens ,
    You need to make sure that the created project is Windows Forms Control library and Windows Forms App.
    Or Windows Forms Control library (.net framework) and Windows Forms App (.net framework).
    Mismatched frameworks will cause the error you're getting.
    Best Regards.
    Jiachen Li

    ----------

    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments