.net core创建控制台应用程序和mvc程序

一、创建控制台应用程序

1.查看支持哪些类型:dotnet new --help

2.创建项目(先定位到需要创建的目录)

dotnet new console -o ./myconsole

3.查看目录

 Program.cs内容:

 

4.运行程序,必须进入Program.cs同级目录运行

dotnet run

 

5.上面是Program.cs同级运行的,执行了run之后,我们进入bin目录下会存在如下目录:

扫描二维码关注公众号,回复: 5530782 查看本文章

在这个目录可以执行:dotnet myconsole.dll。这就是编译后的运行了。

二、创建MVC程序

1.创建项目

dotnet new mvc -o ./mymvc

 

2.查看目录

3.运行项目:dotnet run

4.打开一个窗口执行:

         curl http://localhost:5000

  能正常返回说明启动成功。

注意:修改请求的IP和端口。

在Program.cs的同级查看Properties/launchSettings.json文件,没有就创建该文件。launchSettings.json内容如下:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://0.0.0.0:2829/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "WebApplication1": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "http://0.0.0.0:2830/"
    }
  }
}

里面的端口就是mvc请求端口。里面的IP必须修改为0.0.0.0才能外部访问,否则只能本机访问。

猜你喜欢

转载自www.cnblogs.com/duanjt/p/10529303.html
今日推荐