1)下载安装包含 .NET Core 1.1 Preview 1 的 SDK:()
2)下载最新 VS 2015 NuGet 插件:
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 的值设置为当前项目的命名空间。
14.0 $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 8bc01464-6079-4603-881a-9f8716ba6f7d .\obj .\bin\ v4.6.1 2.0
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() .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) { //.. }}