Skip to content

Commit

Permalink
Migrate to dotnet 8 #198
Browse files Browse the repository at this point in the history
  • Loading branch information
TheAxelander committed Nov 26, 2023
1 parent 3958d0d commit c875588
Show file tree
Hide file tree
Showing 26 changed files with 330 additions and 290 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker-image-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ master ]

env:
DOTNET_VERSION: '7.0.103' # The .NET SDK version to use
DOTNET_VERSION: '8.0.100' # The .NET SDK version to use

jobs:
test:
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/docker-image-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
branches: [ pre-release ]

env:
DOTNET_VERSION: '7.0.103' # The .NET SDK version to use
DOTNET_VERSION: '8.0.100' # The .NET SDK version to use

jobs:
test:
Expand Down Expand Up @@ -56,4 +56,5 @@ jobs:
push: true
tags: axelander/openbudgeteer:pre-release
# file: OpenBudgeteer.Blazor/Dockerfile
platforms: linux/amd64
platforms: linux/arm64,linux/amd64
# platforms: linux/amd64
10 changes: 4 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR /app
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
ENV DOTNET_RUNNING_IN_CONTAINER=true
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false
EXPOSE 80
EXPOSE 443
RUN apk add --no-cache icu-libs icu-data-full

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
WORKDIR /src
COPY . .
RUN dotnet restore -r linux-musl-x64
RUN dotnet restore
WORKDIR "/src/OpenBudgeteer.Blazor"
RUN dotnet publish "OpenBudgeteer.Blazor.csproj" -r linux-musl-x64 --no-self-contained -c Release -o /app/publish
RUN dotnet publish "OpenBudgeteer.Blazor.csproj" --no-self-contained -c Release -o /app/publish

FROM base AS final
WORKDIR /app
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.API/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine AS base
FROM mcr.microsoft.com/dotnet/aspnet:8.0-alpine AS base
WORKDIR /api
ENV DOTNET_CLI_TELEMETRY_OPTOUT=1
ENV DOTNET_RUNNING_IN_CONTAINER=true
Expand All @@ -7,7 +7,7 @@ EXPOSE 80
EXPOSE 443
RUN apk add --no-cache icu-libs icu-data-full

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src
COPY ["OpenBudgeteer.API/OpenBudgeteer.API.csproj", "OpenBudgeteer.API/"]
RUN dotnet restore "OpenBudgeteer.API/OpenBudgeteer.API.csproj"
Expand Down
4 changes: 2 additions & 2 deletions OpenBudgeteer.API/OpenBudgeteer.API.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand All @@ -25,7 +25,7 @@
<ItemGroup>
<PackageReference Include="Asp.Versioning.Http" Version="7.1.0" />
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.1.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.14" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>

Expand Down
5 changes: 0 additions & 5 deletions OpenBudgeteer.API/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,3 @@ await recurringTransactionService.CreatePendingBankTransactionAsync(yearMonth))
//}

app.Run();

internal record WeatherForecast(DateTime Date, int TemperatureC, string? Summary)
{
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
89 changes: 78 additions & 11 deletions OpenBudgeteer.Blazor/App.razor
Original file line number Diff line number Diff line change
@@ -1,11 +1,78 @@

<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
@using Microsoft.Extensions.Hosting
@using OpenBudgeteer.Core.Common
@inject IHostEnvironment Env

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>OpenBudgeteer</title>
<base href="/" />
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:ital,wght@0,200;0,300;0,400;0,600;0,700;0,900;1,200;1,300;1,400;1,600;1,700;1,900&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/bootstrap/@AppSettings.Theme/bootstrap.min.css" />
<link rel="stylesheet" href="css/bootstrap/bootstrap-icons.css">
<link href="css/site.css" rel="stylesheet" />
<link href="css/custom.css" rel="stylesheet"/>
<link href="css/StickyFooter.css" rel="stylesheet" />
<style>
/* Hide Spinner for number Input fields*/
/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
-webkit-appearance: none;
margin: 0;
}
/* Firefox */
input[type=number] {
-moz-appearance: textfield;
}
</style>
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />

<div id="blazor-error-ui" style="z-index: 1">
@if (Env.IsDevelopment())
{
<text>
An unhandled exception has occurred. See browser dev tools for details.
</text>
}
else
{
<text>
An error has occurred. This app may no longer respond until reloaded.
</text>
}
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

<footer class="footer" style="z-index: 2">
<div style="text-align: center">
<span class="text-muted">
App Icons by <a href="https://icons8.com" target="_blank">Icons8</a>
</span>
</div>
</footer>

<script src="_framework/blazor.web.js"></script>
<script src="js/bootstrap/bootstrap.bundle.min.js"></script>
<script src="js/custom.js"></script>

<!-- Reference the included moment.js javascript file. -->
<script src="_content/ChartJs.Blazor/moment-with-locales.min.js"></script>

<!-- Reference the included ChartJs javascript file. -->
<script src="_content/ChartJs.Blazor/Chart.min.js"></script>

<!-- This is the glue between the C# code and the ChartJs charts -->
<script src="_content/ChartJs.Blazor/ChartJsBlazorInterop.js"></script>

<!-- Some styling -->
<link rel="stylesheet" href="_content/ChartJs.Blazor/ChartJSBlazor.css" />
</body>
</html>
12 changes: 6 additions & 6 deletions OpenBudgeteer.Blazor/OpenBudgeteer.Blazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>c146cdfd-f78c-4fb3-8be0-4e15e589371a</UserSecretsId>
<InvariantGlobalization>false</InvariantGlobalization>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
Expand All @@ -11,14 +11,14 @@

<ItemGroup>
<PackageReference Include="ChartJs.Blazor" Version="1.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.5">
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.17.0" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.3.1.21360" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Tewr.Blazor.FileReader" Version="3.3.2.23201" />
</ItemGroup>

<ItemGroup>
Expand Down
8 changes: 0 additions & 8 deletions OpenBudgeteer.Blazor/Pages/_Host.cshtml

This file was deleted.

73 changes: 0 additions & 73 deletions OpenBudgeteer.Blazor/Pages/_Layout.cshtml

This file was deleted.

74 changes: 53 additions & 21 deletions OpenBudgeteer.Blazor/Program.cs
Original file line number Diff line number Diff line change
@@ -1,28 +1,60 @@
using System;
using Microsoft.AspNetCore.Hosting;
using System.Text;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using OpenBudgeteer.Blazor;
using OpenBudgeteer.Core.Common;
using OpenBudgeteer.Core.Data;
using OpenBudgeteer.Core.Data.Contracts.Services;
using OpenBudgeteer.Core.Data.Entities;
using OpenBudgeteer.Core.Data.Services;
using OpenBudgeteer.Core.ViewModels.Helper;
using Tewr.Blazor.FileReader;

namespace OpenBudgeteer.Blazor;
const string APPSETTINGS_CULTURE = "APPSETTINGS_CULTURE";
const string APPSETTINGS_THEME = "APPSETTINGS_THEME";

public class Program
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddLocalization();
builder.Services.AddRazorPages();
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
builder.Services.AddFileReaderService();
builder.Services.AddHostedService<HostedDatabaseMigrator>();
builder.Services.AddDatabase(builder.Configuration);
builder.Services.AddScoped<IServiceManager, ServiceManager>(x => new ServiceManager(x.GetRequiredService<DbContextOptions<DatabaseContext>>()));
builder.Services.AddScoped(x => new YearMonthSelectorViewModel(x.GetRequiredService<IServiceManager>()));

Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); // Required to read ANSI Text files

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
public static void Main(string[] args)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
CreateHostBuilder(args).Build().Run();
}

private static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureServices(service =>
{
service.AddHostedService<HostedDatabaseMigrator>();
})
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});


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.UseRequestLocalization(builder.Configuration.GetValue<string>(APPSETTINGS_CULTURE, "en-US") ?? "en-US");
AppSettings.Theme = builder.Configuration.GetValue(APPSETTINGS_THEME, "Default") ?? "Default";

//app.UseRouting();
app.UseAntiforgery();
/*app.UseEndpoints(endpoints =>
{
endpoints.MapRazorComponents<App>().AddInteractiveServerRenderMode();
});*/
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();

app.Run();

10 changes: 10 additions & 0 deletions OpenBudgeteer.Blazor/Routes.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
Loading

0 comments on commit c875588

Please sign in to comment.