compilation error (class library error)

  • Thread starter Thread starter juli jul
  • Start date Start date
J

juli jul

Hello,
I am trying to compile a project and get the following error:
A project with an Output Type of Class Library cannot be started
directly

Can somebody explain me why?
Thank you very much!
 
juli said:
I am trying to compile a project and get the following error:
A project with an Output Type of Class Library cannot be started
directly

Can somebody explain me why?

Well, a class library is just not a executable type of project. If you
want to execute the result of your compilation, you need to create a
project with the word "Application" in its name (the name that's shown
in the New Project dialog).

Now that you have created the class library, it's not really easy to
change it to an executable type, so it would probably be best if you
just created a new project, probably of type "Windows Application", and
take over the code you have already written. If you absolutely need to
convert the project you already have, please don't hesitate to ask again.



Oliver Sturm
 
It sounds to me like you are not trying to compile the project but you are
trying to execute it or debug it.

In this case you have a library which, generally speaking, does not have an
entry point. You are probably pressing F5 or Ctrl+F5 in Visual Studio which
are actually the commands for debug and run without debugging respectively.
These commands do actually compile the project but they are not the way you
shoudl do it.

Hit Ctrl+Shift+B to build (i.e. compile+link+whatever else) your project or
select build from the build menu.

If on the other hand you are actually trying to execute your library then
chance are you shoudl have a console app or a windows forms app so you should
just right click on the project, go to properties, and then change the
"Output Type" from Class library to something else.

Hope this helps
 
juli said:
I can't change the project name.What can I do in order to solve this?
[...snip...]

Oliver's post was a little misleading. He didn't want you to change the
project name, but the project type. When creating a new project, VS asks you
to specify what kind of project you want to open.
If you select "class library", you will not be able to *execute* the
project. The build will perfom ok. If you need an executable, you'd have to
select any item with "application" in it's name _upon project creation_.

Refer to Biran's post on what to do to make your project compile correctly.
 
Michael said:
I can't change the project name.What can I do in order to solve this?

[...snip...]

Oliver's post was a little misleading. He didn't want you to change the
project name, but the project type. When creating a new project, VS asks you
to specify what kind of project you want to open.
If you select "class library", you will not be able to *execute* the
project. The build will perfom ok. If you need an executable, you'd have to
select any item with "application" in it's name _upon project creation_.

Sure, that's what I meant.
Refer to Biran's post on what to do to make your project compile correctly.

And what Brian suggests was something I didn't want to suggest, because
a class library project will not contain a Main method and it will be
difficult to explain how to create one manually. That's why I suggested
creating a new project to start with and taking over the important parts
that may have been created already in the class library project.



Oliver Sturm
 
Back
Top