How to easily include common code across multiple ASP.NET MVC sites - asp.net-mvc

At work we have about 30 legacy sites which run from a common set of code, currently these sites are in cold fusion. For this common code we have one project, then in IIS we set up a virtual directory to include the common code into each site. This works great, as changes to core logic can be made in one place, and its replicated through all the sites. And as all of our sites are hosted on the same servers, we can also just deploy the common code and all the live sites are updated, we don't need to release every site.
However we are in the process of re-writing our sites and core code into c# and asp.net MVC 3. Its going well, except when we update the core code, we are currently copying the dlls into each site, recompiling, then releasing each site.
This is fine while we only have a couple of sites re-built with the core code, but is going to be very painful when all 30 of our sites have been re-built in .net.
Does anyone have any ideas of how to easily use and delpoy common code without having to copy the dlls to every site?
So far we've tried:
- using a virtual directory of the dlls (doesn't work as site code needs to be re-compiled, and IIS doesn't seem to like it on .net sites anyway)
- deploying our common dlls to the GAC - this is an issue as the third party libraries (eg nHibernate) aren't signed, so can't add them to the GAC too.
Thanks
Saan

The easiest way is to automate your update procedure.
But if you want to rid of copying at all then you can try thing named "codebase".
Here is description of "How the Runtime Locates Assemblies" and details of "Locating the Assembly through Codebases or Probing" http://msdn.microsoft.com/en-us/library/15hyw9x3(v=vs.71).aspx

Interesting.
I also saw in the next .net relase they have http://www.asp.net/vnext/whats-new#_Toc_perf_3 “Sharing Common Assemblies”
This will give us a couple of options to investigate thanks.

Related

How to simplify and rationalize use of IIS Express when wanting to copy Projects and Solutions, or manage on different machines?

I am looking for some best practices ideas (and perhaps simpler mechanisms) of keeping IIS Express ports, both SSL and non-SSL, sanely and neatly managed within a team-based development environment where we may also be copying templates of MVC projects to create new projects.
We are building numerous MVC applications within my company, which are then deployed on various web servers for clients of ours.
IIS Express is great when developing a new MVC app, and debugging it. And subsequent deployment to a "real" web server is no problem.
Problem comes about when copying a Solution with an MVC app to create a new solution (ie new MVC app) based on the old one. I can copy the solution, I can open it in Visual Studio, but (of course) the selected IIS Express ports for non-SSL access and SSL access are the same as in the source application. This is a recipe for disaster, of course, as I want to branch my copy away from the original to create a new app.
I have found suggestions on how to change the IIExpress Server by simply right clicking on the app properties, going to the "Web" tab and modifying the port there. However, that is error prone and almost always involves ALSO needing to edit the IISExpress applicationhost.config file manually.
This problem is compounded when there are two (or more) developers sharing development tasks on these MVC apps as they may have frustratingly overlapping IISExpress ports.
Any experiences that can make this less painful? I feel like I am just wrestling with the IDE and TFS in ways that can't be intended.
Thanks in advance for ideas or pointers to resources that may help.

I need to deploy source ASP.NET MVC code on Azure websites, and for it to run

This may be a terribly simple question, but....
I am using MVC3, Razor, C#, ASP.NET4.5/SQL Server 2008 and deploying to Azure Websites & SQL Azure.
I need to copy all of my source code, without compilation, from my web application ie model source, class libraries and views. All additional projects such as Entity Framework DAL projects will remain as a DLL. However I do not wish to have a web application DLL since I need to edit C# code in situ, and have the site run using this code, no doubt using the JIT compiler.
The main reason is because I am doing some integration work and the 3rd party site sends a return url back, and "Localhost" is not very accessible to the outside world, so wish to use my Azure website instead.
So can I copy my web application code as source, and if so is it a matter of copying all the C# files up and removing the web application DLL?
Thanks in advance.
EDIT
Further thoughts. Azure Websites provides a container for the Worker process to operate which hosts the Application DLL which is P-Code which is then dynamically compiled to native code. So I am not sure if one can start with a source C# file like one can with a Razor View.
EDIT2
Or do I need to make the changes on my Local machine and keep republishing to Azure Websites to test the integration? A little long winded...
MVC Sites must be Web Applications, they cannot be on the fly compiled. Sorry, there is no way around this. You must compile your code into a DLL for it to run if you want to use MVC.
The reasons for this are many, but a big one is that the "on the fly" compilation model used by ASP.NET Web Site projects does not use namespaces, and namespaces are very important to the operation of MVC.
Another issue is that MVC depends heavily on static assembly references, which is also not the case in Web Site projects.
In general, ASP.NET Web Site projects are poorly supported, have a lot of issues that make them unsuitable for larger projects, and even more unsuitable for use with more advanced frameworks.

How do teams work on VB ASP.NET MVC sites?

In PHP, you can just log in to the FTP and see all of the files. I notice in VB ASP.NET MVC when I publish a site it doesn't include the controllers or models. Rather, it seems to compile them into DLLs. How can the files be modified with out access to the originals? Would a developer have to publish the files in a separate directory and then the other developer pull them down and open the project in visual studio?
Keep your SourceCode in a Version Control System like SVN /GIT /TFS etc.. Whenever you want to make an update , Get the specific version you want to update and make update to that.
Having a Version control gives you so many advantages
1) Collaborative working. Many members of a team can work on same code base without overwriting conflict
2) Restore to a Previous Version : Something wrong with the current production move ?. Just get the Previous version (Label) which is working fine (and was running in prod) and rollback to that till you fix the issue.
Keeping the Previous versions of code will save a lot of time in a Programmers / Team's life.
This SO question has good points about why we should use version control.
Version control is not only for Teams. Individual developers can keep their code in Version controls and sleep nicely
Btw, Your MVC project's Model classes and Controllers classes are compiled into the DLL files.
I've seen a lot of companies that work with Visual Studio implement Visual Source Safe.
information can be found here http://msdn.microsoft.com/en-us/library/3h0544kx%28v=vs.80%29.aspx
otherwise it's pretty much what Shyju said.
In a professional environment, there is a very clear distinction between editing source code, and deploying to production. You seem to make no distinction.
Usually developers make changes under careful control using a source control system like SVN.
Build & deployment is then done separately by a dedicated team member. Developers do not touch the production servers willy-nilly.
How can the files be modified with out access to the originals?
I don't understand. If you want developers to have full access to the production environment, why not give them full access to the source code as well? In your PHP example this is a given.

upgrading asp.net mvc apps

Upgrading MVC apps done with VS 2010 has been the biggest issue for me. I have an application that I use to run various websites and I maintain and develop this application separetely then upgrade the sites based on it. A lot of things might change during development of a new version - new Views, new Controllers, stuff added into JS files, updated stylesheets etc.
I've searched around the web but nothing useful came up besides this Haack's article but no source code is available.
I also tried making a Nuget package for the entire MVC app and while this works, it doesn't package up the resource files (an issue within Nuget itself) and my apps rely on those so until this is fixed I cannot use this method.
I checked how others do it and this pretty much summarizes Umbraco's way and it's the same painful way of a dozen of steps like I do it now.
Do you have any good advice on it?
You don't specify the target OS, but I create native packages, i.e. .deb for Ubuntu servers.
However this still means you need to specify all files, manage configuration, upgrade database schemes. But if you test this on a CI server it becomes more reliable, and you can do it iteratively. This is all part of good deployment practice. I can recommend the Continuous Delivery book.

Best way to share an ASP.NET MVC Azure project among 3 PCs?

I zipped an ASP.NET MVC Azure project up and copied it to another computer (both have VS 2008). I thought I could just unzip it in "Documents\Visual Studio\Projects", but I can't quite get it working. My site builds, but the browser doesn't see the master page or Site.css. Should moving projects around as Zip files just work?
My real question is, what's the best way for one developer to share an ASP.NET MVC Azure project among 3 different computers? Should I use something like Dropbox or Live Mesh? Or, github maybe?
OP here. The problem was that "Static Content" was not enabled in IIS on the second computer. The latest installation instructions for Azure (March '09 CTP) omit this crucial step. The first computer originally ran the Jan '09 CTP, whose instructions included the step about enabling Static Content. Moving projects around by zipping them up seems to work fine.
I love using git and github. I've shared my code among many computers with it. This was C# with Visual Studio solution files, so it sounds very similar to your situation.
Of course, I love git for source code management. I'd recommend it to anyone, but there's a decent learning curve if you're new to it. I can recommend resources that helped me, since it was really only about 8 months ago that I delved into it for the first time.
If you're not looking to adopt git as your source code management tool, then you might want to look at other options for moving code between machines.
Perhaps your IIS virtual folders are configured differently on the machines? You said it builds, but does not run. This suggests that configuration of the web site itself might differ between the 2 machines (and we're getting into some things I'm not aware of about how ASP MVC works at this point).
Yes, moving projects around in a zip should work assuming all of your files are in the subdirectory you zipped up. Sometimes you might add files to your solution that aren't in the subdirectory, and that can cause problems. References to other files need to be relative, instead of absolute.
A problem you might encounter is if both of you edit the same file, or accidentally overwrite an edited file with one from a developers machine that doesn't have that change yet.
Most developers use a source control system to share projects. Git is a fairly new one that has a growing audience. Subversion has been around a little longer and is very popular. Visual Studio integrates with TeamFoundation Server.
ProjectLocker.com offers free subversion hosting(so that you don't have to setup your own subversion repository).
Codeplex.com offers Team Foundation Server hosting for open source projects.
It sounds like the type of thing you see if the app-root isn't an application, or if the application isn't handling virtual directories correctly.
With virtuals; for example, you should rarely use "/foo/bar" - because if your app isn't installed at the site root you'll get unexpected behaviour - you mean "~/foo/bar", but this often needs extra code, as discussed here.

Resources