ASP.NET MVC Custom View Path breaks Visual Studio shortcuts - asp.net-mvc-3

I've seen a lot of articles on how to change the default paths for an ASP.NET MVC project so you can relocate or rename your Controllers, Models, and Views folders by extending the RazorViewEngine and specifying new path formats.
So far, this works great but the side-effect is that it has broken the Visual Studio shortcuts for "Go to View" or "Add View...".
Any ideas on whether those shortcut options can be customized to know about the new paths I've specified?
Thanks in advance! - Scott

The Visual Studio features cannot be extended to support custom paths. However, in the ASP.NET and Web Frameworks 2012.2 update that will soon be released (you can download a preview right now from here), the Add View functionality was updated to be a lot more flexible regarding which folders will have it enabled and which won't. It now supports Add View in any folder that is anywhere under a folder called "Views".
Regarding Go To View, that was not updated because unfortunately there is no way for the VS tooling to be aware of runtime customizations made to the view engine - I agree it would be cool, though!
(BTW my source for this information is that I work on ASP.NET MVC at Microsoft.)

Related

How to create a Visual Studio add-in to generate files?

I would like to create a Visual Studio add-in to generate files.
For example, I would like to create something similar to the "Add Controller" dialog in ASP.NET MVC. This appears when you right-click on the "Controller" folder in an MVC project in Visual Studio.
However, instead of creating a controller file, I would like to create "Handler", "Request", and "Reply" classes within a folder, for my implementation of a service bus.
Creating these classes over and over again is becoming a bit of a chore, so I'd like to automate it. Is an add-in the way to go here? Do I also need to use macros and/or T4 templates?
It would be nice I could run the add-in by right-clicking on a folder and then choosing Add->Handler or something similar. I'm sure there must be a way to do something like that, but I haven't found a good resource yet through Google.
For reference, I've already looked at these web pages for info:
http://msdn.microsoft.com/en-us/vstudio/bb968855.aspx
http://msdn.microsoft.com/en-us/library/80493a3w.aspx
http://msdn.microsoft.com/en-us/library/7k3w6w59.aspx
http://www.c-sharpcorner.com/UploadFile/mgold/AddIns11292005015631AM/AddIns.aspx
http://www.codeproject.com/Articles/16515/Creating-a-Custom-Tool-to-Generate-Multiple-Files
http://www.olegsych.com/2010/03/t4-tutorial-integrating-generated-files-in-visual-studio-projects/
You can create templates which could make you nearly everithing you would like to do.
Creating Vs-Templates
Item templates
You can use your custom templates with the built in way easily and you can extract them from
...\Documents\Visual Studio 20[XY]\Templates\
folder to migrate them by copying.

visual studio not letting me add a VB.Net file

I have an example web solution that I downloaded and when I try Add New Item (e.g. page, web control, etc.), only C# is present as a language option. In other solutions I use, I see C# and VB. How can I add a new VB item?
If the current project is a C# project, you will only be able to add C# items to an existing project.
You should be able to add a new project to the solution, set it to a VB.Net project, then add VB items to it.
If you're trying to do this in a web project, you might be able to achieve this like DotNetNuke does it. Check out this post as to what files have to go in what folder (specifically App_Code) as well as changes to your web.config file. I do have to admit that other than DNN, I've never tried to do this in a regular web project.

updating Visual Studio templates on new release of jQuery (and other libraries)

Now that Visual Studio => 2010 has jQuery support, I'm wondering how I can update the project template when a new jQuery release comes out? Currently when you create a project, it automatically creates the 1.4.1 files (in VS2010), but jQuery is ever evolving, and often updates it version.
How can I tell Visual Studio to use the more recent version of jQuery (or other libraries for that matter)?
You can use NuGet
right-click on your project in Solution Explorer
click on "Manage NuGet Packages" in context menu
type "jQuery" in the search box on the top right corner of the dialog box
press Enter key and wait for results
look for "jQuery" in the results, SELECT it and click "Install" button
(after installation, you previous jquery and related files will be replaced with the latest ones)
Alternatively, you can create an Empty project and install the the nuget package(s) through the Package Manager Console. This can include ALL of the libraries that you default to.
PM> Install-Package jQuery
From there, save it as a new template, and whenever you create a new project, simply run the following terminal command before starting work.
PM> Update-Package
more info on Update-Package
You can create a new project template with jQuery 1.4.2 included: http://msdn.microsoft.com/en-us/library/ms247120%28v=VS.100%29.aspx
Automatic update have some issues. If you are using jQuery library with some additional plugin and they depend on the previous jQuery library framework then they will not work. That is why you need to think carefully before updating the jQuery library from version to version.
UPDATE:
You could modify an existing template for Visual Studio which will allow you to refer to the new version of jQuery. Here is an article about creating custom Visual Studio templates.
http://msdn.microsoft.com/en-us/library/ms247119(v=VS.80).aspx
This whole Nuget/update version model in JQuery is a huge mess! (Who designed this system?)
What I do is simply avoid the JQuery template piece in Visual Studio and place the current JQuery javascript links in ONE PLACE in your web project so its pasted into every single page......either the MVC Layout page, usercontrol, or masterpage. You can mix and match controls. But it doesnt matter as modern browsers cache these files after the first download anyway.
Now when you do a JQuery update, you can fix it in one simple place in your web project. All ECMAscripts have been done this way anyway the past 15 years using server side includes or other strategies. I'm still not sure why you want a template to stuff links in hundreds of view pages in MVC you now have to customize one by one when you get different versioned files names. I think ASP.NET MVC has gone backwards in its design for that reason.

can i use visual studio 2008 for a regular asp project

i have taken over an asp project from a friend and he was basically just using notepad++ to develop. I would like to use visual studio 2008 but there is no project file or solution file at this point, just a bunch of asp pages and some images, css
the other trick is that he will still be developing for a bit but doesn't want to use VS.
what is the best way to "upgrade" this so i can use VS ide features and he can still use notepad++ without any issue?
EDIT: Thanks for the responses. One additional request. We will ultimately be looking at migrating this to an ASP.net mvc site. Would that change any of the answers below or should i start from scratch when that happens in terms of vs projects solutions?
Yes. We are currently using it that way to support a legacy .asp application. We have a project in one of the solutions for the .asp pages.
edit:
In response to your edit I wouldn't see a need to change anything when migrating to MVC. You'll be adding new project(s) to your solution containing the .asp code. If anything, having it all in one place might make your life a little easier during the transition. Our ASP.net site(s) are in the same solution as the .asp project.
edit (part deux):
Using Notepad++ should present no issues. The edits would be to the .asp files (and .css, etc), not to the VS .proj file. I often use UE to edit the .asp files if I don't need to open the IDE. Assuming you're using a source repository of some sort...
Just create a blank solution (New Project > Other Project Types > Blank Solution) and then include all of the .asp files and any other relevant files.
You can just do File > Open > Web Site... and point VS at the folder containing the files. That should let you just edit the files. I say should as I don't have a classic ASP site to test this on.
When you start the MVC app, I'd start that one from scratch with a new project and then use your existing asp pages as starting points for your views.

Why does a web application project in VS2005 offer a 'Convert to Web Application' menu choice

I believe I understand fully the differences between Visual Studio 2005's web site model versus the web application project model that was fully delivered in VS2005 SP1 - but I have run into a confusing thing:
I have a web application project I wrote (it has a bin folder with the compiled projectname.dll and referenced .dlls too, etc.). but I just noticed that if I right-click on the project within Solution Explorer, a menu item called "Convert to Web Application" is exposed). That makes no sense to me.
I was comparing this project to a "web site" solution in VS2005 and contemplating converting it to a web application project. Strangely, the solution explorer offers nothing related to "Conversion to Web App" here like one would think is possible and/or appropriate.
I conclude there is nothing to help automate changing a "web site" construct to a proper "web application project". I assume it all has to be done by hand. Tasks such as reconstituting files in App_Code into one or more class library projects needs to be done manually.
I realize a lot has been written about the history and differences but can someone explain why the offer to "convert to web app" seems to be made in the "wrong" model - and just confirm that conversion is manual.
The conversion wizard does a decent job -ie, the process is far from being strictly manual - but you're still going to spend a lot of time moving from the website to web application model.
The "Convert to Web Application" context menu option for aspx pages generates a myclass.designer.cs file, which ties controls defined in markup back to the codebehind class, allowing for intellisense, compile-time validation, and other things.
Performing this action on a project file should generate designer files for all of the aspx's in the project, and I believe also creates some default application settings such as assembly name, etc, that aren't defined in a website project where the output is source, not an assembly.
I'm going to guess that the 'web application' that you wrote didn't start out with the correct vsproj file. If you bring in a project that doesn't have the correct file system scheme .aspx, aspx.cs, aspx.designer.cs then visual studio will assume that you're trying to create a 'web application' and gives you that conversion feature.
Back in 2005, Scott Guthrie did a tutuorial about converting a web site project to a web application project. Here is the section about Migrating from a Web Site Project to a Web Application Project.
Hope this helps some.

Resources