views:

146

answers:

5

Using Visual Studio 2005

I have list of class files, when i try to run the class files, it showing error as "a project with output type of class library cannot be started directly"

How to run the class file? How to create a dll file.

Am new to visual studio 2005

Need Help?

A: 

You cannot run projects of type class library. You need to define a startup project that is either a console application, windows application or a web application which would use the class library.

Darin Dimitrov
+8  A: 

A Class Library is just that, a library of code, you need to create an application that references the library to try it out.
In the same solution, just add a new project as a Winforms Application and then in the winforms application project add a reference to the class library project.

You should then be able to call the methods in the library from the application code.

ho1
+2  A: 

To create a DLL File, click on New project, then select Class Library.

Enter your code into the class file that was automatically created for you and then click Build Solution from the Debug menu.

Now, look in your directory: ../debug/release/YOURDLL.dll

There it is! :)

P.S. DLL files cannot be run just like normal applciation (exe) files. You'll need to create a separate project (probably a win forms app) and then add your dll file to that project as a "Reference", you can do this by going to the Solution explorer, right clicking your project Name and selecting Add Reference then browsing to whereever you saved your dll file.

Then, to be able to use this dll file, in your projects code, you call the methods inside the dll file. For example:

If, in your DLL file you have a method like this:

public string somerandommethod()
{
   string x = "something";
return x;
}

Then, in your Form1.cs file of your separate project, you would call the code from your dll file like this:

button1_Click(object sender, EventArgs e)
{
    MyDllFile dll = new MyDllFile();
    MessageBox.Show(dll.somerandommethod());
}

I hope this has helped you

A: 

If you are creating a library, look at using something like NUnit to test it. It will load the dll and execute whatever tests you define on it.

Pete Kirkham
A: 

You can not run a class file, either you can go to project properties ->Application - > Output type. Here you can specify the application type as console application so your code will run on command prompt. Also make sure that the project you are trying to run is set as startup project (you can do it by right click on project and select "Set as Startup project".

To create a DLL you need to select New Project -> Class library.

Ram