user31673
user31673

Reputation: 13695

ASP.NET code behind file not nested under the related aspx file in Visual Studio

In my C# ASP.NET Web Site using .NET Framework 4.0, I have a couple of pages where the related .cs file is not under its related aspx file. I recently moved the files to a subdirectory. I have 10 pages and for 8 of them the move worked just fine and the .cs file is under the aspx. However for two pages, the .cs file now no longer shows below the aspx file. How can I fix this so that the cs is shown correctly underneath the aspx file? When I compare the top of the markup pages, the two problem pages look just like the other 8 pages. I don't see any issues there.

Upvotes: 4

Views: 4184

Answers (4)

SkinnyPete63
SkinnyPete63

Reputation: 653

I know this is a very old thread, but I just encountered it and the above solutions did not resolve my problem, they made it worse. When I added:

<Compile Include="blah.child">
  <DependentUpon>blah.parent</DependentUpon>
</Compile>

I got a compile error "Duplicate 'Compile' items were included.", despite this being the only compile tag in the project. The answer was to change it to this:

<Compile Update="blah.child">
  <DependentUpon>blah.parent</DependentUpon>
</Compile>

Clean, rebuild and my files were nicely nested once again.

Upvotes: 0

Chris F Carroll
Chris F Carroll

Reputation: 12370

In general for VS projects the nesting is driven by the <DependentUpon/> element. You can fix it by editing the project file directly. Change:

    <Compile Include="blah.child" />

To:

    <Compile Include="blah.child">
      <DependentUpon>blah.parent</DependentUpon>
    </Compile>

This works for any nested files, like .sass -> .css -> .min.css

    <Compile Include="blah.css">
      <DependentUpon>blah.scss</DependentUpon>
    </Compile>
    <Compile Include="blah.min.css">
      <DependentUpon>blah.css</DependentUpon>
    </Compile>

Upvotes: 2

user31673
user31673

Reputation: 13695

I found the way to fix this. First I tried excluding and including the files in the Solution Explorer but that resulted in the same results. The way to fix this is to move the files out of the project, then refresh the Solution Explorer. At this point, the files will no longer be part of the project. Then move the files back into the project. Then refresh and the .cs files should be shown below their associated aspx files.

Upvotes: 4

rciq
rciq

Reputation: 1309

First make sure they have the same name (except for the extension of course). If this does not help and it's a Web Application then try removing the 3 files (.aspx, .aspx.cs, aspx.designer.cs) from the project by right-click -> 'exclude from project'. Then add them again. The easiest way is to show all files (hint: screenshot), then right-click -> 'Include in project'.

VS 2010 Solution Explorer

Upvotes: 8

Related Questions