引用其自身的属性和成员当主网页将无法编译 [英] Master page won't compile when referencing its own properties and members

查看:226
本文介绍了引用其自身的属性和成员当主网页将无法编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在升级DOTNET的网站基于asp.net的WebForms到网络应用我在使用母版页的麻烦。

When upgrading a dotnet Web Site based on asp.net WebForms to a Web App I'm having trouble with Master pages.

我的母版页包含在他们的.aspx文件中的标记,这样的引用:

My Master pages contain, in their .aspx file markup, references like this:

<div>
   Name: <% =GetUserName() %>  Account: <% =AccountId %>
</div>

GetUserName()是我的母版页codebehind文件中定义的保护方法,而 ACCOUNTID 是在同一个地方一个受保护的领域。

GetUserName() is a protected method defined in my master page's codebehind file, and AccountId is a protected field in the same place.

在做Web应用程序升级(这涉及到自动生成一个 Site.Master.designer.cs codebehind文件后陪我自己的母版页(而不是codebehind)的Site.Master.cs codebehind文件)编译开始失败,在&LT拒绝保护的成员引用; %= GetUserName()%GT; 结构。 2015年VS智能感知说,在这种情况下没有定义 GetUserName。

After doing the Web App upgrade (which involves automatically generating a Site.Master.designer.cs codebehind file to accompany my own Site.Master.cs codebehind file) compilation of the Master page (not the codebehind) starts to fail, rejecting the protected member references in the <% =GetUserName() %> constructs. VS 2015 Intellisense says GetUserName not defined in this context.

不过的转到定义... 的VS2015的上下文菜单上的项目仍然可以工作,违规受保护的成员引用。奇怪的。

But the Go To Definition... item on VS2015's context menu still works for the offending protected member references. Weird.

当我做从头开始一个新的Web应用程序项目,它没有这个问题。我该如何解决这个问题?或者是有什么特别的升级网站预测,prevents这些受保护的成员引用?

When I make a new Web App project from scratch, it doesn't have this problem. How can I fix this? Or is there something special about upgraded Web Site projects that prevents these protected member references?

推荐答案

我想通了这一点。

的项目有关事项的顺序 project.csproj ,并从网站到Web应用程序转换并不总是正确。

The order of items matters in the project.csproj, and the conversion from Web Site to Web App doesn't always get it right.

要修复,关闭了VS2015,然后用文本编辑器打开你的 project.csproj 文件。 (它将被命名为您的项目。)查找&LT;编译...&GT; 为您的母版页的codebehind文件标签。

To fix, close up VS2015, then use a text editor to open your project.csproj file. (It will be named for your project.) Look for the <Compile...> tags for your Master page's codebehind files.

然后确保标签编译您自己的codebehind文件自带的之前一对了.Designer.cs code,是这样的:

Then make sure the tag to compile your own codebehind file comes before the one for the .designer.cs code, like this:

<Compile Include="Site.Master.cs">
  <DependentUpon>Site.Master</DependentUpon>
  <SubType>ASPXCodeBehind</SubType>
</Compile>
<Compile Include="Site.Master.designer.cs">
  <DependentUpon>Site.Master</DependentUpon>
</Compile>

在我的经验,这些标签被广泛分离在自动生成的 .csproj的文件。

In my experience, these tags were widely separated in the automatically generated .csproj file.

在任何情况下,搬家所以他们为了解决我的问题,其中之一。

At any rate, moving one of them so they were in order resolved my problem.

不要忘了清理,并在VS2015重建项目,如果你更改IDE之外的 .csproj的文件。

Don't forget to Clean and Rebuild your project in VS2015 if you change your .csproj files outside the IDE.

这篇关于引用其自身的属性和成员当主网页将无法编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆