-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3306 from jimschubert/aspnet5_.NET_Core_1.0
[aspnet5] update to asp.net core 1.0
- Loading branch information
Showing
47 changed files
with
1,118 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 6 additions & 4 deletions
10
modules/swagger-codegen/src/main/resources/aspnet5/Dockerfile.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
FROM microsoft/aspnet:1.0.0-rc1-final | ||
FROM microsoft/dotnet:latest | ||
|
||
ENV DOTNET_CLI_TELEMETRY_OPTOUT 1 | ||
|
||
RUN mkdir -p /app/{{packageName}} | ||
COPY . /app/{{packageName}} | ||
WORKDIR /app/{{packageName}} | ||
RUN ["dnu", "restore"] | ||
RUN ["dnu", "pack", "--out", "artifacts"] | ||
|
||
EXPOSE 5000/tcp | ||
ENTRYPOINT ["dnx", "-p", "project.json", "web"] | ||
|
||
RUN ["dotnet", "restore"] | ||
ENTRYPOINT ["dotnet", "run", "-p", "project.json", "web"] |
9 changes: 9 additions & 0 deletions
9
modules/swagger-codegen/src/main/resources/aspnet5/NuGet.Config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
<!--To inherit the global NuGet package sources remove the <clear/> line below --> | ||
<clear /> | ||
<add key="dotnet-core" value="https://www.myget.org/F/dotnet-core/api/v3/index.json" /> | ||
<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" /> | ||
</packageSources> | ||
</configuration> |
32 changes: 32 additions & 0 deletions
32
modules/swagger-codegen/src/main/resources/aspnet5/Program.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.AspNetCore.Builder; | ||
|
||
namespace {{packageName}} | ||
{ | ||
public class Program | ||
{ | ||
public static void Main(string[] args) | ||
{ | ||
var host = new WebHostBuilder() | ||
.UseKestrel(options => | ||
{ | ||
// options.ThreadCount = 4; | ||
// options.UseHttps("cert.pfx", "certpassword"); | ||
options.NoDelay = true; | ||
options.UseConnectionLogging(); | ||
}) | ||
.UseUrls("http://+:5000" /*, "https://+:5001" */) | ||
.UseContentRoot(Directory.GetCurrentDirectory()) | ||
.UseIISIntegration() | ||
.UseStartup<Startup>() | ||
.Build(); | ||
|
||
host.Run(); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
modules/swagger-codegen/src/main/resources/aspnet5/Project.xproj.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<PropertyGroup> | ||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion> | ||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" /> | ||
<PropertyGroup Label="Globals"> | ||
<ProjectGuid>{{projectGuid}}</ProjectGuid> | ||
<RootNamespace>Sample</RootNamespace> | ||
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath> | ||
<OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath> | ||
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
</PropertyGroup> | ||
<Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /> | ||
</Project> |
22 changes: 19 additions & 3 deletions
22
modules/swagger-codegen/src/main/resources/aspnet5/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,28 @@ | ||
{ | ||
"iisSettings": { | ||
"windowsAuthentication": false, | ||
"anonymousAuthentication": true, | ||
"iisExpress": { | ||
"applicationUrl": "http://localhost:50352/", | ||
"sslPort": 0 | ||
} | ||
}, | ||
"profiles": { | ||
"IIS Express": { | ||
"commandName": "IISExpress", | ||
"launchBrowser": true, | ||
"launchUrl": "swagger/ui", | ||
"launchUrl": "swagger/ui/index.html", | ||
"environmentVariables": { | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
}, | ||
"web": { | ||
"commandName": "Project", | ||
"launchBrowser": true, | ||
"launchUrl": "http://localhost:5000/swagger/ui/index.html", | ||
"environmentVariables": { | ||
"ASPNET_ENV": "Development" | ||
"ASPNETCORE_ENVIRONMENT": "Development" | ||
} | ||
} | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
modules/swagger-codegen/src/main/resources/aspnet5/README.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# {{packageName}} - ASP.NET Core 1.0 Server | ||
|
||
{{#appDescription}} | ||
{{{appDescription}}} | ||
{{/appDescription}} | ||
|
||
## Run | ||
|
||
Linux/OS X: | ||
|
||
``` | ||
sh build.sh | ||
``` | ||
|
||
Windows: | ||
|
||
``` | ||
build.bat | ||
``` | ||
|
||
## Run in Docker | ||
|
||
``` | ||
cd src/{{packageName}} | ||
docker build -t {{packageName}} . | ||
docker run -p 5000:5000 {{packageName}} | ||
``` |
32 changes: 32 additions & 0 deletions
32
modules/swagger-codegen/src/main/resources/aspnet5/Solution.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
| ||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 14 | ||
VisualStudioVersion = 14.0.25420.1 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815BE834-0656-4C12-84A4-43F2BA4B8BDE}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{AFF6BF88-8A7D-4736-AF81-31BCE86B19BD}" | ||
ProjectSection(SolutionItems) = preProject | ||
global.json = global.json | ||
EndProjectSection | ||
EndProject | ||
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "{{packageName}}", "src\{{packageName}}\{{packageName}}.xproj", "{{packageGuid}}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{3B5990B3-40F1-4148-89B5-84AC71432557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{3B5990B3-40F1-4148-89B5-84AC71432557}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{3B5990B3-40F1-4148-89B5-84AC71432557}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{3B5990B3-40F1-4148-89B5-84AC71432557}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
{{packageGuid}} = {815BE834-0656-4C12-84A4-43F2BA4B8BDE} | ||
EndGlobalSection | ||
EndGlobal |
115 changes: 30 additions & 85 deletions
115
modules/swagger-codegen/src/main/resources/aspnet5/Startup.mustache
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,81 @@ | ||
{{>partial_header}} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using Microsoft.AspNet.Builder; | ||
using Microsoft.AspNet.Hosting; | ||
using System.Threading.Tasks; | ||
using System.Xml.XPath; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.AspNetCore.Hosting; | ||
using Microsoft.Extensions.Configuration; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using Microsoft.Extensions.PlatformAbstractions; | ||
using Newtonsoft.Json.Serialization; | ||
using Swashbuckle.SwaggerGen; | ||
using Swashbuckle.SwaggerGen.XmlComments; | ||
using Swashbuckle.Swagger.Model; | ||
using Swashbuckle.SwaggerGen.Annotations; | ||
|
||
namespace {{packageName}} | ||
{ | ||
public class Startup | ||
{ | ||
private readonly IHostingEnvironment _hostingEnv; | ||
private readonly IApplicationEnvironment _appEnv; | ||
public Startup(IHostingEnvironment env, IApplicationEnvironment appEnv) | ||
public IConfigurationRoot Configuration { get; } | ||
|
||
public Startup(IHostingEnvironment env) | ||
{ | ||
_hostingEnv = env; | ||
_appEnv = appEnv; | ||
// Set up configuration sources. | ||
var builder = new ConfigurationBuilder() | ||
.AddJsonFile("appsettings.json") | ||
.SetBasePath(env.ContentRootPath) | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) | ||
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) | ||
.AddEnvironmentVariables(); | ||
Configuration = builder.Build(); | ||
} | ||
|
||
public IConfigurationRoot Configuration { get; set; } | ||
|
||
|
||
|
||
// This method gets called by the runtime. Use this method to add services to the container. | ||
public void ConfigureServices(IServiceCollection services) | ||
{ | ||
string xmlComments = string.Format(@"{0}{4}artifacts{4}{1}{4}{2}{3}{4}{{packageName}}.xml", | ||
GetSolutionBasePath(), | ||
_appEnv.Configuration, | ||
_appEnv.RuntimeFramework.Identifier.ToLower(), | ||
_appEnv.RuntimeFramework.Version.ToString().Replace(".", string.Empty), | ||
Path.DirectorySeparatorChar); | ||
// Add framework services. | ||
services.AddMvc() | ||
.AddJsonOptions( | ||
opts => { opts.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); | ||
|
||
// Uncomment the following line to add Web API services which makes it easier to port Web API 2 controllers. | ||
// You will also need to add the Microsoft.AspNet.Mvc.WebApiCompatShim package to the 'dependencies' section of project.json. | ||
// services.AddWebApiConventions(); | ||
|
||
|
||
services.AddSwaggerGen(); | ||
services.ConfigureSwaggerDocument(options => | ||
|
||
services.ConfigureSwaggerGen(options => | ||
{ | ||
options.SingleApiVersion(new Info | ||
{ | ||
Version = "v1", | ||
Title = "{{packageName}}", | ||
Description = "{{packageName}} (ASP.NET 5 Web API 2.x)" | ||
Description = "{{packageName}} (ASP.NET Core 1.0)" | ||
}); | ||
|
||
options.OperationFilter(new ApplyXmlActionCommentsFixed(xmlComments)); | ||
}); | ||
|
||
services.ConfigureSwaggerSchema(options => { | ||
options.DescribeAllEnumsAsStrings = true; | ||
options.ModelFilter(new ApplyXmlTypeCommentsFixed(xmlComments)); | ||
options.DescribeAllEnumsAsStrings(); | ||
|
||
var comments = new XPathDocument($"{AppContext.BaseDirectory}{Path.DirectorySeparatorChar}{_hostingEnv.ApplicationName}.xml"); | ||
options.OperationFilter<XmlCommentsOperationFilter>(comments); | ||
options.ModelFilter<XmlCommentsModelFilter>(comments); | ||
}); | ||
|
||
} | ||
|
||
// 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) | ||
{ | ||
loggerFactory.MinimumLevel = LogLevel.Information; | ||
loggerFactory.AddConsole(Configuration.GetSection("Logging")); | ||
loggerFactory.AddDebug(); | ||
app.UseIISPlatformHandler(); | ||
app.UseMvc(); | ||
app.UseDefaultFiles(); | ||
app.UseStaticFiles(); | ||
app.UseMvc(); | ||
app.UseSwaggerGen(); | ||
app.UseSwagger(); | ||
app.UseSwaggerUi(); | ||
} | ||
|
||
// Taken from https://github.com/domaindrivendev/Ahoy/blob/master/test/WebSites/Basic/Startup.cs | ||
private string GetSolutionBasePath() | ||
{ | ||
var dir = Directory.CreateDirectory(_appEnv.ApplicationBasePath); | ||
while (dir.Parent != null) | ||
{ | ||
if (dir.GetDirectories("artifacts").Any()) | ||
return dir.FullName; | ||
dir = dir.Parent; | ||
} | ||
throw new InvalidOperationException("Failed to detect solution base path - artifacts not found. Did you run dnu pack --out artifacts?"); | ||
} | ||
|
||
// Entry point for the application. | ||
public static void Main(string[] args) => WebApplication.Run<Startup>(args); | ||
} | ||
|
||
|
||
// using Swashbuckle.SwaggerGen.XmlComments; | ||
public class ApplyXmlTypeCommentsFixed : ApplyXmlTypeComments | ||
{ | ||
public ApplyXmlTypeCommentsFixed() : base("") | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public ApplyXmlTypeCommentsFixed(string filePath): base(filePath) | ||
{ | ||
} | ||
} | ||
|
||
public class ApplyXmlActionCommentsFixed : ApplyXmlActionComments | ||
{ | ||
public ApplyXmlActionCommentsFixed() : base("") | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
public ApplyXmlActionCommentsFixed(string filePath): base(filePath) | ||
{ | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.