2016-05-14 80 views
-4

我試圖建立這個代碼按下Ctrl + Alt + F5:大廈C#的lib

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 

namespace Formater 
{ 
    public class Startup 
    { 
     public async Task <object> Invoke (object input) 
     { 
      return ".NET"; 
     } 
    } 
} 

,但我收到此錯誤:

「與一個類庫輸出類型項目不能直接啓動

爲了調試這個項目,將一個可執行項目添加到引用庫項目的解決方案中,將可執行項目設置爲啓動項目。

可能是什麼問題?我在尋找特種部隊的問題,我發現了幾個解決方案,但他們都沒有工作。

謝謝。

+0

F5不適合建築,它適合跑步。使用F6進行建築。 – NineBerry

回答

1

您正在構建一個沒有任何入口點或主要方法的類庫。你不能單獨運行類庫,你只能建造它,運行這個類庫你要麼必須添加它會console appwin form或任何.NET應用程序

4

What could be the problem?

的至於你說:

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.

這一切都是清晰的英語。類庫(dll)沒有入口點,無法啓動。這是一個在程序中使用的庫。

1

由於您正在構建庫(.dll),因此Visual Studio不知道如何運行它。 Visual Studio只能運行由Web服務器加載的程序(.exe)或網站(以及其他內容)。

Visual Studio提供的解決方案基本上意味着您必須在其他一些程序中引用您的庫才能運行它。