.designer文件未与Visual Studio中的.cs文件关联?

问题描述:

在Visual Studio中似乎存在一个视觉上的(?)错误.当我打开网站文件夹作为网站并查看Views.ascx.designer.cs时,它并不表示它已关联.但是,如果我打开同一网站的解决方案文件,则这些文件已关联,一切都很好.

There seems to be a visual (?) bug in visual studio. When I opened my website folder as a website and looked at my Views.ascx.designer.cs it doesn't show that it is associated. However, if I open that same website's solution file then the files are associated and all is well.

请明确一点,即使它仍显示以下错误消息,但它仍在工作,我认为将其作为网站而不是作为解决方案来打开是一个错误.

Just to be clear, even though it is still showing the below error messages it is working and I believe that it's a bug with opening it as a website instead of as a solution.

在我的实时网站上,我遇到了一个错误:

On my live site I have an error:

但是它应该存在,因为我在Views.ascx.designer.cs中拥有它:

But it should exist because I have it in my Views.ascx.designer.cs:

但是在Visual Studio中,我的Views.ascx.designer.cs未与我的View.ascx关联:

But in Visual Studio my Views.ascx.designer.cs is not being associated with my View.ascx:

我试图将.designer文件拖放到View.ascx上,但显示了此错误消息:

I tried to drag and drop the .designer file onto View.ascx but it displayed this error message:

它可以正常工作,并且在我的开发服务器上看起来还不错:

It works and looks perfectly fine on my dev server:

我不确定如何将文件与View.ascx或View.ascx.cs文件关联起来.

I'm not sure how I would go about getting the file to associate itself with the View.ascx or View.ascx.cs files.

第一步:右键单击文件并排除它们,然后尝试重新包含它们.它可能会自行修复.如果没有,您可以直接编辑项目.您只需添加CSPROJ或VBPROJ期望的依赖项.这是一个示例,您需要确保该示例位于项目XML中:

First step: right-click the files and exclude them, and try including them back in. It may fix itself. If not, you could edit the project directly; you just to add the dependency that the CSPROJ or VBPROJ expects. Here is an example that you need to make sure is in the project XML:

<Compile Include="Views\Main.aspx.designer.vb">
  <DependentUpon>Main.aspx</DependentUpon>
</Compile>
<Compile Include="Views\Main.aspx.vb">
  <DependentUpon>Main.aspx</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>