Change from netcore 1.1 to netcore 2.2

131 Views Asked by At

I have this old project which is in netcore 1.1 and I'm trying to run this project in my new Dev environment which is has netcore above 2.0. As you can guess when I'm trying to debug this old project my command line starts glowing like a christmas tree with all the known errors like

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\

and

- 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]

So my question is how can I change my project settings without installing netcore 1.1?

Also worth to mention is that I already know how to fix this problem when working in Visual Studio with a project solution(just changing the version in project properties will fix this problem) but this project is in Visual Studio Code and it has no solution file inside the project folder. I have already changed some settings in .csproj but without any luck.

This is what I have changed in .csproj From:

 <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> 

to:

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

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

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

</Project>
2

There are 2 best solutions below

0
Pavel Levchuk On

Delete /bin and /obj folders and import Microsoft.AspNetCore.App in your .csproj

<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>
0
Sanjeev On

Delete the bin and obj folders for all reference projects. Change the target framework to 2.2 and also update the nuget packages to .net core 2.2 compatible packages.

Just FYI , .net core 2.2, 3 are unsupported version, move to .net core 6 or above.