- Visual Studio .NET
- VS.NET General Discussion
- Thread starteraaaron123
- Start dateJan 14, 2021
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 14, 2021
- #1
I'm trying Net 5 carefully.
I created a Windows Forms App solution with the main form
Added a Net Core Class Library project to use as a multiuse library
I'd like to add a project with the sole purpose of creating a UserControl that can be used by multiple forms.
When I do an Add New Project I can't find anything to create a UserControl.
Last edited:
Solution
J
- J
jmcilhinney
- Jan 14, 2021
WinForms support in .NET 5.0 is still a bit rough around the edges. There's no Windows Control Library project template like there is for .NET Framework. I just created a C# Class Library (.NET Core) project and then edited the project file from this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup></Project>
to this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net5.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup></Project>
After building, I was then able to right-click the project in the Solution Explorer and add a user control.
Sort by dateSort by votes
Skydiver
Staff member
- Joined
- Apr 6, 2019
- Messages
- 8,067
- Location
- Chesapeake, VA
- Programming Experience
- 10+
- Jan 14, 2021
- #2
You can add a new project that is a library type. Within that project, you can then add a user control.
Upvote0Downvote
J
jmcilhinney
C# Forum Moderator
Staff member
- Joined
- Apr 23, 2011
- Messages
- 5,349
- Location
- Sydney, Australia
- Programming Experience
- 10+
- Jan 14, 2021
- #3
WinForms support in .NET 5.0 is still a bit rough around the edges. There's no Windows Control Library project template like there is for .NET Framework. I just created a C# Class Library (.NET Core) project and then edited the project file from this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup></Project>
to this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net5.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup></Project>
After building, I was then able to right-click the project in the Solution Explorer and add a user control.
Upvote1Downvote
Solution
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 14, 2021
- #4
Skydiver said:
You can add a new project that is a library type. Within that project, you can then add a user control.
I know it has to be simple but I added a class library and then tried add new item to it but could not find the correct item to add.
Upvote0Downvote
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 15, 2021
- #5
jmcilhinney said:
WinForms support in .NET 5.0 is still a bit rough around the edges. There's no Windows Control Library project template like there is for .NET Framework. I just created a C# Class Library (.NET Core) project and then edited the project file from this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup></Project>
to this:
XML:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net5.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> </PropertyGroup></Project>
After building, I was then able to right-click the project in the Solution Explorer and add a user control.
What does <UseWindowsForms>true</UseWindowsForms> do.
Trying Net 5 I could not get System.Windows.Forms to register correctly.
Tried adding that and it seems to fix it. Why?
Upvote0Downvote
J
jmcilhinney
C# Forum Moderator
Staff member
- Joined
- Apr 23, 2011
- Messages
- 5,349
- Location
- Sydney, Australia
- Programming Experience
- 10+
- Jan 15, 2021
- #6
Look at the project in the Solution Explorer thoroughly before and after and you'll see what the difference is.
Upvote0Downvote
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 15, 2021
- #7
jmcilhinney said:
Look at the project in the Solution Explorer thoroughly before and after and you'll see what the difference is.
'Adding <UseWindowsForms>true</UseWindowsForms> to the <PropertyGroup> added the dependencies
'C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\5.0.0\
I looked in that folder. Is that something special for Net 5 or has that always been there.
Just curious. What is it?
Is it something that I might not need after Net 5 get more mature?
Can I add a comment to the project file that the system will ignore?
Upvote0Downvote
J
jmcilhinney
C# Forum Moderator
Staff member
- Joined
- Apr 23, 2011
- Messages
- 5,349
- Location
- Sydney, Australia
- Programming Experience
- 10+
- Jan 15, 2021
- #8
It's the directive that tells the IDE to include the WinForms package for .NET 5. I expect that you'll always need it, but the hope would be that they add a project template that does it for you, just as they have with the WinForms application project. I worked out that you could get a class library to work by examining an application project and seeing what was different, then experimenting.
By the way, you can create your own project templates if you want to. I haven't done it for a long time so can't remember the details, which may have changed since I last did it anyway. Basically, you create a project from an existing template, make the changes you want and then export it as a template. If this is a project type you might need again, maybe you should research how exactly to do that.
Upvote0Downvote
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 16, 2021
- #9
jmcilhinney said:
WinForms package for .NET 5. I expect that you'll always need itt.
Good, I don't need to make a note to check this ocassionally.
Thanks - to bad there can only be one reply marked as solution.
Upvote0Downvote
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 16, 2021
- #10
MSB3290 Failed to create the wrapper assembly for type library "{215d64d2-031c-33c7-96e3-61794cd1ee61}". Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be re-imported as a CLR assembly. LibraryNative0 C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets
I'm converting a class library and cleaned up all errors except the above, which I can find no reference to. Can you tell me the kind of thing I should look for in my code.
Upvote0Downvote
J
jmcilhinney
C# Forum Moderator
Staff member
- Joined
- Apr 23, 2011
- Messages
- 5,349
- Location
- Sydney, Australia
- Programming Experience
- 10+
- Jan 16, 2021
- #11
The obvious first step is to search for the error code and find out what it means and what existing solutions there may be.
Upvote0Downvote
A
aaaron123
Member
- Joined
- Jan 3, 2021
- Messages
- 18
- Programming Experience
- 1-3
- Jan 16, 2021
- #12
jmcilhinney said:
The obvious first step is to search for the error code and find out what it means and what existing solutions there may be.
Naturally, I did, and only got some general suggestion to use community.
I'll try again but I already di a few times.
Edit: I really did not search - I clicked the error message in the error list and thought the was equivalent. Guess not.
If that's the problem, how can I possibly get around it. I need 'tom"
I'll try again to add a reference and see if that helps'
It did not work the first time because I selected the reference rather than checking it - so it really did not get added.
Thanks for the quick reply.
Last edited:
Upvote0Downvote
Similar threads
- Question
QuestionDelay in inserting images in UserControl displayed in TabItem
- Elad Yehuda
- Mar 5, 2024
- Windows Presentation Foundation (WPF)
- Replies
- 1
- Views
- 549
Mar 5, 2024
Skydiver
- Question
How can I remove a git and github repository connection to a solution in Visual Studio 2022?
- complete
- Jul 18, 2024
- Third Party Products
- Replies
- 1
- Views
- 171
Jul 18, 2024
Skydiver
J
- Question
QuestionIs this the best way to implement multi-lingual into a large application?
- jackrabbit
- Jul 8, 2024
- Localization and i18n (Internationalization)
- Replies
- 3
- Views
- 470
Jul 9, 2024
Skydiver
P
- Question
QuestionSet up MudBlazor for Blazor Wep App in .Net 8
- Pablo
- Jul 6, 2024
- ASP.NET Core, Razor, and Blazor
- Replies
- 2
- Views
- 206
Jul 6, 2024
Skydiver
- Question
Windows Form project Deployment with WebView2
- philip
- Mar 27, 2024
- Deployment
- Replies
- 4
- Views
- 523
Mar 31, 2024
philip
Share this page
Latest posts
How to open web form web sites
- Latest: SaeedP
Web Forms
Read last 6 bytes
- Latest: Skydiver
C# General Discussion
P
WNetAddConnection2 failure exit
- Latest: patrick
C# General Discussion
P
TaskDefinition Run whether user is logged on or not C#
- Latest: patrick
C# General Discussion
Resolveddraw string
- Latest: Skydiver
Windows Forms
- Visual Studio .NET
- VS.NET General Discussion