在Visual Studio中将现有.NET Framework项目迁移至.NET Core 1.1 Preview 1

来源:互联网 发布:win7仿苹果mac os x 编辑:程序博客网 时间:2024/04/29 08:54

1)下载安装包含 .NET Core 1.1 Preview 1 的 SDK:Windows x64 安装包(下载地址列表)

2)下载最新 VS 2015 NuGet 插件:https://dist.nuget.org/index.html

3)创建一个扩展名位 .sln 的空白文件,将以下内容复制粘贴到这个 .sln 文件中。

复制代码
Microsoft Visual Studio Solution File, Format Version 12.00# Visual Studio 14VisualStudioVersion = 14.0.25420.1MinimumVisualStudioVersion = 10.0.40219.1Global    GlobalSection(SolutionConfigurationPlatforms) = preSolution        Debug|Any CPU = Debug|Any CPU        Release|Any CPU = Release|Any CPU    EndGlobalSection    GlobalSection(ProjectConfigurationPlatforms) = postSolution        {8BC01464-6079-4603-881A-9F8716BA6F7D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU        {8BC01464-6079-4603-881A-9F8716BA6F7D}.Debug|Any CPU.Build.0 = Debug|Any CPU        {8BC01464-6079-4603-881A-9F8716BA6F7D}.Release|Any CPU.ActiveCfg = Release|Any CPU        {8BC01464-6079-4603-881A-9F8716BA6F7D}.Release|Any CPU.Build.0 = Release|Any CPU    EndGlobalSection    GlobalSection(SolutionProperties) = preSolution        HideSolutionNode = FALSE    EndGlobalSectionEndGlobal
复制代码

这样就创建了一个空白的 .NET Core 解决方案文件。

3)在各个VS项目文件夹(.csproj文件所在的文件夹)中创建扩展名位 .xproj 的空文件,将下面的内容复制/粘贴至其中,并将 RootNamespace 的值设置为当前项目的命名空间。

复制代码
<?xml version="1.0" encoding="utf-8"?><Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">  <PropertyGroup>    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>  </PropertyGroup>  <Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />  <PropertyGroup Label="Globals">    <ProjectGuid>8bc01464-6079-4603-881a-9f8716ba6f7d</ProjectGuid>    <RootNamespace></RootNamespace>    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.\obj</BaseIntermediateOutputPath>    <OutputPath Condition="'$(OutputPath)'=='' ">.\bin\</OutputPath>    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>  </PropertyGroup>  <PropertyGroup>    <SchemaVersion>2.0</SchemaVersion>  </PropertyGroup>  <ItemGroup>    <DnxInvisibleContent Include="bower.json" />    <DnxInvisibleContent Include=".bowerrc" />    <DnxInvisibleContent Include="ConnectionString.config" />    <DnxInvisibleContent Include="packages.config" />    <DnxInvisibleContent Include="Web.config" />  </ItemGroup>  <Import Project="$(VSToolsPath)\DotNet.Web\Microsoft.DotNet.Web.targets" Condition="'$(VSToolsPath)' != ''" /></Project>
复制代码

4)在各个项目文件夹中添加如下包含基本配置的 project.json 文件:

复制代码
{  "dependencies": {    "Microsoft.NETCore.App": "1.1.0-preview1-*"  },  "frameworks": {    "netcoreapp1.1": {      "imports": [        "portable-net45+win8+wp8"      ]    }  }}
复制代码

5)对于 MVC 或 Web API 项目

5.1)在 project.json 中添加 buildOptions, runtimeOptions 与 publishOptions 的配置

复制代码
  "buildOptions": {    "emitEntryPoint": true,    "preserveCompilationContext": true  },  "runtimeOptions": {    "configProperties": {      "System.GC.Server": true    }  },  "publishOptions": {    "include": [      "wwwroot",      "web.config"    ]  },
复制代码

5.2)添加 Program.cs 与 Startup.cs 文件

Program.cs

复制代码
public class Program{    public static void Main(string[] args)    {        var host = new WebHostBuilder()                    .UseKestrel()                    .UseUrls("http://*:5000")                    .UseContentRoot(Directory.GetCurrentDirectory())                    .UseIISIntegration()                    .UseStartup<Startup>()                    .Build();        host.Run();    }}
复制代码

Startup.cs

复制代码
public class Startup{    public Startup(IHostingEnvironment env)    {        //..    }    public IConfigurationRoot Configuration { get; }    public void ConfigureServices(IServiceCollection services)    {        //..    }    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)    {        //..    }}
阅读全文
0 0
原创粉丝点击