开发者

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.


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'.

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


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.


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜