Convert .Net Core to .Net Framework

后端 未结 8 1420
小蘑菇
小蘑菇 2020-12-08 06:18

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 star

相关标签:
8条回答
  • 2020-12-08 06:34

    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.

    0 讨论(0)
  • 2020-12-08 06:36

    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>

    0 讨论(0)
  • 2020-12-08 06:46

    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.

    0 讨论(0)
  • 2020-12-08 06:49

    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.

    0 讨论(0)
  • 2020-12-08 06:52

    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!

    0 讨论(0)
  • 2020-12-08 06:53

    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.

    0 讨论(0)
提交回复
热议问题