How do I make a MVC project appear properly in Visual Studio? - c#

How do I make a MVC project appear properly in Visual Studio? I understand the logic of this sort of structure. I have seen some blogs and explanations and even code segments explaining how a program can use MVC. But I want to know what is a good way to represent a Model-View-Controller program in the Visual Studio.
For example, in an ASP.NET program, the asp.net file is associated with a C# file. THey have the same name and, in the Solution Explorer window of the Visual Studio development environment, they are shown linked together where one is a tree branch of the other. Should the same sort of thing be done for a MVC solution? I can remember a few years ago, I worked on a MVVM project, and a developer who first put the solution file together actually had view and the view-model files arranged like this. In order to make this happen, he had to download some sort of patch that allowed him to edit the .sln (solution) file.
Is that the way to go for a Model-View-Controller program? Should each be its own workspace in the solution, or should the solution file be edited such that each Model-View-Controller coupling be handled as a tree structure file representation kind of like it is done for an ASP.NET solution?
Here is another question. What is a good template to use in Visual Studio to create an example of a Model-View-Controller program? I tried this route but when I clicked to "get new templates", it did not work:
http://i67.photobucket.com/albums/h292/Athono/Embedded/Capture_02_zps6vn4ri07.png
http://i67.photobucket.com/albums/h292/Athono/Embedded/Capture_zpscdczk1b4.png

From your screenshots, it looks like you're using an old version of Visual Studio (either 2008 or 2010, there isn't enough showing to be sure, but I see the default .NET framework listed as 3.5 up there).
The latest versions of the ASP.NET MVC framework requires .NET 4.5. Visual Studio 2010 doesn't support this, so the solution is to upgrade to a newer version of Visual Studio which includes support and project templates specifically for the latest versions of ASP.NET MVC.

Related

ASP.NET MVC C# Web Section Missing

I am starting to study ASP.NET MVC but now I see that I don't have the whole "web section" when I open new project. Before I studied pure C# (Console Applications) so I didn't really need it and I haven't noticed that it doesn't exist in my Visual Studio.
So I can't make a new MVC project... How can I add it? Is there a way of adding it without reinstalling the Visual Studio? PS: I use Visual Studio 2015 Community.
Try running the installer once again and select the appropriate checkboxes for ASP.NET or Web development.I think you may not have selected that option when installing or it might have got missed.

No WPF User Control Library Template found in VS 2013

I am using VS 2013 (Express Version) and I want to create a WPF user Control Library project. But I am not able to find the template in my installed templates list. If I use Winforms, I am able to build a DLL out of my Winforms Application Project just by changing the Output type as "Class Library". But it is not happening in WPF and it is throwing errors if I do so. Is this the correct method of doing it or am I going wrong?
And in the Create New Project dialogue window, I am not able to find the .NET Framework selector drop down. After creating the project only I am able to change the .NET framework version by going inside the properties of the project.
Kindly help me to get out of this. Thanks in advance.
I have been working on this exact same problem for hours this morning. Here is what I think I have learned:
With Visual Studio Express 2013, it is by design that the WPF User Control Library template is not available for making a New Project. This is because it is the free Express version.
With the Express version, you don't have a "devenv.exe" for trying the "devenv /installvstemplates" to "fix" things. It is, instead, called (just a moment while I look this up again...) "WDExpress.exe" and will be located (if you have default location) in the "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE" directory. BUT - this won't help you. It won't fix your problem, because, as I mentioned, your Express installation is designed to not have that template available for New Project, so your "fix" won't put it there. I know this because this is what I tried myself. (Also, note that the instructions for doing this tell you to uninstall any extensions you've installed before doing it. And then, of course, if you still want them you have to reinstall them. Like I still have to do, incidentally.) I'm letting you know all of this so you don't go through the headache I'm having.
Note that I have not done this yet, so this is somewhat hypothetical on my part, but is based on my research on the Internet so far - Your solution is to create a WPF User Control Library manually [but now see UPDATE below]. (No, I don't know how to do this yet. I got into this in the first place, because I'm a WPF novice - just started working with it a few days ago - and late last night I got this great idea to add a "spinner" progress indicator to my "WPF play/learning project" I'm working on, and found a couple of relatively easy-to-work-with samples on the Internet - both of them are a WPF User Control Library - and at first I wanted to use the copy-and-paste to put the code in. But then I discovered... well, our mutual problem, because I'm using Visual Studio Express 2013. No such template under New Project. And literally at the tail end of my about-to-throw-in-the-towel, I'm googling and your post, Dhivakar, is already showing up with the right Google search.) So I haven't finished my research yet, but my next step is to learn exactly how to create a WPF User Control Library manually (the code and various project property settings), and then I can just save a WPF User Control Library skeleton for future use and document the details.
UPDATE: This guy totally has the solution for Express versions. I have followed his steps and it works great. The only additional piece of information I would add is that in my version (VSE2013), after you've created your WPF User Control Library template, when you open Visual Studio again and use File -> New Project, my selection in the tree (for a Windows app) came up under Templates -> Visual C# -> Windows (which is what I've been using). I did not see my template showing up there, after I created it, and I thought, "Great! Another piece of advice that doesn't work." But then I clicked up one on the "Visual C#" parent - and there was the template!
Here you go:
How to add a WPF control library template to Visual C# Express 2008
https://dotupdate.wordpress.com/2007/12/05/how-to-add-a-wpf-control-library-template-to-visual-c-express-2008/
Yes, it works this way for VSE2013 too.
UPDATE 2: I'm not absolutely positive about this, but I think he missed one little piece. In his step #4 he says to delete Window1.xaml and App.xaml. Maybe this didn't apply with VSE 2008, but in VSE 2013 there is also the App.config file which I believe is extraneous for our purpose. So you can delete App.config as well. As I said, I'm not absolutely certain about this yet, but I noticed that file in the project when I added a WPF User Control Library project to my solution, and I deleted it, and the solution compiled okay.
Try running devenv with the /installvstemplates switch, from https://msdn.microsoft.com/en-us/library/vstudio/ms247116(v=vs.100).aspx
If this doesn't work, browse to C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\ItemTemplatesCache\CSharp\WPF\1033\WPFUserControl (this could change dependent upon your installation directory), open the .vstemplate file in a text editor, and make sure the setting is set to true, then try running devenv with the switch again.
Hope it helps.

Specify .NET version in Build Configuration in Visual Studio

I have a Solution file (.Sln) in Visual Studio for my Application. Application development started back in .NET 3.0. Later it was decided to provide application in .NET 3.0 and .NET 4.0.
Since there wasn't an option (I was not present at that time) so two solution files were created.
App_NET30.Sln
App_NET40.Sln
Later came a requirement to support .NET 4.5 as well. So one more file was created
App_NET45.Sln
Respective Solution files are opened using Visual Studio version
App_NET30.Sln - Opened in VS 2008
App_NET40.Sln - Opened in VS 2010
App_NET45.Sln - Opened in VS 2010
Now, somehow, this does not seem a good way to me. There has to be a neat and clean way of doing this. Like doing it all in a single solution file
I tried to create a single solution and defined various build configurations in the file and changed Target Framework in each build configuration. But it did not persist.
What can be a way to have a single solution file and achieve all that I desire ?

Add installer to a c# application

I made a search to find how am I adding an installer to my c# application. In every result I found that I need to add new file from Setup and Deployment templates, but I have no those templates. Even in online search I didn't find so.
what should I do?
The VS setup templates were removed post VS-2010.
Now, you have to use something else. "InstallShield" is still available, and Wix is a very popular install framework. You can, of course, just roll your own installer as well.
Alternatively, just use VS 2010 or earlier to create your setup/deployment projects.
I reckon you should do some research. There are many options out there depending on your type of application. Is it an executable that runs locally? Is it a Web application? Or a mobile application?
Microsoft provides lots of options/guides out of the box. Assuming you use Visual Studio 2013 check this MSDN article which is a good guide to start your research journey: https://msdn.microsoft.com/en-us/library/wtzawcsz.aspx

Developing for ASP.NET-MVC without Visual Studio

Instead of writing my ASP.NET C# applications in Visual Studio, I used my favorite text editor UltraEdit32.
Is there any way I can implement MVC without the use of VS?
There is nothing VS specific with the MVC framework - it is just a bunch of DLLs that you can use. The wizards in VS just build you a quick-start framework.
ASP.NET MVC is "bin-deployable" - there is nothing too clever to set up on the server either - just point the wildcard ISAPI filter to ASP.NET
Assuming you have the correct assemblies and a C# compiler you in theory can use whatever you want to edit the code and then just run the compiler by hand or using a build script. That being said it is a real pain doing .NET development without Visual Studio/SharpEdit/Monodevelop in my opinion.
Even if you didn't want to actually edit in VS, you could create the project there and edit the files in another editor.
For small to mid size mvc project WebMatrix is not bad at all. Also for simple changes to the projects I often use SublimeText.

Categories