在linux
,採用了最新的dotnetcore
第一次嘗試在dotnetcore ASP.Net:WebHostBuilder錯誤
[[email protected] dot-net-core-centos-7-master]$ dotnet --version
1.0.4
[[email protected] dot-net-core-centos-7-master]$
我得到這個簡單的應用程序的erron。我錯過了什麼?
的的.csproj文件
[[email protected] dot-net-core-centos-7-master]$ more dot-net-core-centos-7-master.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk.Web">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.1.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc">
<Version>1.1.0</Version>
</PackageReference>
</ItemGroup>
</Project>
[[email protected] dot-net-core-centos-7-master]$
project.json:
[[email protected] dot-net-core-centos-7-master]$ more project.json
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-rc2-3002702"
},
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0-rc2-final"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
},
}
的Program.cs的
[[email protected] dot-net-core-centos-7-master]$ more Program.cs
using System;
using System.IO;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace aspnetcoreapp
{
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseStartup<Startup>()
.UseUrls("http://*:80/")
.Build();
host.Run();
}
}
}
個Startup.cs
[[email protected] dot-net-core-centos-7-master]$ more Startup.cs
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
namespace aspnetcoreapp
{
public class Startup
{
public void Configure(IApplicationBuilder app)
{
app.Run(context =>
{
return context.Response.WriteAsync("Hello from ASP.NET Core!");
});
}
}
}
[[email protected] dot-net-core-centos-7-master]$
當我嘗試運行它,我得到一個運行時錯誤:
[[email protected] dot-net-core-centos-7-master]$ dotnet run
/home/idf/dotnet/sdk/1.0.4/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.DefaultItems.targets(101,5): warning : A PackageReference for 'Microsoft.NETCore.App' was included in your project. This package is implicitly referenced by the .NET SDK and you do not typically need to reference it from your project. For more information, see https://aka.ms/sdkimplicitrefs [/home/idf/dotnet_progs/dot-net-core-centos-7-master/dot-net-core-centos-7-master.csproj]
Program.cs(14,28): error CS0246: The type or namespace name 'WebHostBuilder' could not be found (are you missing a using directive or an assembly reference?) [/home/idf/dotnet_progs/dot-net-core-centos-7-master/dot-net-core-centos-7-master.csproj]
Program.cs(20,18): error CS7036: There is no argument given that corresponds to the required formal parameter 'handler' of 'RunExtensions.Run(IApplicationBuilder, RequestDelegate)' [/home/idf/dotnet_progs/dot-net-core-centos-7-master/dot-net-core-centos-7-master.csproj]
The build failed. Please fix the build errors and run again.
[[email protected] dot-net-core-centos-7-master]$ ls
你運行的是什麼版本的dotnet? 'dotnet --version' – kimbaudi
@kimbaudi 1.0.4 – Ivan
好的只是想知道。我想知道爲什麼你有'.csproj'文件和'project.json'文件。也許你從'project.json'遷移到'.csproj'。我認爲你應該先將'project.json'備份到某個地方,然後從你的web應用程序中刪除它。我會發佈一個答案,我希望能幫助你。 – kimbaudi