I have a solution where I have a MVC project containing all my views, and all other front end code. We also have another project (in the same solution) where I have the controllers.
If I add a controller to the mvc project and add a viewresult function to this conroller I can right click on the "return view(viewModel);" and choose "add view".
If I copy this controller to the "non mvc" project, I do not get "add view" in the right click context menu. Is there any way to get this ?
Yes - you need to add the MVC ProjectTypeGuid to the project file. Upload the project in Visual Studio and then right-click > Edit project file. Check to see whether you have a <ProjectTypeGuids> tag in your project. It may well be directly beneath the <ProjectGuid> tag. There are 3 guids in my MVC project but I'm not sure exactly which one(s) is/are needed. Start by adding all 3, reload the project, check you have the context menu, and then try removing them one at a time to isolate which is needed. I don't think it will harm the project to leave them all in though. Here's the tag from my project file:
<ProjectTypeGuids>{E3E379DF-F4C6-4180-9B81-6769533ABE47};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
EDIT: Not sure whether this will give you the in-view context menu but it will give you the solution explorer, right-click > Add View context menu.
EDIT 2: Yes it will, just tried it.
Related
I'm working on an ASP.NET MVC web application that consists of 43 projects in one solution. We've created some T4 templates for generating/scaffolding Controllers and Views and they're working as they should, but upon selecting Add -> Controller > MVC 5 Controller it hangs on Gathering Information loading screen for about 4-5 minutes until giving you the option to name your Controller and finally creating one.
The same thing happens when selecting Add -> View, but in this case the Gathering Information part is happening before a dialog in which you choose a view template even opens. After choosing any template it creates a new View almost instantly.
This is happening in both Visual Studio 2015 and 2019. I suspect it has something to do with a size of a solution, because in a blank project in a newly created solution it works just fine.
Does anyone know what might be the cause of this problem and is there a way to solve it?
I just ran across this issue in a solution with 7 projects. Ultimately I ended up unloading all of the projects except the one I wanted to add the controller to. After that, I was able to add the controller with just a few seconds delay, then reloaded the other projects.
For those who may not be familiar with multiple project solutions, to unload projects, in the Solution Explorer, select them by clicking the project while holding either the Ctrl or Shift buttons just as you would when selecting files in file explorer. Once selected, right click and select "Unload Project."
When you create a VB project in Visual Studio there is a 'References' tab in the Project Properties window. It looks like this:
It's rather a helpful window as it shows the paths to all the referenced DLLs in one place and lets you add and remove references easily.
However this same tab does not appear for projects in other languages making it very difficult to check the path for each referenced DLL.
Can this tab be made viewable or available for other projects? If not, what is the simplest way to view all the referenced DLL paths at once?
Unfortunately the reference tab for the other languages does not exist.
But you can try to edit the xml project, with these steps:
Show the context menu on your project in the window solution explorer
Select: Unload project
Right click and select Edit
Edit the ProjectReference element in xml file
Save and close xml
Reload Project (right click in solution explorer)
I know this is not what you wanted, but it could be a quick alternative to display the path of your references.
(Edit for search-ability: called "File Nesting")
I'm not sure if "folding" is the correct term, but the feature I'm referring to is shown in the 1st image below, versus the 2nd one which does not have an expandable tree list node for the code behind file.
Folding:
No folding:
My questions are:
What is the correct name of this feature?
How do I set it?
Why does my Solution Explorer not have this feature enabled when I try to convert my Web Site Project to a Web Application Project?
References:
Upgrading VS 2005 Web Site Projects to be VS 2005 Web Application
Edit
Thanks Sean, but as you can see below, my Nest Related Files button does show up in this project for some reason:
Should have button shown below:
Edit:
I figured out the reason: I accidentally created a C# Web Application Project, and then added VB ASP.NET files to it.
It's called File Nesting.
When a website project is selected in Solution Explorer, the third button in the Solution Explorer toolbar is for "Nest Related Files".
A website project or project file must be selected in Solution Explorer (rather than the root Solution), for the button to appear in the toolbar. The command/tool button is not available when C++/C# projects are selected in Solution Explorer. I don't have a web app project to test but can only conclude that the command is not applicable to web app projects either.
see this related question for a possible registry hack (changing 9.0 to 8.0 in the question's reg script):
Visual Studio 2010 related file nesting
When you are not using a website project, the nesting button in the solution explorer won't appear—but you can still nest files in .NET 5.0 projects.
Here's how you do it:
Open the project's .csproj file. Visual studio can open it in its own viewer, or else you can use your favorite XML or text editor.
Locate or create an appropriate Item Group element. If there's already one that includes some of your files, put it in there for cleanliness and consistency. If there isn't, create a new one.
Create a new Content element for the file you wish to nest. This element's Include attribute should be the name of your desired file.
Add a new DependentUpon child element to your content element. This element's text value should be the name of the file you wish to nest your target file underneath.
Save the project file and Visual Studio will likely prompt you to reload the project. If you did it correctly, your target file should now be nested under your desired file.
There's shockingly few questions and answers that address this situation. The above answer didn't help me, so I figured that I would share what did for posterity.
This is what I get when I select "go to definition" in the ConfigTests.cs. But I expected to go to already opened Config.cs with actual declaration.
What did I do wrong?
You added a normal assembly reference.
When you Go to Definition on a member not defined in your project (or in Project References), Visual Studio will generate a source file from metadata using Reflection.
Delete the reference, then re-add it as a Project reference (in the Projects tab).
If the project isn't in the same solution, put it there.
This seems to indicate that your reference to the Models assembly is via the compiled DLL, not via the project in the solution. Try the following in the Solution Explorer:
Expand (unfold) the “References” item of the main project in your solution.
Select “Models” and press Delete to remove it.
Right-click on “References” and choose “Add Reference”.
Select the Projects tab (not the Browse tab).
Highlight the Models project and click OK.
Of course, this assumes that the Models project is in your solution to begin with. If it isn’t, you will first have to add it by right-clicking the first item in the Solution Explorer (the Solution itself), choosing “Add”, “Existing Project”, and then choosing the right csproj file for the Models project.
I am developing a Sketchflow (Silverlight) project in Expression Blend 3. It has been working fine up until today, now I cannot run the project. Specifically in the Project menu the "Run Project" option is now greyed out (all the other options are fine). F5 also doesn't have any effect.
I've obviously messed up the code somewhere but I can't find any information on what could cause the "Run Project" option to be disabled. This would obviously help the troubleshooting. Does anybody know what controls this functionality?
I can build the project no problem. And if I package the project (so it runs outside Expression) this also works fine. It is just launching it from Expression that doesn't work.
Right-click on the project (in the project pane) and verify that "Startup Project" is checked. I had obviously accidentally unchecked it at some point.
Usually when you create new Silverlight solution Blend or VS would create a solution with two projects in it. One would be called something like MyProject and another would be called smth. like MyProjectScreens.
The MyProjects doesn't contain much of Silverlight code, it's rather meant to be just "wrapper" (or in other words "it contains bootstrapping code for your actual SL screens") with Default.html and Default.aspx and App.xaml. And MyProject is the startup project.
The MyProjectScreens project in turn - is your actual SL project. (And it is NOT startup project).
THE SOLUTION TO OP'S PROBLEM, Maybe Blend somehow messed up solution configuration files (even though VS was fine with them) and my MyProject project has disappeared from the solution explorer. All you have to do is to right click on solution, click "Add Existing Project" and navigate to my solutions folder and choose the project file. (Yeah and also make sure that when MyProject is added it is marked as "Startup Project" (as #Hugh mentions).
HTH