【问题标题】:Upgrading to ASP.Net Core 2.0升级到 ASP.Net Core 2.0
【发布时间】:2018-01-28 22:58:26
【问题描述】:

从 ASP.Net Core 1.X 升级到 2.0 (https://docs.microsoft.com/en-us/aspnet/core/migration/1x-to-2x/)

我遇到过以下疑惑/问题:

第一:元包

现在

<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
</ItemGroup>

我们获得了项目所需的所有参考资料。但是我不知道我是否应该排除Microsoft.VisualStudio.Web的包

我对这些参考有怀疑

<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="2.0.0" />

我看到 metapackage 包含这个:Microsoft.VisualStudio.Web.BrowserLink" Version

我是否应该只排除那个并保留另外两个(CodeGeneration.Design 还有Microsoft.VisualStudio.Web.CodeGenerators.Mvcthere?

第二个:错误

我遇到了各种各样的错误

第一个说metapackage安装的包与aspnetcore2.0不兼容有人遇到过吗?有关如何处理此问题的任何建议?

第二次给出这个错误信息:

“Microsoft”命名空间中不存在“EntityFrameworkCore”命名空间的类型或名称(是否缺少任何程序集引用?)

提前致谢!

决赛

这就是我的 csproj 看起来像 atm 的样子:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
  </PropertyGroup>

  <ItemGroup>
    <Compile Remove="wwwroot\lib\kendo-ui-core\**" />
    <Content Remove="wwwroot\lib\kendo-ui-core\**" />
    <EmbeddedResource Remove="wwwroot\lib\kendo-ui-core\**" />
    <None Remove="wwwroot\lib\kendo-ui-core\**" />
  </ItemGroup>

  <ItemGroup>
    <Content Include="wwwroot\css\bootstrap-lumen.css" />
    <Content Include="wwwroot\css\bootstrap-sand.css" />
    <Content Include="wwwroot\css\bootstrap-sand.min.css" />
    <Content Include="wwwroot\js\application-role-index.js" />
    <Content Include="wwwroot\js\family-index.js" />
    <Content Include="wwwroot\js\jquery-3.2.1.min.js" />
    <Content Include="wwwroot\js\modal-action-store.js" />
    <Content Include="wwwroot\js\populate-district.js" />
    <Content Include="wwwroot\js\store-index.js" />
    <Content Include="wwwroot\js\type-index.js" />
    <Content Include="wwwroot\js\user-index.js" />
    <Content Include="wwwroot\js\jquery.filtertable.min.js" />
    <Content Include="wwwroot\js\machine-index.js" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Bootstrap.v3.Datetimepicker" Version="4.17.45" />
    <PackageReference Include="Bootstrap.v3.Datetimepicker.CSS" Version="4.17.45" />
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="NuGet.CommandLine" Version="4.1.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
  </ItemGroup>

</Project>

【问题讨论】:

标签: asp.net .net asp.net-mvc


【解决方案1】:

如果您使用的是 .NET Core,请尝试安装 NuGet 包:

Microsoft.AspNetCore.All

如果您使用的是 .NET Framework,那么the process is different

对于 .NET Framework,我建议使用普通的 Visual Studio 2017 模板创建一个新的 ASP.NET Core 项目。这将为您提供使用 .NET Framework 创建 ASP.NET Core 2.0 项目的选项,并且您可以选择目标版本。然后,您需要将内容迁移到项目中。这是一个手动过程,因为项目文件格式非常不同。一旦完成,你会得到一些编译错误,因为类已经移动到新的命名空间等等。但是,让它工作起来并不难。此方法可确保您也不会拉取任何垃圾 NuGet 包。您将一帆风顺。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-02
    • 1970-01-01
    • 2018-08-03
    • 1970-01-01
    相关资源
    最近更新 更多