Creating component generating DLL

Asked

Viewed 219 times

0

I modified some components generating a DLL when compiling the project. Is there any way that DLL can only be used together with the current project? Is there any way not to generate the DLL and compile everything as a single executable?

  • Add a minimal example of code so that it is possible to identify at what point of development the problem is. It will allow a more accurate analysis and the problem and consequently a better solution, without assumptions.

2 answers

0

I hope when you are referring to components as being the controls used for handling the user interface (i.e. textbox, combobox, etc.).

Is there any way not to generate the DLL and compile everything as a single executable?

Yes, it is possible to extend components and have everything compiled into a single executable. For this to happen just create the class that extends the component, or its own component, within the main project.

Note that it is not about including one project within the other. The code for the component must be transported and adapted within the main project so that it is compiled in the same executable. For any other existing project (outside the main project) a DLL will be created.

In the following example, I customized a textbox and entered a property called Hump (I know that there is already Backcolor, but I used only as an example). Note that everything is within the main project.

inserir a descrição da imagem aqui

public partial class TextBoxPersonalizada : System.Windows.Forms.TextBox
{

    public void CorFundo(System.Drawing.Color cor)
    {
        this.BackColor = cor;
    }

}

Customization consists of displaying the textbox with the background in red color.

inserir a descrição da imagem aqui

The image above shows the component in Toolbox and added to the main form.

The main form code is:

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        textBoxPersonalizada1.CorFundo(System.Drawing.Color.Red);
    }
}

And the result:

inserir a descrição da imagem aqui

Is there any way that DLL can only be used together with the current project?

How much the use of the DLL only by the current project seems, at first glance, as something incoherent. If you do not want to use the functions of this DLL with other projects, put these functions within the main project, because the purpose of using libraries is to provide access to methods that can be shared by various applications, thus avoiding code duplicity.

  • Thanks for the feedback. In my project I gave an increment in Textbox to be compatible with my needs and attached in my project. In the project I now have 2 projects... one with the set of Forms and the other project with this component. happens that when I have it compiled ("build") it creates the EXE of the Forms and the DLL of the component.

  • As I explained above, you need to implement this "incremented" Textbox within the main project in order to create a single executable. If there is another project besides the main one, Dlls will be created.

  • I tried to do as you said... but I can only include an existing project within the Solution... and not within the project. Within my Solution Explorer, 3 projects appear... 1 from Forms... and 2 other from optimized controls. Only when I compile, it creates 1 exe and 2 dll

0

Is there any way that DLL can only be used together with the project current?

There is a business called Strong Name, basically, it will create a hash between to the DLL, so your project is tied to this DLL:

Link:

Strong-Named Assemblies How to: Sign an Assembly with a Strong Name

Is there any way not to generate the DLL and compile everything as a single executable?

There is a type of project called Shared, it does not generate DLL all the code is placed inside the exe, is available in VS2015 version:

Link: Shared Project : An Impressive Feature of Visual Studio 2015 Preview

Visual Basic 14 - What’s New in the New Version - Shared Projects

What is the Difference between a Shared Project and a Class Library in Visual Studio 2015?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.