Why are code-behind files not visible in a VB.NET Web Application project?
Asked Answered
P

2

12

I am trying to convert a VB.NET web site project to a web application project, yet the in web application project, my code-behind files are not visible unless I set the solution explorer "show all files" option. Why is this? What setting can I change so that my code behind files are always visible?

Paneling answered 17/8, 2011 at 11:0 Comment(1)
A note for readers. This problem does not occur with Web Site projects -- just Web Application projects. This is true in Visual Studio 2012. I don't know about VS 2013 or 2015.Maegan
S
13

You can set VS to always show all files. That's the best soluution although a really ugly way to avoid this would be to rename the files for the code behind.

Sipper answered 20/8, 2011 at 6:31 Comment(4)
Yes, that is ugly, but it seems stupid to me that it shows code-behind files for C# apps, but not for VB, giving the impression that MS thinks VB users are too stupid to handle a slightly more complex view in Solution Explorer.Paneling
As far as how to Show All Files, select the Project (not the Solution) in the Solution Explorer window. An icon will then appear in the Solution Explorer toolbar for "Show All Files"Furlong
Kind of weird that this would not be on by default. Should I be defining layouts in code?Arsenopyrite
@JohnGlen: depends upon how you work, I typically use the solution filter to find files that I know exist, but which aren't open, so it's not problem for me. And if I'm working in the code behind file for an aspx page, I'll probably be toggling back and forth between the two, so open which ever is handy and then F7 to switch.Sipper
F
6

I know this is a bit of an old question, but it's the top result on Google and I found an alternate solution.

Open your .vbproj file for the project in a text editor, and search for your codebehind file's name. You'll find that it looks something like this:

<Compile Include="dashboard\index.aspx.vb">
  <DependentUpon>index.aspx</DependentUpon>
  <SubType>ASPXCodebehind</SubType>
</Compile>

If you simply remove the DependentUpon tag, everything will still work properly, but both files will show up in Visual Studio, as desired. So my final version would look like this:

<Compile Include="search\index.aspx.vb">
  <SubType>ASPXCodeBehind</SubType>
</Compile>

It takes a little bit of manual editing but it works for me. Alternatively if you manually rename/edit your files into a page/codebehind format after creating regular class files, they will appear as wanted in the project without having to resort to "Show All Files."

Fasta answered 20/9, 2013 at 19:55 Comment(4)
When you do "Show All Files" the code behind and designer pages are nested under the .aspx file. With your method, the file is listed completely separately. Is there a change you can make in the .vbproj file to get the code behind file to become visible but nested under the .aspx file? Otherwise, great solution. Allows you to pick which files exactly to show.Lingenfelter
I think the DependentUpon flag is what is normally used to nest the files, but it's specifically disabled for VB files because evidently it's too complex of a feature for VB devs. See MS dev David Nelson's comment at the bottom of this feedback: connect.microsoft.com/VisualStudio/feedback/details/590046/…Fasta
Saw that link in my search, but didn't realize he was an MS dev. Thanks for that!Lingenfelter
For anyone interested in David's comment, Connect is gone, but the wayback has it: web.archive.org/web/20140406095522/https://…Sipper

© 2022 - 2024 — McMap. All rights reserved.