001 Updating-To - Net-7
001 Updating-To - Net-7
Net 7
1. Update the API.csproj
Update the TargetFramework to net7.0 and add the ImplicitUsings tag as well as the Nullable but
set to disabled in the API.csproj
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>e03e58b7-54a5-4902-a8df-e5e9a2b419fe</UserSecretsId>
</PropertyGroup>
2. Update the other packages in the API.csproj to the latest versions. This is how it looks at the
end of the course:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>disable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>e03e58b7-54a5-4902-a8df-e5e9a2b419fe</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="CloudinaryDotNet" Version="1.20.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="7.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.1" />
<PackageReference Include="Stripe.net" Version="41.6.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
3. Update the SwaggerUI middleware to persist the token we use as this configuration will save
the bearer token into localStorage:
if (env.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.ConfigObject.AdditionalItems.Add("persistAuthorization", "true");
Updating to .Net 7 1
});
}
4. Update 2 properties in the Order.cs and add the Required tag to the ShippingAddress property
to avoid a warning we will receive when using EF 7 and owned entities, and set the OrderDate
to use DateTime.UtcNow instead of DateTime.Now which is required for the latest versions of
Postgres
using System.ComponentModel.DataAnnotations;
namespace API.Entities.OrderAggregate
{
public class Order
{
public int Id { get; set; }
public string BuyerId { get; set; }
[Required]
public ShippingAddress ShippingAddress { get; set; }
public DateTime OrderDate { get; set; } = DateTime.Now;
public List<OrderItem> OrderItems { get; set; }
public long Subtotal { get; set; }
public long DeliveryFee { get; set; }
public OrderStatus OrderStatus { get; set; } = OrderStatus.Pending;
public string PaymentIntentId { get; set; }
7. If you have got to the stage of using Stripe then check to see if you need to upgrade your
version of the API in Stripe.net
Updating to .Net 7 2
If there is an upgrade available then choose the option to do this if you have updated the
Stripe.Net nuget package in your app.
Updating to .Net 7 3