Skip to content

Commit 7aebbbd

Browse files
committed
Updating csharp scenario
1 parent 3411647 commit 7aebbbd

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

csharp/aspnetcore/Dockerfile

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
FROM microsoft/aspnetcore
1+
FROM microsoft/dotnet:2.1-sdk-stretch AS build
2+
WORKDIR /app
23

3-
# install sdk
4-
# @see https://www.microsoft.com/net/learn/get-started/linux/debian9
5-
RUN apt-get -qq update
6-
RUN apt-get -qy install curl libunwind8 gettext apt-transport-https gnupg
7-
RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
8-
RUN mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
9-
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-debian-stretch-prod stretch main" > /etc/apt/sources.list.d/dotnetdev.list'
10-
RUN apt-get -qq update
11-
RUN apt-get -qy install dotnet-sdk-2.1.103 libuv1-dev
4+
# copy csproj and restore as distinct layers
5+
COPY *.csproj .
6+
RUN dotnet restore
127

13-
WORKDIR /usr/src/app
8+
# copy everything else and build app
9+
COPY . .
10+
RUN dotnet publish -c release -o out
1411

15-
COPY Program.cs Startup.cs aspnetcore.csproj ./
12+
FROM microsoft/dotnet:2.1-aspnetcore-runtime-stretch-slim AS runtime
13+
WORKDIR /app
14+
COPY --from=build /app/out ./
1615

17-
RUN dotnet build --configuration Release
16+
ENV ASPNETCORE_URLS http://*:3000
17+
ENV COMPlus_TieredCompilation 1
1818

19-
EXPOSE 3000
20-
CMD dotnet run bin/Release/netcoreapp2.0/aspnetcore.dll
19+
ENTRYPOINT ["dotnet", "aspnetcore.dll"]

csharp/aspnetcore/Program.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using System.IO;
2+
using Microsoft.AspNetCore;
23
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.Extensions.Logging;
35

46
namespace aspnetcore
57
{
6-
public class Program
8+
public class Program
79
{
810
public static void Main(string[] args)
911
{
10-
var host = new WebHostBuilder()
11-
.UseKestrel()
12-
.UseStartup<Startup>()
13-
.UseUrls("http://0.0.0.0:3000")
14-
.Build();
15-
16-
host.Run();
12+
CreateWebHostBuilder(args).Build().Run();
1713
}
14+
15+
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
16+
WebHost.CreateDefaultBuilder(args)
17+
.ConfigureLogging(config => config.ClearProviders())
18+
.UseStartup<Startup>();
1819
}
1920
}

csharp/aspnetcore/Startup.cs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using Microsoft.AspNetCore.Builder;
22
using Microsoft.AspNetCore.Http;
3-
using Microsoft.Extensions.DependencyInjection;
43
using Microsoft.AspNetCore.Routing;
4+
using Microsoft.Extensions.DependencyInjection;
55

66
namespace aspnetcore
77
{
@@ -14,22 +14,21 @@ public void ConfigureServices(IServiceCollection services)
1414

1515
public void Configure(IApplicationBuilder app)
1616
{
17-
var routeBuilder = new RouteBuilder(app);
18-
19-
routeBuilder.MapGet("", context => {
20-
return context.Response.WriteAsync("");
21-
});
17+
app.UseRouter(routes =>
18+
{
19+
routes.MapGet("", context => {
20+
return context.Response.WriteAsync("");
21+
});
2222

23-
routeBuilder.MapGet("user/{id}", context => {
24-
return context.Response.WriteAsync($"{context.GetRouteValue("id")}");
25-
});
23+
routes.MapGet("user/{id}", context => {
24+
var id = context.GetRouteValue("id").ToString();
25+
return context.Response.WriteAsync(id);
26+
});
2627

27-
routeBuilder.MapPost("user", context => {
28-
return context.Response.WriteAsync("");
28+
routes.MapPost("user", context => {
29+
return context.Response.WriteAsync("");
30+
});
2931
});
30-
31-
var routes = routeBuilder.Build();
32-
app.UseRouter(routes);
3332
}
3433
}
3534
}
Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
23
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<TargetFramework>netcoreapp2.0</TargetFramework>
4+
<TargetFramework>netcoreapp2.1</TargetFramework>
55
</PropertyGroup>
6+
67
<ItemGroup>
7-
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
8-
<PackageReference Include="Microsoft.AspNetCore.Routing" Version="1.1.2" />
8+
<PackageReference Include="Microsoft.AspNetCore.App" />
99
</ItemGroup>
10-
</Project>
10+
11+
</Project>

0 commit comments

Comments
 (0)