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


    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 14
    VisualStudioVersion = 14.0.25420.1
    MinimumVisualStudioVersion = 10.0.40219.1
    Global
        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
        EndGlobalSection
    EndGlobal

    这样就创建了一个空白的 .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)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
      </PropertyGroup>
      <Import Project="$(VSToolsPath)DotNetMicrosoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
      <PropertyGroup Label="Globals">
        <ProjectGuid>8bc01464-6079-4603-881a-9f8716ba6f7d</ProjectGuid>
        <RootNamespace></RootNamespace>
        <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">.obj</BaseIntermediateOutputPath>
        <OutputPath Condition="'$(OutputPath)'=='' ">.in</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.WebMicrosoft.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)
        {
            //..
        }
    }
  • 相关阅读:
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
    第 8 章 容器网络
  • 原文地址:https://www.cnblogs.com/dudu/p/5971478.html
Copyright © 2020-2023  润新知