33

I've download sample code with C#. but when I run I get this error message:

A project with an Output type of Class Library cannot be started directly In order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.

Please give me a solution.

Damith
  • 62,401
  • 13
  • 102
  • 153
hin leaksmei
  • 367
  • 1
  • 3
  • 3
  • 1
    Possible duplicate of ["A project with an Output type of Class Library cannot be started directly"](https://stackoverflow.com/questions/3363106/a-project-with-an-output-type-of-class-library-cannot-be-started-directly) – kenorb Sep 18 '18 at 15:58

8 Answers8

70

The currently selected startup project is a Class Library.

You need an entry point for your application. Does your solution contain multiple projects?

Are you sure you want to 'run' the Class Library?

enter image description here

Possibly you've downloaded a Class Library solution only. In that case there might be unit tests that you can 'debug' to step-trough the code.

Update In response to your comment, these are possibilities to run the class library:

  • Create a console application and reference the class library. Then 'use' its contents
  • Debug an unit-test project
  • start existing client project
Myrtle
  • 5,761
  • 33
  • 47
  • Yes, I got many projects in a solution. and I want to run the Class Library. – hin leaksmei Jun 22 '12 at 08:03
  • 1
    @hinleaksmei You can not run a Class Library stand alone. Its logic is supposed to be 'used' by another project. Therefore you need logic that is 'using' the classes found in your Class Library. – Myrtle Jun 22 '12 at 08:04
  • I had to set the startup project after migrating a webforms solution from VS2017 to VS2019. – Andrew Morton Sep 24 '20 at 11:43
13

If you have a project with an executable right-click this and select "Set as start project" - if not you have to write one to debug your code (or use Unit-Tests).

Random Dev
  • 51,810
  • 9
  • 92
  • 119
  • I had downloaded a Microsoft Live SDK and opened one of its sample projects. I had to "Set as start project" before I could run it. This answer helped. Thanks @carsten-konig. – Dizzley Jan 15 '15 at 07:08
13

The debug settings of your Visual Studio development environment might be left blank. Please check if the following highlighted fields are missing, if they are missing then fill it up with your specific executable.

Debug Settings

These fields are required to let the VS start the program for debugging. In the above picture, I'm developing a VSPackage so the:

  1. The external program is devenv.exe
  2. Command line argument is /rootsuffix Exp (for starting the experimental instance).

Note: I can assure you the answers mentioned in here didn't help me fix the issue because my project was already set as a startup project, now I came across an MSDN blog which helped me and lead to this answer.

Pang
  • 9,564
  • 146
  • 81
  • 122
Jerric Lyns John
  • 936
  • 10
  • 25
  • And if there isn't a Start Action section it may be because you're using a free, Express, edition of Visual Studio. In that case look for a .csproj.user file and edit. For instance, I'm using VS Express 2012 to build an XLL with Excel-DNA. Here's my .cspros.user file... – osullivj Apr 25 '15 at 15:23
4

You need to check that you have the startup project setup correctly.

If there is more than one project in the solution, right click on the one that should be run when you compile and choose Set as startup project

Gaz Winter
  • 2,924
  • 2
  • 25
  • 47
0

I was trying to run a Debug test with breakpoint in the specFlow feature.cs file instead of the Step.cs file. Put the breakpoint in the Step.cs file and it's working as expected. Thanks!

Tien
  • 159
  • 1
  • 3
  • 10
  • Did this get posted to the wrong answer? This question doesn’t pertain to breakpoints or a `Step.cs` file, so it’s unclear how it addresses the question. – Jeremy Caney Oct 13 '21 at 19:20
0

Try to close Visual Studio and restart it by opening the file you are trying to debug from Unity

Dan Levin
  • 718
  • 7
  • 16
0

None of the answers provided above helped me resolve this error, this is what resolved the issue for me.

  1. Right click on the solution and select "Properties", which is in my case "Sintctech.Data".
  2. Select the section called "Application".
  3. Check what you have selected as your output type. If it is "Windows Application", change it to "Console Appication".

enter image description here

  1. Rebuild the solution
Dennis Kozevnikoff
  • 2,078
  • 3
  • 19
  • 29
-3
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
    <StartAction>Program</StartAction>
    <StartProgram>C:\Program Files (x86)\Microsoft Office\Office14\excel.exe</StartProgram>
    <StartArguments></StartArguments>
    <StartWorkingDirectory></StartWorkingDirectory>
    <EnableUnmanagedDebugging>true</EnableUnmanagedDebugging>
  </PropertyGroup>
</Project>
osullivj
  • 341
  • 1
  • 5