11

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?

ProfK
  • 49,207
  • 121
  • 399
  • 775
  • 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. – Mike Grove aka Theophilus Jun 09 '16 at 13:47

2 Answers2

12

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.

jmoreno
  • 12,752
  • 4
  • 60
  • 91
  • 9
    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. – ProfK Aug 20 '11 at 11:18
  • 2
    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" – Eric Barr Sep 24 '15 at 15:26
  • Kind of weird that this would not be on by default. Should I be defining layouts in code? – John Glen Aug 03 '23 at 02:13
  • @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. – jmoreno Aug 03 '23 at 02:41
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."

justisb
  • 7,081
  • 2
  • 26
  • 44
  • 1
    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. – DanM7 Sep 29 '15 at 15:00
  • 2
    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: https://connect.microsoft.com/VisualStudio/feedback/details/590046/show-related-code-behind-files-for-vb-net-web-applications-in-solution-explorer – justisb Sep 29 '15 at 17:07
  • Saw that link in my search, but didn't realize he was an MS dev. Thanks for that! – DanM7 Sep 29 '15 at 17:47
  • 1
    For anyone interested in David's comment, Connect is gone, but the wayback has it: https://web.archive.org/web/20140406095522/https://connect.microsoft.com/VisualStudio/feedback/details/590046/show-related-code-behind-files-for-vb-net-web-applications-in-solution-explorer – jmoreno Aug 03 '23 at 02:36