[英]what is the general way to find what dependencies do I need on .net core?
我正在嘗試根據在一些博客中找到的代碼創建一個簡單的.net核心應用程序。 我在Ubuntu 16.04上。 我的文件是:
project.json
{
"version": "1.0.0-*",
"buildOptions": {
"debugType": "portable",
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"dependencies": {
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.AspNetCore.Server.WebListener": "0.1.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"imports": "dnxcore50"
}
}
}
Program.cs中
using Microsoft.Extensions.Configuration; // for using IConfiguration
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Server.Kestrel;
using System.IO; // for using Directory
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
}
hosting.json
{
"server.urls": "http://localhost:60000;http://localhost:60001"
}
執行dotnet發布時出現的錯誤是:
error CS0246: The type or namespace name 'Startup' could not be found (are you missing a using directive or an assembly reference?)
另外,請記住,我正在尋找一種通用的方式來知道我錯過了哪些依賴項。
真的不會有一個。 您也許可以找到像reshaper這樣的工具,它知道官方的Microsoft軟件包,並且會告訴您“ Microsoft.EntityFrameworkCore”或您所缺少的任何內容。 但是,通常要可靠地解決問題。 在您的示例中,您缺少了應該在您的代碼中定義的類。 也可以通過包含定義了啟動的程序包來解決。 即使假設是這種情況,它怎么會知道選擇合適的人呢? 可能有很多實現Startup類的軟件包。 Foo.Startup,Bar.Startup,Microsoft.CrossPlatform.StartUp-所有這些都可以想象為以您對代碼進行編譯的方式實現Startup。 工具將如何知道哪一個適合您的需求? 通常,您將找到要包含和添加的庫,而不是編寫代碼,然后尋找所需內容的實現。
您要的是依賴性,但您不會錯過任何一個。 您缺少的是Startup
類,您所關注的博客忘記提及了,或者您沒有按照說明進行操作。
創建新ASP.NET Core項目的最簡單方法是運行dotnet new -t web
。 該類的Startup
類在這里 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.