文章出處

回到目錄

新寵兒

DotNetCore是.net5.0版本,之所以不叫.net5.0為的就是不讓我們把它與前面的.net混為一淡,它將是真正意義的跨平臺開發語言,在網上也有相關介紹,中國的一些大牛也發了相關文章,像張善友大牛也發了幾個文章,來介紹.NetCore,這段時間,大叔將會一步一步說說這個跨平臺的新寵兒!

重新起名了

  • ASP.NET 5 –> ASP.NET Core 1.0
  • .NET Core 5 –> .NET Core 1.0
  • Entity Framework 7 –> Entity Framework Core 1.0

起航

下載.net core 1.0.0 rc2版

建立一個MVC項目

之前我們會看到相應的信息,今天主要說一下起始文件,Startup.cs

Configure方法主要作用是對運行環境進行個性化配置,如調試環境(Development),生產環境(Production),跌代環境(Staging)等

  public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                .SetBasePath(env.ContentRootPath)
                .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            //判斷運行環境
            if (env.IsDevelopment())
            {
                // For more details on using the user secret store see http://go.microsoft.com/fwlink/?LinkID=532709
                builder.AddUserSecrets();

                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true,endpointAddress:"localhost:5000");
            }

            builder.AddEnvironmentVariables();
            Configuration = builder.Build();
 
        }

需要希望修改監聽的端口,需要修改program.cs程序,具體如下

     public static void Main(string[] args)
        {
            var host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .UseStartup<Startup>()
                    .UseUrls("http://192.168.2.22:5000")
                    .Build();


            host.Run();
            host.Run();
        }

這樣我們的第一個應用程序就可以了,它可以部署到linux,maxos等操作系統上,只需要安裝dotnet-cli即可。

終于OK了,咱們的第一個跨平臺的.net程序完成了!

謝謝您的閱讀!

回到目錄


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()