I have an existing MVC web application build using .Net framework 4.5 in visual studio 2015. Now what i want is to migrate this application to new framework i.e ASP.NET MVC CORE using visual studio 2015 without installing any other framework tool or something.
-
Possible duplicate of [Migrate to .NET Core from an ASP.NET 4.5 MVC web app](http://stackoverflow.com/questions/30671193/migrate-to-net-core-from-an-asp-net-4-5-mvc-web-app) – mmushtaq Apr 07 '17 at 07:25
1 Answers
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 loadbootstrap.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.

- 937
- 3
- 16
- 31
-
@orhun.begendi- As per your answer, is it necessary to install 'ASP.NET Core' framework into VS15 or nuget can help out ? – Akshay Chawla Apr 07 '17 at 07:29
-
1@AkshayChawla you need at least vs2015 with .net core. Or you need VS 2017. Also you need dotnet core framework for migrate to asp.net core. – orhun.begendi Apr 07 '17 at 07:41
-
1
-
@orhun.begendi- i am stuck at point #2. Getting error while installing "Microsoft.AspNetCore.StaticFiles" package from nuget. – Akshay Chawla Apr 10 '17 at 08:22
-
@orhun.begendi- if i skip installing "Microsoft.AspNetCore.StaticFiles" package from point #2 and move ahead then i get stuck at point #4. Getting error on following lines: -loggerFactory.AddConsole(); -app.UseDeveloperExceptionPage(); -app.UseStaticFiles(); – Akshay Chawla Apr 10 '17 at 08:23
-
please check following url to complete step 2. https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files – orhun.begendi Apr 10 '17 at 14:32
-
@orhun.begendi- i tried to follow the defined steps in Visual Studio 2017 and it worked. Previously i was using VS15 and net core framework was not installed in it. so i was just downloading the packages from nuget as defined in point #1. But it needed lot more than just packages from nuget, which was solved by .net core framework in VS17. Thanks – Akshay Chawla Apr 12 '17 at 06:03
-