Richard Watts
Richard Watts

Reputation: 1004

Convert .Net Core to .Net Framework

I have a .Net Core project web project, and for various reasons want to convert it to a .Net Framework project.

Is there an easy way to do this, or do I have to start again and import the code from the previous projects

Upvotes: 77

Views: 88760

Answers (10)

Chan Kin Sung
Chan Kin Sung

Reputation: 71

For me, I just change net461 and reload the whole program. It just works.

You may also need to go to attributes, select target framework as .NET Framework 4.6.1 if you see the selection is blank.

Visual Studio can automatically recognize my change is .NET framework rather than .NET Core, the settings appearance also change accordingly.

Upvotes: 0

I had only a handful of source files. For me it worked best by

  1. Closing Visual Studio 2022
  2. Renaming away the solution folder
  3. Creating a new Visual Studio solution of type "WPF App (.NET Framework)" with the original folder name and same project name
  4. Copying all *.xaml. *.xaml.cs and *.cs from the old project to the new, not touching *.sln, *.csproj and *.config.
  5. Project->Add Existing Item… and adding the copied items
  6. Adding all the special references.

That rebuilt all without a complaint.

Upvotes: 0

Joshua Schlichting
Joshua Schlichting

Reputation: 3450

There's lots of similar answers here, but I didn't see one that was quite what I ended up doing, so I'd like to leave this here just in case someone else is in the same shoes.

Just to be clear, my project was a console program. So, if you're trying to use this answer for something else, your mileage may vary.

In your .csproj file, inside of the <PropertyGroup></PropertyGroup> tag, modify <TargetFramework> to reflect the following:

<TargetFramework>net461</TargetFramework>

Now, in this example, I was using v4.6.1. I can only assume that you'll plug in your version behind the word "net", without the periods. Good luck!

Upvotes: 18

lemon
lemon

Reputation: 71

add below in csproj

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
  </PropertyGroup>

Upvotes: 0

Pawan
Pawan

Reputation: 43

My .net standard project is relatively simple with few Nuget packages. I just changed

<TargetFramework>netstandard2.0</TargetFramework>

TO

<TargetFramework>**net461**</TargetFramework> under PropertyGroup section of .csproj file and this did the job for me.. Thanks to Brandon Barkley for your answer in the comments.

Upvotes: 0

Greg Gum
Greg Gum

Reputation: 38089

This worked for me in VS2017:

Start with .net core web project template.

Edit *.csproj so it looks like this:

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

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.CookiePolicy" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.RazorPages" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.1.1" />
  </ItemGroup>

</Project>

Save and close.

Try running project.

The PackReferences is just the NuGet files, and you can add them through the GUI if the versions are different from mine above.

Upvotes: 21

VorTechS
VorTechS

Reputation: 493

In my version of Visual Studio 2017 (15.6.2) after 'Unloading the Project', right-clicking and selecting 'Edit <your project file>, I had to:

  1. Add the node:

    <TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>

  2. Delete the nodes:

    <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>

    <TargetPlatformVersion Condition=" '$(TargetPlatformVersion)' == '' ">10.0.16299.0</TargetPlatformVersion>

    <TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>

    <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>

Upvotes: 1

Sai Kiran
Sai Kiran

Reputation: 1

There are several steps that you need to do, in order to achieve this.

  1. Firstly right click on the .csproj file and add the following

   <TargetFrameworks>netstandard2.0;netcoreapp2.0;net35;</TargetFrameworks>
        <RuntimeIdentifiers>win7-x86;win7-x64</RuntimeIdentifiers> <EnableDefaultCompileItems>false</EnableDefaultCompileItems>

  1. Once you have made these changes reload the project and build it.
  2. This will generate the .dll files and Nuget package for this build in the Debug/Release folder of the project.
  3. Add these .dll to the nuget and access these projects from nuget.

Try the above steps. This should work.

Upvotes: 0

Brandon
Brandon

Reputation: 91

None of the answers here worked for me. In .Net Core 2 the project.json file no longer exists. However, I did solve this problem using the following steps.

1) I removed all nuget packages from my existing project.

2) I created a separate .net core web app project, targeting .net 4.61. This was to get the default nuget packages.

3) I edited the temporary project's .csproj file, copied all the PackageReference nodes inside ItemGroup, and pasted them into my existing projects .csproj file.

4) Edited the TargetFramework node (inside PropertyGroup) from "netstandard2" to "net461"

I had a few package changes to track down and resolve, but otherwise I was able to run.

Upvotes: 9

Aleksandr Zolotov
Aleksandr Zolotov

Reputation: 1100

I have loaded core project to the VS 2017 RC Community and open *.csproj in text editor.

Just delete teg

<RuntimeFrameworkVersion>

and replace

<TargetFramework>netcoreapp1.1</TargetFramework>

to

<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>

And after all in project properties set to any another framework and reset back (VS reload and repair *.csproj file).

Upvotes: 34

Related Questions