I know this is old question, but need to update I guess. Because some of production application migrating asp.net mvc to asp.net core. I gather up some step by step migration. I'll hope its gonna be useful.
Yes it is possible.
1) Create a new empty ASP.NET Core web app with the same name as the previous project. So namespace will be match.
2) Install the Microsoft.AspNetCore.Mvc
and Microsoft.AspNetCore.StaticFiles
NuGet packages. The ASP.NET runtime is modular, and you must explicitly opt in to serve static files
3) Open the .csproj file and add a PrepareForPublish
target:
For example
<Exec Command="bower install" />
</Target>
4) Open the Startup.cs file and change the code to match the following:
namespace WebApp1
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
}
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole();
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
}
}
5) Add a Controllers folder.Then add MVC controller class with the name HomeController.cs to the Controllers folder.
- Add a Views folder.
- Add a Views/Home folder.
- Add an Index.cshtml, MVC view page to the Views/Home folder.
For mid test please do following
Replace the contents of the Views/Home/Index.cshtml file with the following:
<h1>Hello world!</h1>
6) Migrating functionality from the ASP.NET MVC project. We will need to move the following:
- client-side content (CSS, fonts, and scripts)
- controllers
- views
- models
- bundling
- filters
- Log in/out, identity
7) Copy each of the methods from the ASP.NET MVC OldController to NewController
8) Copy the About.cshtml
, Contact.cshtml
, and Index.cshtml
Razor view files from the ASP.NET MVC project to the ASP.NET Core project.
9) Run the ASP.NET Core app and test each method.
10) For static content Add a Bower configuration file named bower.json
to the project root (Right-click on the project, and then Add > New Item > Bower Configuration File). Add Bootstrap and jQuery to the file
11) Copy the favicon.ico file from the old MVC project to the wwwroot folder in the ASP.NET Core project.
12) Copy the _ViewStart.cshtml
file from the old ASP.NET MVC project's Views folder into the ASP.NET Core project's Views folder. The _ViewStart.cshtml
file has not changed in ASP.NET Core MVC.
13) Create a Views/Shared folder.
14) Copy the _Layout.cshtml
file from the old ASP.NET MVC project's Views/Shared folder into the ASP.NET Core project's Views/Shared folder.
15) Change some old features on razor view with news like followings
- Replace
@Styles.Render("~/Content/css")
with a <link>
element to
load bootstrap.css
- Remove
@Scripts.Render("~/bundles/modernizr")
.
Comment out the @Html.Partial("_LoginPartial")
line (surround the
line with @*...*@)
.
- Replace
@Scripts.Render("~/bundles/jquery")
with a <script>
element.
- Replace
@Scripts.Render("~/bundles/bootstrap")
with a
<script>
element.