2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

初めての.NET 5

Posted at

rksoftware君がblogを書いているので、追っかけてみます

ここから初めて
https://devblogs.microsoft.com/dotnet/announcing-net-5-0-rc-1/
RC1 is a “go live” release とあるので、実開発にも使えるのね

Visual Studio 2019 の Preview 版をインストールが前提みたいですが
https://visualstudio.microsoft.com/ja/vs/preview/
VisualStudioのインストーラーにはないので
ここから
https://dotnet.microsoft.com/download/dotnet/5.0
これを
https://dotnet.microsoft.com/download/dotnet/thank-you/sdk-5.0.100-rc.1-windows-x64-installer
ダウンロードします

.NET 5 SDK をインストール (私は Windows の x64 インストーラーでインストールしました)

じゃ、まずは、Webアプリのプロジェクトを作ってみます

新しいプロジェクトの作成から
image.png

ASP.NET Core Web アプリケーションを選択

image.png

Web アプリケーションを選択

image.png

SDK が入っているので プルダウンで ASP.NET Core 5.0 を選択可能です。

image.png

見慣れた、光景ですね。

起動すると

image.png

いつものProgram.cs

Program.cs
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication10
{
    public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });
    }
}

いつもの、StartUp.cs

StartUp.cs
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace WebApplication10
{
    public class Startup
    {
        public Startup(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        public IConfiguration Configuration { get; }

        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRazorPages();
        }

        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseHsts();
            }

            app.UseHttpsRedirection();
            app.UseStaticFiles();

            app.UseRouting();

            app.UseAuthorization();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapRazorPages();
            });
        }
    }
}

3.1からの移行は、そんなに困らなさそう?

2
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?