从netcore 1.1更改为netcore 2.2

时间:2019-01-10 14:01:38

标签: .net-core-2.0 .net-core-1.1

我有一个在netcore 1.1中的旧项目,我试图在我的新开发环境(netcore在2.0以上)中运行该项目。您可以猜测,当我尝试调试该旧项目时,命令行开始像圣诞树一样发光,并出现所有已知错误,例如

It was not possible to find any compatible framework version
    The specified framework 'Microsoft.NETCore.App', version '1.1.2' was not found.
      - Check application dependencies and target a framework version installed at:
      C:\Program Files\dotnet\


- The following versions are installed:
      2.1.6 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      2.1.7 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
      2.2.0 at [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

所以我的问题是,如何在不安装netcore 1.1的情况下更改项目设置?

还有一个值得一提的是,我已经知道在使用带有项目解决方案的Visual Studio时如何解决此问题(只需更改项目属性中的版本将解决此问题),但是该项目位于Visual Studio Code中,并且具有项目文件夹中没有解决方案文件。 我已经更改了.csproj中的某些设置,但没有任何运气。

这是我在.csproj中所做的更改:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" 
Version="1.1.1" />
  </ItemGroup>

</Project> 

收件人:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

</Project>

1 个答案:

答案 0 :(得分:0)

删除/bin/obj文件夹并在您的.csproj中导入Microsoft.AspNetCore.App

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
    <LangVersion>latest</LangVersion>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Api.Analyzers" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
  </ItemGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

</Project>