Skip to content

Add Support for ASP.NET Core 2.2 #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Dec 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ApiVersioning.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "misc", "misc", "{2957BAF3-9
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{915BB224-B1D0-4E27-A348-67FCC77AAA44}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "webapi", "webapi", "{F446ED94-368F-4F67-913B-16E82CA80DFC}"
ProjectSection(SolutionItems) = preProject
samples\webapi\directory.build.targets = samples\webapi\directory.build.targets
samples\directory.build.props = samples\directory.build.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "webapi", "webapi", "{F446ED94-368F-4F67-913B-16E82CA80DFC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "aspnetcore", "aspnetcore", "{900DD210-8500-4D89-A05D-C9526935A719}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BasicSample", "samples\aspnetcore\BasicSample\BasicSample.csproj", "{59389B47-8280-411E-B840-D097AA1DCDEE}"
Expand Down
2 changes: 1 addition & 1 deletion build/code-analysis.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

<ItemGroup Label="NuGet">
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.6.2" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.0-beta009" PrivateAssets="All" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.1-beta.61" PrivateAssets="All" />
</ItemGroup>

</Project>
17 changes: 5 additions & 12 deletions samples/aspnetcore/BasicSample/BasicSample.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>Microsoft.Examples</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Content Update="wwwroot\**\*;Views;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Mvc.Versioning\Microsoft.AspNetCore.Mvc.Versioning.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
namespace Microsoft.Examples.Controllers
{
using AspNetCore.Mvc.Routing;
using AspNetCore.Routing;
using Extensions.DependencyInjection;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

[ApiController]
[ApiVersion( "1.0" )]
[Route( "api/v{version:apiVersion}/[controller]" )]
public class HelloWorldController : Controller
public class HelloWorldController : ControllerBase
{
// GET api/v{version}/helloworld
[HttpGet]
Expand Down
11 changes: 4 additions & 7 deletions samples/aspnetcore/BasicSample/Controllers/Values2Controller.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
namespace Microsoft.Examples.Controllers
{
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

[ApiController]
[ApiVersion( "2.0" )]
[Route( "api/values" )]
public class Values2Controller : Controller
public class Values2Controller : ControllerBase
{
// GET api/values?api-version=2.0
[HttpGet]
public string Get() => $"Controller = {GetType().Name}\nVersion = {HttpContext.GetRequestedApiVersion()}";
public string Get( ApiVersion apiVersion ) => $"Controller = {GetType().Name}\nVersion = {apiVersion}";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
namespace Microsoft.Examples.Controllers
{
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

[ApiController]
[ApiVersion( "1.0" )]
[Route( "api/[controller]" )]
public class ValuesController : Controller
public class ValuesController : ControllerBase
{
// GET api/values?api-version=1.0
[HttpGet]
Expand Down
25 changes: 8 additions & 17 deletions samples/aspnetcore/BasicSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
namespace Microsoft.Examples
{
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;

public class Program
public static class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
public static void Main( string[] args ) =>
CreateWebHostBuilder( args ).Build().Run();

host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder( string[] args ) =>
WebHost.CreateDefaultBuilder( args )
.UseStartup<Startup>();
}
}
}
39 changes: 16 additions & 23 deletions samples/aspnetcore/BasicSample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,34 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Mvc.Routing;
using static Microsoft.AspNetCore.Mvc.CompatibilityVersion;

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

public IConfigurationRoot Configuration { get; }
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.AddMvc();

// reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
services.AddApiVersioning( o => o.ReportApiVersions = true );
// the sample application always uses the latest version, but you may want an explict version such as Version_2_2
// note: Endpoint Routing is enabled by default; however, if you need legacy style routing via IRouter, change it to false
services.AddMvc( options => options.EnableEndpointRouting = true ).SetCompatibilityVersion( Latest );
services.AddApiVersioning(
options =>
{
// reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions"
options.ReportApiVersions = true;
} );
}

public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory )
public void Configure( IApplicationBuilder app, IHostingEnvironment env )
{
loggerFactory.AddConsole( Configuration.GetSection( "Logging" ) );
loggerFactory.AddDebug();
app.UseMvc();
}
}
}
}
10 changes: 4 additions & 6 deletions samples/aspnetcore/BasicSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Warning"
}
}
}
},
"AllowedHosts": "*"
}
17 changes: 5 additions & 12 deletions samples/aspnetcore/ByNamespaceSample/ByNamespaceSample.csproj
Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<RootNamespace>Microsoft.Examples</RootNamespace>
</PropertyGroup>

<ItemGroup>
<Content Update="wwwroot\**\*;Views;Areas\**\Views;appsettings.json;web.config">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\src\Microsoft.AspNetCore.Mvc.Versioning\Microsoft.AspNetCore.Mvc.Versioning.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.9" />
</ItemGroup>

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

</Project>
30 changes: 11 additions & 19 deletions samples/aspnetcore/ByNamespaceSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,16 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;

namespace Microsoft.Examples
namespace Microsoft.Examples
{
public class Program
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;

public static class Program
{
public static void Main( string[] args )
{
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot( Directory.GetCurrentDirectory() )
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
public static void Main( string[] args ) =>
CreateWebHostBuilder( args ).Build().Run();

host.Run();
}
public static IWebHostBuilder CreateWebHostBuilder( string[] args ) =>
WebHost.CreateDefaultBuilder( args )
.UseStartup<Startup>();
}
}
36 changes: 19 additions & 17 deletions samples/aspnetcore/ByNamespaceSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Versioning.Conventions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace Microsoft.Examples
namespace Microsoft.Examples
{
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.Versioning.Conventions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using static Microsoft.AspNetCore.Mvc.CompatibilityVersion;

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.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices( IServiceCollection services )
{
services.AddMvc();
// the sample application always uses the latest version, but you may want an explict version such as Version_2_2
// note: Endpoint Routing is enabled by default; however, if you need legacy style routing via IRouter, change it to false
services.AddMvc( options => options.EnableEndpointRouting = true ).SetCompatibilityVersion( Latest );
services.AddApiVersioning(
options =>
{
Expand All @@ -25,15 +34,8 @@ public void ConfigureServices( IServiceCollection services )
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure( IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory )
public void Configure( IApplicationBuilder app, IHostingEnvironment env )
{
loggerFactory.AddConsole();

if ( env.IsDevelopment() )
{
app.UseDeveloperExceptionPage();
}

app.UseMvc();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Microsoft.AspNetCore.Mvc;
using Models;

[ApiController]
[Route( "[controller]" )]
[Route( "v{version:apiVersion}/[controller]" )]
public class AgreementsController : Controller
public class AgreementsController : ControllerBase
{
// GET ~/v1/agreements/{accountId}
// GET ~/agreements/{accountId}?api-version=1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Microsoft.AspNetCore.Mvc;
using Models;

[ApiController]
[Route( "[controller]" )]
[Route( "v{version:apiVersion}/[controller]" )]
public class OrdersController : Controller
public class OrdersController : ControllerBase
{
// GET ~/v1/orders/{accountId}
// GET ~/orders/{accountId}?api-version=1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Microsoft.AspNetCore.Mvc;
using Models;

[ApiController]
[Route( "[controller]" )]
[Route( "v{version:apiVersion}/[controller]" )]
public class AgreementsController : Controller
public class AgreementsController : ControllerBase
{
// GET ~/v2/agreements/{accountId}
// GET ~/agreements/{accountId}?api-version=2.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
using Microsoft.AspNetCore.Mvc;
using Models;

[ApiController]
[Route( "[controller]" )]
[Route( "v{version:apiVersion}/[controller]" )]
public class OrdersController : Controller
public class OrdersController : ControllerBase
{
// GET ~/v2/orders/{accountId}
// GET ~/orders/{accountId}?api-version=2.0
Expand Down
Loading