Cannot add my user control to the toolbox from DLL file - visual-studio

I created a custom WinForms control. When I added reference to the control's project for any project in the same solution, the control appeared in a WinForms designer toolbox and I can use it.
But I have problem to use it as an external library.
I built it and got a DLL file. When I add reference to the DLL file for a project, the control doesn't show in the toolbox. I tried also add it by "right click toolbox => choose items...", but I have an error: "'path to dll' targets a platform whose toolbox items cannot be enumerated dynamically".
Visual Studio 2022 Community .Net 6

I found the "answer" here: link
The only solution is workaround: Putting your controls in a NuGet package and referencing that

Related

Can I make a windows form application in Microsoft Visual Studio Express 2013 Windows 8?

Seems likely that I am not able to create a windows form application using the Microsoft Visual Studio Express 2013 under Windows 8. The default templaters are only for creating apps rather than traditional normal windowed applications.
Is there any way I could find the template or find a solution?
Thanks.
You cannot.
Download Microsoft Visual Studio 2013 Express for Windows Desktop instead.
Link for online installer
Link for ISO file
Visual Studio download page
Actually yes, you can do that manually, by adding the references to the project (System.Windows.Forms) and changing the output type in the properties of the project, and adding classes - you have to manually do the whole thing..
To Expand RobDev's answer, you can actually do this. I will show you an example of how to do this in Visual Studio Express 2015 for Web, probably same applies for 2013 version.
Steps.:
Create an empty solution
Create a .dll library project
Change output in project properties to Windows Application. To do so, right click on the new added project and pick "Properties". There, you can change "Output Type" dropdown in Application tab.
Add a reference to System.Windows.Forms to your project (by right-clicking => Add Reference to your Reference option under your project)
Set the project to Startup Project, by right-clicking the project and choosing "Set up as Startup Project"
add a main method to the generated class (you can rename it to Main). It will need this code to start.
using System.Windows.Forms;
namespace ClassLibrary1
{
public class Class1
{
public static void Main()
{
Application.Run(new Form());
}
}
}
and voila! That will create a new fresh Form. You could use a starting point whatever form you want. To do so, add a new .cs class and make it inherit from Form class.
The toolbox to customize forms is available at View => Toolbox menu.

How do I put a dll into my project - visual studio C# 2010

I need to put a dll file into my project, my notes say simply drag the dll into the toolbox but it doesn't seem to be working.
How do i do this?
thanks.
You use the "References" item in the Solution Explorer to add a reference to it; Right-click and choose to Add Reference. There is an option there to select the DLL file.
When you do this, by default the DLL is copied and included in the project's output, which is what you usually want for a .NET Assembly, anyway.
Which reminds me to ask to make sure; Are you talking about a .NET Assembly DLL here? Things could be quite different if you mean a native code DLL.
Put the DLL into the root of your ASP.NET project, then make a regular .NET reference to it. Once you click "Add Reference..." you'll get to the .NET assemblies tab in the reference dialog. Then you click "Browse" which should open up the root directory of the project. In there you'll find the DLL you want to use, select it and ok out of everything. Visual Studio will then copy the DLL into the bin directory for you and the code that uses that assembly will then work.
<%#RegisterAssembly="(DLL Name)"Namespace="(Namespace from Object Browser)"TagPrefix="(Any Prefix)" %>

Removing all unused references from a project in Visual Studio projects

I just wondered if it possible within various Visual Studio versions to automatically remove all references from a project that were never been used?
In your answer, please specify which version of VS the solution applies to.
If you have Resharper (plugin) installed, you can access a feature that allows you to analyze used references via Solution Explorer > (right click) References > Optimize References...
http://www.jetbrains.com/resharper/webhelp/Refactorings__Remove_Unused_References.html
This feature does not correctly handle:
Dependency injected assemblies
Dynamically loaded assemblies (Assembly.LoadFile)
Native code assemblies loaded through interop
ActiveX controls (COM interop)
Other creative ways of loading assemblies
All you need is stone and bare knuckle then you can do it like a caveman.
Remove unused namespaces (for each class)
Run Debug build
Copy your executable and remaining namespace references to new location
Run the executable
Missing Reference DLL error will occur
Copy required DLL from Debug folder
Repeat 4-6
Gu Gu Ga Ga?
Throw your stone
You can also rely on your build tools to let you know which reference is still required. It's the era of VS 2017, caveman still survived.
The Resharper extension will do this for you.
This extension supports Visual Studio 2005 through 2017.
While the compiler won't include unused assemblies, extraneous using statements and references slows down Visual Studio and Intellisense, since there's more code the tools have to consider.
You can try the free VS2010 extension: Reference Assistant by Lardite group. It works perfectly for me. This tool helps to find unused references and allows you to choose which references should be removed.
In a Visual Basic project there is support to remove "Unused References" (Project-->References-->Unused References). In C# there isn´t such a function.
The only way to do it in a C# project (without other tools) is to remove possible unused assemblies, compile the project and verify if any errors occur during compilation. If none errors occur you have removed a unused assembly. (See my post)
If you want to know which project (assembly) depends on other assemblies you can use NDepend.
With Visual Studio versions 2017 and 2015, you can do this with the Code Map feature, but this feature is only available in the Enterprise Edition, not the Community or Professional versions.
Right-click on the project node in the solution explorer and select 'Show on Code Map.' This will display your .dll as a single node in a blank graph. Right-click on that node in the Code Map and select "Show Assemblies This References." This will add an additional node called "Externals" which can be expanded to show only the assemblies that are actually referenced.
For Visual Studio 2013/2015/2017 there is an extension that does exactly what you want: ResolveUR. What this basically does is:
reference is removed in the project
project is compiled with msbuild
check for build errors
restore removed references if there were build errors.
For anybody coming here looking for Visual studio 2012:
Download and Install Reference Assistant for Visual Studio 11
Later you can do:
In Visual Studio 2013 this extension works:
ResolveUR
Some people suggested to use an awesome tool - Reference Assistant for Visual Studio. The problem is that VS2012 is the latest supported Visual Studio. But there is the way to make it work in VS2013 as well ;)
And here is how:
1) Download Lardite.RefAssistant.11.0.vsix
2) Change the extension to zip: Lardite.RefAssistant.11.0.vsix -> Lardite.RefAssistant.11.0.zip
3) Unzip and open the extension.vsixmanifest file in the text editor
4) Find all occurences of InstallationTarget Version="[11.0,12.0)" and replace them with InstallationTarget Version="[11.0,12.0]" (note the closing bracket)
5) Save the file and zip all files so they are on the root zip level
6) Change the extension of the new zip to vsix
7) Install and enjoy :)
I've tested it with VS2013, thanks source for the tutorial
EDIT
Add to support VS 2015 Community Edition
<InstallationTarget Version="[14.0,15.0]" Id="Microsoft.VisualStudio.Community" />
Meaning of the brackets
[ – minimum version inclusive.
] – maximum version inclusive.
( – minimum version exclusive.
) – maximum version exclusive.
[Update] This feature is only available for .Net core projects.
This feature will be coming to Visual Studio 2019 very soon and already available with Visual Studio 2019 v16.10 Preview 1.
This option is turned off by default, but you can enable it under menu Tools > Options > Text Editor > C# > Advanced. Select the Remove Unused References command in Solution Explorer (Experimental). Once the option is enabled, the Remove Unused References command will appear in the right-click menu of a project name or dependencies node.
You can use Reference Assistant extension from the Visual Studio extension gallery.
Used and works for Visual Studio 2010.
In the VS2022 (preview at the moment of writing) this comes out of the box for SDK Style Projects (read: .NET Core and newer).
If it is available you can find it in the project context menu:
You get to choose what to do with each finding.
Read more about it here.
Pro-tip: Check if your project compiles and runs correctly after applying this. In my experience it doesn't check whether a dependency is used at runtime, for instance.
Using DevExpress, I follow these instructions:
In VS, go to DevExpress - Editor - Code Cleanup. Under Rules, check 'Remove unused namespace references'. Click OK.
Right-click on the solution, and choose 'Code Cleanup'. The cleanup runs for a few minutes, and finishes.
Build your application
The following method does not depend on any 'add-on's and is not very painful.
Step through each of your source files and
Select all (Ctrl-A)
Toggle outline expansion (Ctrl-M, M). This will reduce the file to two lines.
Click on the namespace's '+'. This will show each of the file's classes as a single line. Scan each class's reference count, looking for unreferenced classes.
Click on each of the classes' '+'. This will show each of the class functions as a single line. Scan each function's reference count, looking for unreferenced functions.
Scanning each file looking for '0 reference' takes only a second.
Scanning an entire project takes only a couple of minutes.
In VB2008, it works this way:
Project>Add References
Then click on the Recent tab where you can see list of references used recently. Locate the one you do not want and delet it. Then you close without adding anything.

How do you tell the Visual Studio project type from an existing Visual Studio project

Using Visual Studio 2005.
Is there anything in the .sln or .vcproj files (or anywhere else) that defines the project type / subtype?
Edit: What I mean is that when you create a project, you first choose a language (e.g. Visual C#), then a project type (e.g. Windows) and then a subtype (e.g. Console Application).
Where is this information stored within the VS files?
In the project XML files:
Console applications contain:
<OutputType>Exe</OutputType>
WinForms applications contain:
<OutputType>WinExe</OutputType>
Library (.dll) projects contain:
<OutputType>Library</OutputType>
and do NOT contain a
<ProjectTypeGuids>
ASP.NET and WCF projects contain:
<ProjectTypeGuids>{603c0e0b-db56-11dc-be95-000d561079b0};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
The GUIDs do something to define exactly what type of project it is. The ones above were taken from an ASP.NET app. They exist in WCF projects too, and flipping around the GUIDs can fool Vis Studio into changing the project type when you open it.
Some further research and I found this:
INFO: List of known project type Guids.
My .sln file contains:
Visual Studio 2005
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AddNumbers", "AddNumbers.csproj", "{2C81C5BB-E3B0-457E-BC02-73C76634CCD6}"
The link shows:
Project Type Description Project Type Guid
Windows (C#) {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
So it's Windows C# and the subtype is as per #HardCode's reply. In my case, it's "Console Application".
Right Click on Project of a solution.
Open Properties -> Application Tab.
On the right you can see 'Output Type' which defines your project type of an existing solution.
The .vproj file defines the project type, for example, the following defines a C++ project.
<VisualStudioProject
ProjectType="Visual C++"
The project tag also includes the compiler version.
Double-click on "My Project" in the Solution Explorer, and look at the "Application type:" ComboBox. It tells you (and lets you change) the project type.
Easy solution.
If you want to know if it's a WCF Project or ASP.NET Web Service simply open your project's folders in File Explorer. You can hover over the icon with your mouse and a tooltip will display the project type as shown in the picture. Also, you can look under the Type column in File Explorer and it shows it there as well.
WCF Web Service Project:
ASP.NET Web Service Project:
Also to note, if your project has a Resources.Designer.cs or Settings.Designer.cs in its Properties folder it's likely a WinForms application.
If you are interested in finding subtypes of a project i.e. Under C# Windows Project Category, checking whether it is a Windows Form Application or WPF
Try adding new item in the project and it will show you the items specific to that project type along with default options.
For instance if there is a WPF project it shows the WPF related options like 'Window' , 'Page' 'User Control' ... In case of Window Form Application it Shows 'Window Form' etc.....
Follow:
Solution Explorer -> hover/right click over your project item ( not the project folder. Check the Properties view to find if you clicked on the folder or the project) -> Properties.
Then all information is available for the project.
Right click on solution and click open folder in file explorer. Navigate to Project file. hover on it, tool tip displays the type of project file.

Add references to project when control dropped from Visual Studio 2008 toolbox

When I drop a third-party control onto a visual design surface in Visual Studio, any library references required by the control are automatically added to my project. I have an inherited version of a third-party control that I've added to the toolbox. However, when I drag it onto a form, only some of the references to the underlying third-party libraries are added. How can I specify additional references to be added?
If you know the path to the DLL that contains the controls, read this.
It's the same in VS2008 as in VS2005.

Resources