将我的ASP.NET网站从.NET 2.2 Core Preview 2升级到.NET 2.2 Core Preview 3

I've recently returned from a month in South Africa and I was looking to unwind while the jetlagged kids sleep. I noticed that .NET Core 2.2 Preview 3 came out while I wasn't paying attention. My podcast site runs on .NET Core 2.2 Preview 2 so I thought it'd be interesting to update the site. That means I'd need to install the new SDK, update the project references, ensure it builds in Azure DevOps's CI/CD Pipeline, AND deploys and runs in Azure.

我最近刚从南非一个月回来,所以我想放松一下那些身手不稳的孩子睡觉的时候。 我注意到.NET Core 2.2预览版3出炉时我没有注意。 我的播客站点在.NET Core 2.2 Preview 2上运行,因此我认为更新站点会很有趣。 这意味着我需要安装新的SDK,更新项目引用,确保它构建在Azure DevOps的CI / CD管道中,并在Azure中部署和运行。

Let's see how it goes. I'm a little out of it but I'm writing this blog post AS I DO THE WORK so you'll see my train of thought with no editing.

让我们看看进展如何。 我有点不高兴了,但是我正在写这篇博客,因为我在做工作,所以您将看到我的思路而无需编辑。

Ok, what version of .NET Core does this machine have?

好的,这台计算机有什么版本的.NET Core?

C:\Users\scott> dotnet --version
2.2.100-preview2-009404
C:\Users\scott> dotnet tool update --global dotnet-outdated
Tool 'dotnet-outdated' was successfully updated from version '2.0.0' to version '2.1.0'.

Looks like I'm on Preview 2 as I guessed. I'll take a moment and upgrade one Global Tool I love - dotnet-outdated - in case it's been updated since I've been out. Looks like it has a minor update. Dotnet Outdated is a great utility for checking references and you should absolutely be using it or another tool like NuKeeper or Dependabot.

我猜好像我正在预览2中。 我将花一点时间升级一个我喜欢的全球工具-dotnet已过时-以防自从我离开以后就进行了更新。 看起来它有较小的更新。 Dotnet过时了是用于检查引用的好工具,您绝对应该使用它或其他工具,例如NuKeeperDependabot

I'll head over to https://www.microsoft.com/net/download/dotnet-core/2.2 and get .NET Core 2.2 Preview 3. I'm building on Windows but I may want to update my Linux (WSL) install and Docker images later.

我将转到https://www.microsoft.com/net/download/dotnet-core/2.2并获取.NET Core 2.2 Preview 3 。 我在Windows上构建,但稍后可能要更新Linux(WSL)安装和Docker映像。

All right, installed. Check it with dotnet --version to confirm it's correct:

好的,已安装。 用dotnet --version检查它,以确认它是正确的:

C:\Users\scott> dotnet --version
2.2.100-preview3-009430

Let's try to build my podcast website. Note that it consists of two projects, the main website on ASP.NET Core, and Unit Tests with XUnit and Selenium.

让我们尝试建立我的播客网站。 请注意,它由两个项目组成,ASP.NET Core上的主要网站,以及XUnit和Selenium的单元测试

D:\github\hanselminutes-core [main ≡]> dotnet build
Microsoft (R) Build Engine version 15.9.8-preview+g0a5001fc4d for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Restoring packages for D:\github\hanselminutes-core\hanselminutes.core.tests\hanselminutes.core.tests.csproj...
Restore completed in 80.05 ms for D:\github\hanselminutes-core\hanselminutes.core.tests\hanselminutes.core.tests.csproj.
Restore completed in 25.4 ms for D:\github\hanselminutes-core\hanselminutes.core\hanselminutes-core.csproj.
D:\github\hanselminutes-core\hanselminutes.core.tests\hanselminutes.core.tests.csproj : error NU1605: Detected package downgrade: Microsoft.AspNetCore.App from 2.2.0-preview3-35497 to 2.2.0-preview2-35157. Reference the package directly from the project to select a different version. [D:\github\hanselminutes-core\hanselminutes-core.sln]

The dotnet build fails, which make sense, because it's saying hey, you're asking for 2.2 Preview 2 but I've got Preview 3 all ready for you!

dotnet构建失败,这很有道理,因为这是说嘿,您要使用2.2 Preview 2,但我已经为您准备了Preview 3!

Detected package downgrade: Microsoft.AspNetCore.App from 2.2.0-preview3-35497 to 2.2.0-preview2-35157

Let's see what "dotnet outdated" says about this!

让我们看看“ dotnet过时”对此有何评论!

dotnet outdated says there's a few packages I need to update

Cool! I love these dependency tools and the community around them. You can see that it's noticed the Preview 2 -> Preview 3 opportunity, as well as a few other smaller minor or patch version bumps.

凉! 我喜欢这些依赖工具以及周围的社区。 您会发现它注意到了Preview 2-> Preview 3的机会,以及其他一些较小的次要版本或补丁版本。

I can run dotnet outdated -u to automatically update the references, but I'll want to treat the "reference" of "Microsoft.AspNetCore.App" a little differently and use implicit versioning. You don't want to include a specific version - as I did - for this package.

我可以运行过时的dotnet -u来自动更新引用,但是我想对“ Microsoft.AspNetCore.App”的“引用”进行一些不同的处理,并使用隐式版本控制。 您不希望像我一样为该程序包包含特定版本。

Per the docs for .NET Core 2.1 and up:

根据.NET Core 2.1及更高版本的文档

Remove the "Version" attribute on the package reference to Microsoft.AspNetCore.App. Projects which use <Project Sdk="Microsoft.NET.Sdk.Web"> do not need to set the version. The version will be implied by the target framework and selected to best match the way ASP.NET Core 2.1 works. (See below for more information.)

删除对Microsoft.AspNetCore.App的程序包引用上的“版本”属性。 使用<Project Sdk="Microsoft.NET.Sdk.Web">不需要设置版本。 该版本将由目标框架隐含并选择为与ASP.NET Core 2.1的工作方式最匹配。 (请参阅下面的详细信息。)

Doing this also fixes the build because it picks up the latest 2.2 SDK automatically! Now I'll run my Unit Tests (with code coverage) and see how it works. Cool all tests pass (including Selenium).

这样做还可以修复构建,因为它会自动获取最新的2.2 SDK! 现在,我将运行单元测试(代码覆盖率),并查看其工作原理。 冷却所有测试通过(包括Selenium)。

88% Code Coverage

It builds locally, will it build in Azure DevOps when I check it in to GitHub?

它在本地构建,当我签入GitHub时会在Azure DevOps中构建吗?

Azure DevOps

I added a .NET Core SDK installer step when I set up my Azure Dev Ops Pipeline. This is where I'm explicitly installing a Preview version of the .NET Core SDK.

设置Azure Dev Ops管道时,添加了.NET Core SDK安装程序步骤。 这是我明确安装.NET Core SDK预览版的地方。

While I'm in here I noticed the Azure DevOps pipeline was using NuGet 4.4.1. I run "nuget update -self" on my local machine and got 4.7.1, so I updated that version as well to make the CI/CD pipeline reflect my own machine.

当我在这里时,我注意到Azure DevOps管道正在使用NuGet 4.4.1。 我在本地计算机上运行“ nuget update -self”,并获得了4.7.1,所以我也更新了该版本,以使CI / CD管道反映我自己的计算机。

Now I'll git add, git commit (using verified/signed GitHub commits with my PGP Key and Yubikey):

现在,我将进行git add,git commit(使用带有我的PGP Key和Yubikey的经过验证/签名的GitHub提交):

D:\github\hanselminutes-core [main ≡ +0 ~2 -0 !]> git add .
D:\github\hanselminutes-core [main ≡ +0 ~2 -0 ~]> git commit -m "bump to 2.2 Preview 3"
[main 7a84bc7] bump to 2.2 Preview 3
2 files changed, 16 insertions(+), 13 deletions(-)

Add in a Git Push...and I can see the build start in Azure DevOps:

添加一个Git Push ...,我可以在Azure DevOps中看到构建开始:

CI/CD pipeline build starting

Cool. While that's building, I'll make sure my existing Azure App Service (website) installation is ready to receive the deployment (assuming the build succeeds). Since I'm using an ASP.NET Core Preview build I'll want to make sure I have the Preview Site Extension installed, per the docs.

凉。 在构建过程中,我将确保现有的Azure应用服务(网站)安装已准备就绪,可以接收部署(假设构建成功)。 由于我使用的是ASP.NET Core预览版本,因此我要确保每个文档都已安装了预览站点扩展

If I visit the Site Extensions menu item in the Azure Portal I can see I've got .NET Core 2.2 Preview 2, but there's an update available, as expected.

如果我访问Azure门户中的“站点扩展”菜单项,则可以看到我已经拥有.NET Core 2.2预览版2,但是正如预期的那样,有可用的更新。

Update Available

I'll click this extension and then click Update. This extension's job is to make sure the App Service gets Preview versions of the .NET Core SDK. Only released (GA - general availability) SDKs are installed by default.

我将单击此扩展名,然后单击“更新”。 此扩展程序的工作是确保App Service获得.NET Core SDK的预览版。 默认情况下,仅安装发布的(GA-通用)SDK。

OK, .NET Core 2.2 is all updated in Azure, so I'll confirm that it's deployed as well in Azure DevOps. Yes, I'm deploying into Production without a net. Seriously, though, if there is an issue I'll just rollback. If I was deeply serious about downtime I'd be doing all this in Staging.

好的,.NET Core 2.2已在Azure中全部更新,因此我将确认它也在Azure DevOps中进行了部署。 是的,我没有网络就可以部署到生产环境中。 严重的是,如果出现问题,我将回滚。 如果我非常认真地考虑停机时间,那么我将在暂存中进行所有这些操作。

image

Successful local test, successful CI/SD build and test, successful deployment, and the site is back up now running on ASP.NET Core 2.2 Preview 3. It took about 45 min to do the work while simultaneously taking these screenshots and writing this blog post during the slow parts.

成功的本地测试,成功的CI / SD构建和测试,成功的部署以及站点现在都在ASP.NET Core 2.2 Preview 3上运行。 完成这项工作大约需要45分钟,同时获取这些屏幕截图并在较慢的部分中撰写此博客文章。

Good night everyone!

各位晚安!

翻译自: https://www.hanselman.com/blog/updating-my-aspnet-website-from-net-22-core-preview-2-to-net-22-core-preview-3

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值