I am using Visual Studio 2019, with .NET Framework 4.8, creating ASP.NET MVC 5 software (not Core).
I would like to use the CRUD Scaffolder from an older version of Visual Studio (e.g. 2017 or 2015). I have searched on internet and on Microsoft site; I cannot find anything. I do not have the older versions of software now.
In one of the older versions, the CRUD scaffolder created Views with simple code-
#Html.EditorFor(model => model.xxx)
#Html.EditorFor(model => model.yyy)
#Html.EditorFor(model => model.zzz)
along with of course the rest of the view code. And this is what I would like to do in VS 2019 (for just the scaffolded Views). I am looking to simplify the scaffolded view code (as was the case in older versions of VS).
QUESTIONS:
Is there a way to download and install/copy the older scaffolders?
If not the above, is it possible and easy to copy and modify the current VS2018 scaffolder code? Where could I find info on how to do it?
You will need to create custom scaffolding templates for that.
Here is a great link.
https://learn.microsoft.com/en-us/archive/msdn-magazine/2018/march/asp-net-use-razor-to-generate-html-for-templates-in-a-single-page-app
Scroll down to Changing the Scaffolding.
This is for VS 2017. The default template path in VS 2019 is C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\Microsoft\Web\Mvc\Scaffolding\Templates\MvcView
You will also need to put everything in CodeTemplates\MvcView if you will be creating your own T4 template.
You will just have to install the older versions of VS to get their T4 Files.
Here is another great tutorial on how to do this.
Hopefully some of this helps.
Related
I'm attempting to create a Custom Scaffold Extension for .NET Framework and Visual Studio 2019. I do not want to overwrite the default MVC T4 templates. I'm trying to do something like:
https://marketplace.visualstudio.com/items?itemName=robinliks.HappyScaffoldingforMVC5
I've found plenty of articles detailing the process for older versions of VS to include the SideWaffle projects but nothing that works with 2019.
Can anyone point me in the right direction?
Does Visual Studio 2015 support the older versions of MVC:
MVC3
MVC4
MVC5
Not all hosting environments support the newer versions of MVC, so to support needs of older infrastructure this is required.
If it is supported how do you create new solutions using the older MVC versions in Visual Studio 2015? By default new MVC projects are created as version 5.2.
Does Visual Studio 2015 support the older versions of MVC?
Yes, It support them just after a migration (for adding/supporting new features in IDE like Intellisense and etc).
how do you create new solutions using the older MVC versions in Visual
Studio 2015?
This is not an intellectual action since the newer platforms have a lot of fixes and advantages rather than prior ones. Unless, you may be forced to use an older one due to lack of hosting support, In this case you can't Create an older version of MVC project by the IDE (VS 2015) itself, unless by adding older assembly references and some handy works in configuration based on your complete awareness of older required files and architecture, since the newer IDE usually don't have the previews references.
Note: The VS 2015 is just an IDE (Integrated Development Environment). You can run any MVC version on it (with above considerations), But the IDE's new features will be limited likely. For example, the result of MVC 4 migration in VS 2015 will be:
ASP.NET MVC 4 projects have limited functionality in Visual Studio
Next. Commands such as Add Controller, Add View, Add Area, and Go to
View/Controller are not available. Intellisense for Razor (CSHTML and
VBHTML) files is limited to HTML markup. Please see
http://go.microsoft.com/fwlink/?LinkID=320968 for additional
information on how to upgrade an MVC 4 project.
Which suffers from the lack of Intellisense and etc. But you can still run/develop the project with it or another IDE like Visual Studio Code and debugging the projects will make sense here.
Visual Studio 2015 RTM supports MVC 5 and MVC 6 only; tooling and Razor support are missing for MVC4 and earlier versions. Note that MVC4 projects will be migrated automatically and should compile and run on VS 2015 RTM, but the editing experience in Razor views will be poor.
There has been significant negative feedback concerning this change since release, and the team is planning to ship MVC4 support for 2015 RTM. Watch the WebDev Blog for an official announcement soon.
The Send-a-Smile feature in Visual Studio 2015 is responsible for the rapid acquisition of this feedback and the decision to respond quickly. Consider using Send-a-Smile if feature changes impact you negatively.
The Visual Studio 2015 Update 1 RC should support MVC 4 projects. See https://msdn.microsoft.com/en-us/library/mt591926.aspx
I'm using Visual Studio 2012 and have just installed "Microsoft ASP.NET and Web Frameworks 2013.1 - Visual Studio".
As expected, it added the option to create an "ASP.NET MVC 5 Empty Project". The thing is, I see no way of jump-starting an already functional "base application" as I had when I was using MVC 4 (e.g. "Asp.NET MVC 4 Web Application"). I only see an empty template.
I've seen answers such as:
How can I add the MVC 5 project template to VS 2012?
Create and Run MVC 5 Project in VS 2012
Direct download link to ASP.NET MVC 5 for VS 2012
And found this article on the matter.
This is obviously not a show-stopper as I can always create the application from a scratch, but I still would like to know if it is possible to achieve that on VS 2012. Did I miss a step, or do I need VS 2013 for that? A fully functional Web application template (with authentication etc.) would be nice to dabble around MVC 5's new features or for prototyping.
After creating a new project using ASP.NET MVC 5 Empty Project, you can right click on the project, then click Add.. > New Scaffolded Item..., select MVC on the left, then MVC 5 Dependencies and choose Full dependencies from the prompt.
This will add a default layout (Views\Shared\_Layout.cshtml), Content folder, Scripts folder with bootstrap, jquery, modernizr, etc, and other things the Web Application template creates.
If you get the error "CS0103: The name 'Styles' does not exist in the current context" just add <add namespace="System.Web.Optimization"/> under <namespaces> in Views/web.config
The answer from Sean Lynch is nice but not really complete.
However there is this nice guy that took the time to prepare the template just like in Visual Studio 2013. You will get everything down to the bootstrap template and pre-configured database table for authentication.
All you need to do is change the DefaultConnection in Web.Config to you SQL Server and voila all the relevant authentication table will be created for you.
Archive of the original blog (by web.archive.org)
Update
The original blog is no longer online, but thankfully his template is still online. You can download the MVC5 Template for Visual Studio 2012 Here:
Direct link to MVC5 Template For Visual Studio 2012
And here is the excerpt from the original blog:
Installing the template is very simple, there are just two steps:
Copy it into the following folder of your computer (creating the directory structure if necessary):
%USERPROFILE%\Documents\Visual Studio 2012\Templates\ProjectTemplates\Visual C#\Web
Once you’ve done this, simply restart Visual Studio and you will have this template available in the dialog box to create a new project under “Visual C# > Web”.
Now you can create applications with a little more shape than the mere empty structure provided by default and enjoy the benefits of adopting Bootstrap and its responsive design, a full membership system and user authentication, bundles, filters, some content pages, etc.
You have 2 option to fix it.
Install the latest 2013 version which have MVC5 support inbuilt (VS2013 missing MVC3 and ASPX file template (ASPX templates will be added in future))
stay with 2012 update 4. Read my old article to get it fixed http://geekswithblogs.net/anirugu/archive/2013/11/28/mvc-5-in-visual-studio-2012-update-4.-how-to.aspx
I'm not using 2012 now, but rather 2013, and I see the mvc 5 template there. However, I did this a while back before I had any mvc 5 templates showing up by installing mvc 5 first. You should be able to download from http://www.asp.net/mvc/mvc5.
Also make sure your target framework is set correctly.
Then I updated the web config like this:
You have to have the correct versions of the assemblies. I googled a lot to get this info, so it should still be available if you do some research.
For some reason my Visual Studio 2013 Preview cannot create MVC 5 Projects. Since the MVC project is now open source in CodePlex I was wondering if there's a simple way to develop MVC 5 projects in my Visual Studio 2012 Ultimate.
Microsoft has released updated Web Tools 2013.1 that provide the support:
Description
Direct download
Note that I had to install it manually from the second link, the tools did not install properly from Web Platform Installer. Also a colleague had to install both Update 4 and these tools to get proper support.
Original answer (not actual anymore):
I received this answer from Microsoft developer:
MVC 5/Razor 3 tooling support for VS 2012 has not shipped yet. We hope to ship this support in Mid November.
Recently ASP.NET Program Manager from Microsoft mentioned in a talk that this would be included in VS2012 Update 4. Edit: unfortunately the support is not in Update 4.
So the accepted answer is true for now but we can plan to soon have this support in VS2012 as well.
A new tutorial has been recently added to the ASP.NET website on how to upgrade an MVC4 project to MVC5.
I migrated a VS 2012 project using this tutorial without problems, but there is no design time support for Razor 3 in VS2012 due to changes in the way VS loads the razor engine.
You can edit razor pages in VS2012, but it will be a plain HTML editor.
Microsoft has released an update for this, Web Tools 2013.1 for VS2012.
http://blogs.msdn.com/b/webdev/archive/2013/11/18/announcing-release-of-asp-net-and-web-tools-2013-1-for-visual-studio-2012.aspx
I'm not sure MS will fix it.
The bug report says problem closed : by design
https://connect.microsoft.com/VisualStudio/feedback/details/806348/razor-intellisense-does-not-work-in-visual-studio-2012-after-upgrading-to-mvc-5-razor-3
and it is mid November
I have a tutorial that will not only get your empty MVC 5 project working with Bundling, a controller, jQuery, jQuery UI, Modernizr and more, but it will walk you through installing Zurb's Foundation 5, a responsive Framework which I have working with Sass in MVC 5. It's all here:
http://tinyurl.com/VS12-MVC5-F5
The problem many have ran into is that Visual Studio 2012 only allows you to start from a blank MVC 5 project, so I will help you get the NuGet installed which is pretty similar to the instructions in the NuGet package with a few minor changes; however, it does not take into consideration that you will be installing from Visual Studio 2012 using a Blank MVC 5 project. If you would like to use Foundation 5 with MVC 4 Web Application template just omit the Bootstrap uninstall and the NuGet package should work fine, but if you need to use MVC 5 and you don’t have Visual Studio 2013, you will need to build the Home Controller, Bundling class, modify the Global.asax.cs as well as other quirky little things. So lets get started.
I spent a good part of a few hours getting it all working.
I have an old ASP.NET MVC 2 project which I do not want to upgrade to MVC 3 or MVC 4. I am working on a new machine running Windows 8, Visual Studio 2012 and Visual Studio 2013. When I try to open the MVC 2 project in VS 2012 or VS 2013 I receive the error:
This project is incompatible with the current edition of Visual Studio
The project is then unloaded and grayed out in Solution Explorer. I do not want to install another copy of Visual Studio. How can I open an old MVC project in a new version of Visual Studio?
Opening an unsupported MVC project in Visual Studio 2012 or Visual Studio 2013 is actually pretty easy to accomplish with two steps. In fact, as bytebender’s comment indicates, these same steps should apply to and work for MVC 1 projects. However, I haven’t tested them and therefore cannot guarantee that they do in fact work.
Assuming that you have not already done so step one is to download and install MVC 1, MVC 2 or MVC 3 (close Visual Studio before starting the installation).
Once you have the appropriate flavor of MVC installed the project will still not load in VS 2012. This is because ASP.NET MVC projects are a project subtype of the Web Application project type. This means that the project has additional add ins and features available to it when used within Visual Studio.
Both Visual Studio 2012 and Visual Studio 2013 are limited in their backwards compatibility with ASP.NET MVC and other project types. Unfortunately, installing the old MVC bits did not change that. Visual Studio 2012 is compatible with the ASP.NET MVC 3 and 4 project flavors. Visual Studio 2013 is compatible with MVC 4 and MVC 5.
To get the project to load you will have to modify the project file. To do so right click on the unloaded project and select Edit. Which will open the project file as an XML text file. Find the ProjectTypeGuids node which should look something like this:
<ProjectTypeGuids>
{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Remove the appropriate Project Guid from the list:
ASP.NET MVC 1: {603c0e0b-db56-11dc-be95-000d561079b0}
ASP.NET MVC 2: {F85E285D-A4E0-4152-9332-AB1D724D3325} (shown in example above)
ASP.NET MVC 3: {E53F8FEA-EAE0-44A6-8774-FFD645390401}
ASP.NET MVC 4: {E3E379DF-F4C6-4180-9B81-6769533ABE47}
With the appropriate GUID removed the ProjectTypeGuids should look similar to this:
<ProjectTypeGuids>
{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}
</ProjectTypeGuids>
Save the file and close the Visual Studio project file editor. Right click the project and select reload. If the project does not reload close and reopen Visual Studio. You should now be able to work with your old ASP.NET MVC project in your new version of Visual Studio.
One important thing to note is that after these modifications Visual Studio is not aware that this is an ASP.NET MVC project; therefore the project-specific features like "Add Controller, View etc." will not be present in menus.
I used #ahsteele's approach (thanks and 2x+1s!), but was having one further error:-
.csproj : error : The operation could not be completed. Invalid class string
I can't find any citations for the real cause of that, but I was able to get VS2012RTM to load the project successfully by changing the <ProjectGuid>. (No idea how this happened - its part of a large solution and VS08, VS10, VS11 Beta and VS2012RC have all upgraded the .csproj and .sln over time.
In VS2017 the solution is to just make it like <ProjectTypeGuids></ProjectTypeGuids> so.
No Spaces in between ladies and gentlemen, otherwise it will waste 48 hours of your time.
Regards