在Visual Studio中将现有.NET Framework项目迁移至.NET Core 1.1 Preview 1
2017-08-04 10:43
323 查看
1)下载安装包含 .NET Core 1.1 Preview 1 的 SDK:Windows x64 安装包(下载地址列表)
2)下载最新 VS 2015 NuGet 插件:https://dist.nuget.org/index.html
3)创建一个扩展名位 .sln 的空白文件,将以下内容复制粘贴到这个 .sln 文件中。
这样就创建了一个空白的 .NET Core 解决方案文件。
3)在各个VS项目文件夹(.csproj文件所在的文件夹)中创建扩展名位 .xproj 的空文件,将下面的内容复制/粘贴至其中,并将 RootNamespace 的值设置为当前项目的命名空间。
4)在各个项目文件夹中添加如下包含基本配置的 project.json 文件:
5)对于 MVC 或 Web API 项目
5.1)在 project.json 中添加 buildOptions, runtimeOptions 与 publishOptions 的配置
5.2)添加 Program.cs 与 Startup.cs 文件
Program.cs
Startup.cs
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)\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) { //.. } }
相关文章推荐
- 在Visual Studio中将现有.NET Framework项目迁移至.NET Core 1.1 Preview 1
- 将现有企业级模板项目从 Visual Studio .NET 2003 迁移到 Visual Studio 2005
- 将现有企业级模板项目从 Visual Studio .NET 2003 迁移到 Visual Studio 2005
- 现有 Delphi 项目迁移到 Tiburon 中的注意事项
- 将Visual Studio安装项目中将用户选择的安装路径写入注册表的方法
- 现有 Delphi 项目迁移到 Tiburon 中的注意事项
- [转].NET 4.5+项目迁移.NET Core的问题记录 HTTP Error 502.5
- .net core 2.0学习笔记(四):迁移.net framework 工程到.net core
- Svn项目迁移到Git及Visual Studio 中git使用
- web developer tips (82):Visual Studio 2005web应用项目迁移到Visual Studio 2008
- 将 ASP.NET 1.1 应用程序迁移到 Visual Studio 2010
- Eclipse中将现有的maven项目 导入Git,并发布到github
- 现有Delphi项目迁移到D2009中的注意事项
- web developer tips (82):Visual Studio 2005web应用项目迁移到Visual Studio 2008
- 使用Visual Studio 2010新建项目或网站 无法选择.NET Framework版本解决方案
- .net core 2.0学习笔记(四):迁移.net framework 工程到.net core
- 现有 Delphi 项目迁移到 Tiburon 中的注意事项[转]
- 在 Visual Studio 中将网站项目转换为 Web 应用程序项目以及转化时常见错误
- 将cocos2dx项目从Visual Studio 迁移到 xcode