74

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

Richard Watts
  • 954
  • 2
  • 8
  • 21
  • There is no automatic way to do this and I seriously doubt there ever will be. – DavidG Mar 06 '17 at 10:25
  • maybe this link could help you: https://blogs.msdn.microsoft.com/dotnet/2016/02/10/porting-to-net-core/ – raBinn Mar 06 '17 at 10:26
  • @raBinn That's not what OP is asking for. – DavidG Mar 06 '17 at 10:28
  • Ok, what would be the best way forward. Should I need a new project, or could I replace the project files and asp.net core references with asp.net references – Richard Watts Mar 06 '17 at 10:34
  • Start a new project and begin copying code. Almost everything is different so you're much better off just going in fresh. – DavidG Mar 06 '17 at 10:35
  • 1
    Do you want to revert back to ASP.NET MVC 5 or you want to be able to use full .NET Framework? – Marcin Zablocki Mar 06 '17 at 10:37
  • 2
    Your question states .NET Core to .NET Framework. That's possible with target monikers by changing `netcoreapp1.0` to `net462` or `net451` or alike. `ASP.NET Core` to `ASP.NET MVC 5` isn't that easy. I've done it for a SharePoint Add-In and I ended up copying all the code to a new project that targets `ASP.NET MVC 5`. – koelkastfilosoof Mar 06 '17 at 10:51
  • I'm already targeting net451, and would need to change from ASP.NET Core to ASP.NET MVC 5. I have a large application with quite a few dependencies on .Net Framework DLLs. This has caused some pain. However starting again is also a lot of work, so I think I need to wait for VS 2017 to see if upgrading can solve my issues – Richard Watts Mar 06 '17 at 11:01
  • ASP.NET Core -> ASP.NET MVC 5 will always be painful, because a lot of patterns changed in the Core rewrite. I'd recommend starting a new project and copying as much code as you can. – Nate Barbettini Mar 07 '17 at 00:34
  • What are the reasons that made you do that!? Would you tell me , because I want to do the apposite and I afraid. – Mohsen Aug 21 '17 at 10:04

9 Answers9

33

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

Aleksandr Zolotov
  • 1,078
  • 3
  • 19
  • 32
  • 5
    My csproj file did not have the tag, but I followed the rest of these instructions and this still worked for my project. – Nick Painter Jul 12 '17 at 18:10
  • This doesn't work for me at all. What do you even mean by repair? – Ms01 Aug 31 '17 at 15:50
  • @MarkusStenqvist- when you start VS "see" a new record in *.csproj file and create right structure inside – Aleksandr Zolotov Aug 31 '17 at 16:09
  • Remeber - you should close VS - edit *.csproj file and only after start VS – Aleksandr Zolotov Aug 31 '17 at 16:14
  • 2
    @Alexander there is no need to close VS, you can just unload the project and right click the project to edit .csproj file directly in VS and then load it again – Zaak Sep 02 '17 at 17:36
  • 23
    This solution got me close enough, but I had some errors when building relating to inferring frameworks. It gave me what I needed in the GUI to actually be able to select a framework though. The actual line output was net461 in Visual Studio after I was done. – Brandon Barkley Sep 12 '17 at 04:50
  • 6
    This failed to work for me and I had difficulty undoing it. Readers, I suggest backing up your .csproj files first. – person27 Dec 01 '17 at 05:00
  • 1
    [.NET Framework 4.7.1 provides built-in support for .NET Standard 2.0](https://github.com/dotnet/standard/issues/514) – bvj Mar 08 '18 at 15:35
  • I did this and after this change the "Target Framework" in "Properies"is empty. Does this result in any negative conciquences? Am I missing something? – K.Oleksiak Aug 14 '19 at 08:56
  • @K.Oleksiak - this is strange, usually after editing and starting VS make all work by himself. Have you started VS jet ? – Aleksandr Zolotov Aug 15 '19 at 09:12
  • @K.Oleksiak - and of course remember about this https://github.com/dotnet/standard/issues/514 – Aleksandr Zolotov Aug 15 '19 at 09:13
21

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.

Greg Gum
  • 33,478
  • 39
  • 162
  • 233
17

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!

Joshua Schlichting
  • 3,110
  • 6
  • 28
  • 54
9

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.

1

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>

VorTechS
  • 473
  • 5
  • 12
0

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.

Sai Kiran
  • 1
  • 2
0

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.

Pawan
  • 43
  • 8
0

add below in csproj

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.1;net471</TargetFrameworks>
  </PropertyGroup>
lemon
  • 71
  • 1
  • 4
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.