首页 > 解决方案 > 使用 .NET Core 3.1 构建需要更多时间和内存(.NET Core 主机和 Visual Studio 代码)

问题描述

我在 Visual Studio Code 编辑器中使用 .NET Core 3.1.2。

在我执行dotnet publishor之后dotnet build

构建应用程序需要更多时间。

有时构建会在一分钟内完成。大多数情况下,完成构建过程需要很长时间。

以下是我正在使用的架构:

文件项目.WebAPI

 <ItemGroup>
    <ProjectReference Include="..\Project.Persistence\Project.Persistence.csproj" />
    <ProjectReference Include="..\Project.Application\Project.Application.csproj" />
  </ItemGroup>

文件项目.应用程序

 <ItemGroup>
    <ProjectReference Include="..\Project.Domain\Project.Domain.csproj" />
    <ProjectReference Include="..\Project.Persistence\Project.Persistence.csproj" />
    <ProjectReference Include="..\Project.Infrastructure\Project.Infrastructure.csproj" />
  </ItemGroup>

文件项目.域

没有其他图书馆提到这一点。

文件项目.持久性

    <ProjectReference Include="..\Project.Domain\Project.Domain.csproj" />
  </ItemGroup>

我已经检查了构建时间需要更多的地方。

Project.Domain库中,构建需要更多时间(几乎 10 分钟)

Task Scheduler中,.NET Core Host占用了更多内存。

标签: .netvisual-studio.net-core

解决方案


持久性项目具有所有迁移文件。

我注意到该文件夹​​有 90 多个迁移文件。

在我使用以下步骤删除所有文件后,

Step 1: Delete all the migration scripts in the Migrations folder.

Step 2: In the package manager console: run

        PM> Add-Migration InitialCreate

Step 3: Delete the code for both the Up() and Down() methods. Before you do this, keep those methods saved elsewhere as we will need them again in step 5.

Step 4: Run:

        PM> Update-Database

It'll insert a new record into __EFMigrationsHistory table.

Step 5: After that, fill the above migration scripts (i.e., ..._InitialCreate) Up() and Down() method from the content kept in a safe place from Step 3.

构建问题已解决。


推荐阅读