I am building a site that hosts games I am writing. I'm using MVC4 and VS express 2012. The main site is its own project. I want each game I write to exist in a separate project, so I can build and deploy each game independently of the main site. That
is to say, I don't want to have to recompile and publish the entire site just to update one game.
The problem I am having is I don't see anyway the game projects can use the main site's layout. I want it to be as simple as setting the path of the layout page whenever I add a view to one of the game projects. I don't want to have to scrape or iframe
my own games.
Searching around I see a lot of people talking about "razor generator" which sounds a bit convoluted, but I can't try it out as the installer seems to ignore VS 2012 Express. What is the right way to do this?
I don't see anything on that page specifically talking about rendering views from another project, or it isn't clear if it is there.
I think I'm going to have to do this the other way around, have the games exist in class libraries and have the site call out for them to render their html & javascript. I'm not sure where the images will live for each project but that seems to be an easier
problem to solve than this.
If you look at the constructor, author is assigning different set of pathing for each of the properties, you need to do similar stuff to point to a path, and while looking for view file viewengine will also search in the mentioned location.
But doesn't "~" refer to the root of the project you are in? How would you tell a game project to it "pull "~/Views/Game.cshtml" from a different project?
planet idiot
Member
57 Points
30 Posts
Multiple projects sharing views vs 2012 express?
Feb 04, 2013 02:32 PM|LINK
I am building a site that hosts games I am writing. I'm using MVC4 and VS express 2012. The main site is its own project. I want each game I write to exist in a separate project, so I can build and deploy each game independently of the main site. That is to say, I don't want to have to recompile and publish the entire site just to update one game.
The problem I am having is I don't see anyway the game projects can use the main site's layout. I want it to be as simple as setting the path of the layout page whenever I add a view to one of the game projects. I don't want to have to scrape or iframe my own games.
Searching around I see a lot of people talking about "razor generator" which sounds a bit convoluted, but I can't try it out as the installer seems to ignore VS 2012 Express. What is the right way to do this?
bruce (sqlwo...
All-Star
36822 Points
5441 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 04, 2013 02:54 PM|LINK
1) use VS 2012's linked file sharing. this will mean if you change the layout in the main site, you will need to redeploy all other site.
2) write your own viewengine. the viewengine is respondible for finding the view files, it can have a common shared location for all shared views.
planet idiot
Member
57 Points
30 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 04, 2013 03:40 PM|LINK
1) unfortunately this is what we are trying to avoid
2) I need more information on how to do this to render views from another project.
CPrakash82
All-Star
18270 Points
2839 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 04, 2013 10:58 PM|LINK
Its just the matter or locating a folder location in the ViewEngine properties, looks here for sample implementation.
planet idiot
Member
57 Points
30 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 05, 2013 04:02 PM|LINK
I don't see anything on that page specifically talking about rendering views from another project, or it isn't clear if it is there.
I think I'm going to have to do this the other way around, have the games exist in class libraries and have the site call out for them to render their html & javascript. I'm not sure where the images will live for each project but that seems to be an easier problem to solve than this.
CPrakash82
All-Star
18270 Points
2839 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 05, 2013 04:39 PM|LINK
If you look at the constructor, author is assigning different set of pathing for each of the properties, you need to do similar stuff to point to a path, and while looking for view file viewengine will also search in the mentioned location.
public MyRazorViewEngine() : base() { AreaViewLocationFormats = new[] { "~/Areas/{2}/Views/%1/{1}/{0}.cshtml", "~/Areas/{2}/Views/%1/{1}/{0}.vbhtml", "~/Areas/{2}/Views/%1/Shared/{0}.cshtml", "~/Areas/{2}/Views/%1/Shared/{0}.vbhtml" }; AreaMasterLocationFormats = new[] { "~/Areas/{2}/Views/%1/{1}/{0}.cshtml", "~/Areas/{2}/Views/%1/{1}/{0}.vbhtml", "~/Areas/{2}/Views/%1/Shared/{0}.cshtml", "~/Areas/{2}/Views/%1/Shared/{0}.vbhtml" }; AreaPartialViewLocationFormats = new[] { "~/Areas/{2}/Views/%1/{1}/{0}.cshtml", "~/Areas/{2}/Views/%1/{1}/{0}.vbhtml", "~/Areas/{2}/Views/%1/Shared/{0}.cshtml", "~/Areas/{2}/Views/%1/Shared/{0}.vbhtml" }; ViewLocationFormats = new[] { "~/Views/%1/{1}/{0}.cshtml", "~/Views/%1/{1}/{0}.vbhtml", "~/Views/%1/Shared/{0}.cshtml", "~/Views/%1/Shared/{0}.vbhtml" }; MasterLocationFormats = new[] { "~/Views/%1/{1}/{0}.cshtml", "~/Views/%1/{1}/{0}.vbhtml", "~/Views/%1/Shared/{0}.cshtml", "~/Views/%1/Shared/{0}.vbhtml" }; PartialViewLocationFormats = new[] { "~/Views/%1/{1}/{0}.cshtml", "~/Views/%1/{1}/{0}.vbhtml", "~/Views/%1/Shared/{0}.cshtml", "~/Views/%1/Shared/{0}.vbhtml" }; }planet idiot
Member
57 Points
30 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 05, 2013 10:08 PM|LINK
But doesn't "~" refer to the root of the project you are in? How would you tell a game project to it "pull "~/Views/Game.cshtml" from a different project?
CPrakash82
All-Star
18270 Points
2839 Posts
Re: Multiple projects sharing views vs 2012 express?
Feb 06, 2013 01:59 AM|LINK
You got to store at some shared location which can be used by both the project.