MVC4 and MVC5 in one solution - c#

I have an odd question. Can we have a solution comprising of both MVC4 and MVC5 projects?
The scenario is that there is a common project which is on MVC4 and being used by many other applications, but now we want to create a project in MVC5 or convert the existing template to MVC5, but also want to include that MVC4 project in the new solution.
Will that work? Will the new MVC5 project be able to work with old MVC4 projects in one solution?
I was following the guideline of conversion but it says to run the upgrade-package command and this command updates all packages in the MVC4 project as well, which we don't want to do.
Both projects are targeting .NET Framework 4.5 and using Visual Studio 2015.

A solution is just a collection of projects; there's no restriction they they use the same frameworks or dependencies, so it should be fine to have them both in one solution.
You probably cannot, however, deploy them to the same web application. They will likely need to be isolated to different applications in IIS or wherever you deploy them.
If you have dependencies between the MVC apps you will likely have problems. I would recommend moving as much logic that is not critical to the MVC app (classes, business logic, repositories, etc) out of the MVC apps into a common library that is independent of the app that uses it.

Related

Sharing code between ASP.NET MVC 5, ASP.NET Web Api 2 and Mobile (Xamarin)

I'm an experienced ASP.NET MVC and Web Api 2 Developer and now our company is starting on mobile development.
Our projects use .net framework 4.7.2.
We have a "common library" that all our projects reference.
Also, we have a POCO class project, which, of course, contains only poco classes (we use entity framework 6)
So, what we need is to use that "common library" and the POCO classes with the mobile software, while using them on existing projects, like the ASP.NET MVC 5 project.
What is necessary to accomplish it, considering we do not want to "duplicate" code?
Thank you very much!
You can use Shared Projects.
Here is a complete walkthrough how to achieve that (the tutorial is long so I won't post any steps).
With this, you can reference the models in other projects, and keep the always updated.

How to make asp.net core application to look for view files in the current project?

I have two projects in my solution.
One (main) of them is the application entry point. The other one (api) handles one of the business processes, which require JSON communication in 99% cases.
However, for 1% of cases I need full HTML response, and here is the problem. I created a controller and a view, but it seems that application looks for the view in the main project.
I want it to work with the following file structure within the solution:
/Main/ (and the content of main application)
/API/Controllers/TestController.cs (contains definition of Action())
/API/Views/Test/Action.cshtml
But it seems I need to copy the view from /API/Views/Test/Action.cshtml to /Main/Views/Test/Action.cshtml or /Main/Views/Shared/Action.cshtml. That splits internal logic of my application :(
You can keep your views with your DLL.
Just ensure on build/deployment copy 'views' folder at root location.
You cannot (currently, at least) share views between ASP.NET Core projects. In ASP.NET Core 2.1 (in preview), you will be able to share views by adding them to a class library that both projects can reference.
Razor UI in a class library
ASP.NET Core 2.1 will make it easier to build and include Razor based UI in a library and share it across multiple projects. A new Razor SDK will enable building Razor files into a class library project that can then be packaged into a NuGet package. Views and pages in libraries will automatically be discovered and can be overridden by the application. By integrating Razor compilation into the build, the app startup time is also significantly faster, while still allowing for fast updates to your Razor views and pages at runtime as part of an iterative development workflow.
For the time being, you'll just have to duplicate the views in each project and put it on your road map to factor them out once 2.1 is released and you can upgrade.

How to Deploy/Publish two projects in ASP.NET MVC with VS (Codeplex: AspNet.Identity.MySQL)

I have created an ASP.NET MVC 5 project with Entity Framework and a MySQL database. In Debug-mode everything works perfectly, but now I would like to publish it to my IIS-Server.
The first project in my Solution is AspNet.Identity.MySQL which
allows me to use Entity Framework in combination with Identity 2.0
and MySQL. It is from codeplex. https://aspnet.codeplex.com/SourceControl/latest#Samples/Identity/AspNet.Identity.MySQL/
The second project is my ASP.NET MVC application.
Publishing the second project by itself is no problem. I just don´t know how to publish the first project (AspNet.Identity.MySQL).
Long story short,
I have this and don´t know how to deploy/publish it via File-System:
IdentityWeb is the ASP.NET MVC Appliaction.
Thanks for your help,
Beardy Bear
The first project AspNet.Identity.MySql is a class library, so it's output is a DLL only. When you build the solution, a DLL is output into the bin folder. If project IdentityWeb has a reference to the other one, the DLL for it will appear in the bin for that project too.
As long as when you publish the IdentityWeb project, it has the DLL AspNet.Identity.MySQL.dll in the bin, then you should be able to deploy your ASP.NET MVC application to IIS.

Unable to reference new C# class library project

Background
I am working on a reasonably large legacy ASP.NET MVC solution.
Currently all of the code resides in just two projects (one containing model first C# generated code, the other containing the rest of the application).
Problem
I've added 2 projects to the solution - one for unit tests & one containing some code to be used as a service by the web application.
When I reference the service project from the main project there's a yellow warning sign by the reference.
As I said this is a legacy project with code all over the place & I'm not sure why this is happening.
I've tried Googling for a solution but haven't been able to find anything that gives some clues to this problem...
Note: There are just two classes in the service project
Here's a picture of the warning:
Make sure that both projects are set to the same version of the .NET Framework.
For example if your Main project targets to .NET Framework 4.0 and your Services project targets to .NET Framework 4.5.2, you can expect some compatibility issues.

Install ASP.NET MVC3 and MVC2 side by side?

Can you install ASP.NET MVC3 and MVC2 side by side?
I want to install MVC3 and try it out on a smaller project. BUT I want to retain our current large project on MVC2 for a little while.
If I install MVC3, will my existing project be automatically upgraded or do I have the option to keep it on MVC2?
MVC 3 and 2 can exist side-by-side. The project file will not / does not have to be upgraded.
For more details, see http://www.asp.net/learn/whitepapers/mvc3-release-notes
Question title says it all: Can you install ASP.NET MVC3 and MVC2 side by side?
You can perfectly fine have ASP.NET MVC 2 and 3 running side by side on the same machine. In VS2010 you have the possibility of choosing which version you want when creating new projects and on the production server you can have MVC 2 and 3 applications running side by side without any problems. Just don't forget that MVC 3 implies .NET 4.0 whereas MVC can run on both .NET 3.5 and .NET 4.0 application pools.
Yes, I have MVC2 and MVC3 installed on my development machines. When you start new projects you are prompted for both MVC versions to choose from.
Yes, but:
I had a problem with NUnit because some of the classes are defined in both versions of the System.Web.Mvc dlls. The applications run fine, but an NUnit looses its mind - it blows up with a message Cannot cast SelectedList to SelectedList.
Edit
I am running NUnit 2.5.5. Whats happening is that when the application is built it is using the version 3.0.0.0 of the dll, but when it is run under NUnit by the time it loads the app dll, the 2.0.0.0 version of the dll is already loaded. Both of them have the SelectedList class defined in them and that causes the NUnit to loose its mind

Categories