4

I want to compile each individual form on my application to be used sort of as a dll on its own... I looked into this and found very confusing representations of assemblies, which may or may not be what I wanted.

Is it possible to compile the form1.cs, form1.designer.cs and form1.resx to be 1 single file which then will be able to be used as a dll. I use "dll" as an example because that is the functionality I need with each of these forms when compiled to a single file, I need to be able to call it and use it from a shell application.

I know it is possible in VS to create a separate project which will compile into a dll but with something on the verge of 80 forms to compile... it will be a messy thing to maintain. So basically, is there an easier way?

this is the closest code I could get, but it is in console, so it will be impractical if there are easier ways... also I am not sure if it will actualy compile form1.cs, form1.designer.cs and form1.resx and still work as a dll

csc /target:library /out:MathLibrary.DLL Add.cs Mult.cs

Thanks for the help

4
  • How does an 80-form-project get any less messy when you compile them on the command line one by one? Maybe you can find a pattern or hierarchy that you don't need 80 different forms from the start? Commented Apr 8, 2014 at 6:37
  • Let me make sure I understand this correctly: You want to produce 80 different .dll-files that you can then refer to and use in a separete application, right? Commented Apr 8, 2014 at 6:45
  • unfortunately, due to the unique initial design of the application... this is how it is, and this is how it will stay.. every form does a different thing, it is a fairly complex application... the idea behind the dll for each form is to make it easier to update when changes are needed Commented Apr 8, 2014 at 6:47
  • @Kjartan essentially.. yes.. I realise this may not be ideal but I have little say over this matter. Dont worry about the number, is it possible? Commented Apr 8, 2014 at 6:48

3 Answers 3

1

Possible? Yes. Advisable? Umm, not sure.

You must study the CSC options to use it in such a massive way.

Partial classes are simply each listed among the sources. See here

The RESX file must be compiled by ResGen.exe to a resources file see here

You will use the /References parameter to include other DLLs.

The real challenge will probably come when you try to get cross references to work, depending on the layout of your application. Is there a main hub that will control all forms? Is it a plug-in architecture?

Good luck

Sign up to request clarification or add additional context in comments.

1 Comment

this looks like what I was looking at, thanks for the help with resx files too
1

Basically, you are working with solution. It can contain multiple projects. For each dll, you must have one project. So create 80 projects, add to each of them single form, edit it, add some logic.

Then there will be a main project, which produce exe. You can reference all dlls in that project, but better don't. If you do, updating any of dll will required recompiling that exe too. You can load them dynamically or use sort of plugin system (to enumerate dlls, understand their purpose, etc). Then you obtain Type from assembly (loaded dll), create instance (which will call constructor, which calls InitializeComponents, which loads form resources) and display form.

Regarding abstraction, you surely need something. To example, login window. You can create a generic form with some focus, user interface and user interaction logic. But it has to communicated with main project (which encapsulate encryption, password storage model, user rights, etc). One easy way to do this is to provide 2 interfaces:

interface ILoginImplementation
{
    public void SetInitialUserName(string name);
}

interface ILoginLogic
{
    public bool TryAuthenticate(string name, string password);
}

Implementation is what your form must implement and Logic is what main project implements and supply when instantiating login form.

Comments

0

I realize this is probably not ideal, but I still think your best bet is to use Visual Studio and create a separate project for each .dll to be created.

By right clicking the Solution node and selecting Add > New Solution Folder, you can at least organize your projects into a somewhat more orderly hierarchy. That alone might go a long way to make your project more manageable.

PS: If you haven't already, you should definitely try to create an interface, or a base class (or both!) that each of your Form-classes can derive from or implement. If you're able to abstract away and generalize some of the logic, it is quite likely to save you a lot of work down the road.

1 Comment

thanks, and yes I actually use an abstracted base usercontrol but in most cases the logic cannot be generalized because it is unique to the form.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.