VS2015 - VB/ASP.NET Build fake error: "Type 'XYZ' is not defined" in UserControl code-behind
VS2015 - VB/ASP.NET Build fake error: "Type 'XYZ' is not defined" in UserControl code-behind
好吧伙计们,这并不容易...
对于这个故事,我有一个旧的 3.5 ASP.NET/VB.NET 网站项目 (ASPX) 构建在 VS2012 上,我已经升级到 4.5 到 运行 在 VS2015 上很好。
我还试图删除它得到的所有编译错误,即使该网站在它们下工作(VB.NET 很奇怪...)
在此操作期间,我得到了一些未更改的代码,这些代码以前运行良好,但它们不再让我使用 运行。
所以,这是构建问题:
我有一个 UserControl (private/UserControls/Fiche/OngletAccueil.ascx
),用于页面 (private/fiche.aspx
),它需要 MasterPage (private/MasterPage.master
) 中的一些值。
它们都使用相同的命名空间Vita
,这里摘录一些来理解:
主页:
Namespace Vita
Partial Public Class private_MasterPage
Inherits System.Web.UI.MasterPage
Public _debug As Integer = HttpContext.Current.Request.Params("debug")
Public ReadOnly Property ModeDebug As Integer
Get
Return _debug
End Get
End Property
...
用户控件:
Namespace Vita
Public Class private_UserControls_Fiche_OngletAccueil
Inherits System.Web.UI.UserControl
Public ReadOnly Property modeDebug As Integer
Get
Return DirectCast(Me.Page.Master, private_MasterPage).ModeDebug
End Get
End Property
...
ASPX 页面:
<%@ Page Async="true" Title="" Language="VB" MasterPageFile="~/private/MasterPage.master" AutoEventWireup="false" CodeFile="fiche.aspx.vb" Inherits="Vita.public_fiche" %>
<%@ Register TagPrefix="Tools" TagName="OngletAccueil" Src="UserControls/Fiche/OngletAccueil.ascx" %>
...
因此,我在 UserControl 中遇到了有关 MasterPage class 类型的编译错误:
Type 'private_MasterPage' is not defined.
在 \private\UserControls\Fiche\OngletAccueil.ascx.vb
我什至不明白为什么它不 运行 IISexpress 在以前的框架上没问题...
我给你看代码是为了让你明白代码并不是真正的问题:问题似乎来自智能感知或编译临时文件,比如 MasterPage class 不能被 UserControl 看到(范围访问),因为它们不在同一个临时程序集中。
之前,我遇到了将 userControl 用于另一个 userControl 的相同问题(哪些文件保存在完全相同的文件夹中......),但我能够用 web.config
设置,似乎有效:
<pages>
<controls>
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/PosteUser.ascx" tagName="PosteUser" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/NotesDeFrais.ascx" tagName="NotesDeFrais" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/Evals_CollaborateursInternes.ascx" tagName="EvalsCollaborateursInternes" />
</controls>
</pages>
但是在这里,MasterPage不是一个控件,它是一个页面,我不能用同样的技巧...
感谢大家的帮助,我已经花了很多时间在这上面 post 之前我确实分析了一堆问答和 MSDN 文档,你是我最后的希望: '(
这里是关于 web.config
的一些最新且有用的信息:
<supportedRuntime version="v4.0"/>
...
<compilation debug="true" batch="false" strict="false" explicit="true" targetFramework="4.5">
...
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
...
好的伙计们,我知道了,通过更换 PC...
我认为问题出在不同版本的 VS 上编译项目。
我在 2012 年只对我的项目进行了一次编译,然后在 2015 年的编译出现了这个无法破解的错误...
因此,即使您清除一些临时文件夹,如 AppData\Local\Temp\Temporary ASP.NET Files
、AppData\Local\Temp\VWDWebCache
或 .vs\project\v14\.suo
,也不够。
在对出现的其他内容进行更多调试后,我现在可以零错误进行编译,并且在进行更多调试后也可以发布。现在我在运行时遇到了一些其他问题,它仍然没有像以前那样完全工作,但它越来越接近了;)
更新
我之前为编译所做的工作但没有解决运行时问题(错误在运行时作为 InvalidCastException 返回)。
为了解决运行时问题,我刚刚检查了 Build/Publish 选项 "use fixed naming and single page assemblies",它解决了我的问题:)
取消勾选构建(和发布)选项 "Allow this precompiled site to be updatable"
这里有一些有用的链接:https://msdn.microsoft.com/en-us/library/hh475319(v=vs.110).aspx
好吧伙计们,这并不容易...
对于这个故事,我有一个旧的 3.5 ASP.NET/VB.NET 网站项目 (ASPX) 构建在 VS2012 上,我已经升级到 4.5 到 运行 在 VS2015 上很好。 我还试图删除它得到的所有编译错误,即使该网站在它们下工作(VB.NET 很奇怪...)
在此操作期间,我得到了一些未更改的代码,这些代码以前运行良好,但它们不再让我使用 运行。
所以,这是构建问题:
我有一个 UserControl (private/UserControls/Fiche/OngletAccueil.ascx
),用于页面 (private/fiche.aspx
),它需要 MasterPage (private/MasterPage.master
) 中的一些值。
它们都使用相同的命名空间Vita
,这里摘录一些来理解:
主页:
Namespace Vita
Partial Public Class private_MasterPage
Inherits System.Web.UI.MasterPage
Public _debug As Integer = HttpContext.Current.Request.Params("debug")
Public ReadOnly Property ModeDebug As Integer
Get
Return _debug
End Get
End Property
...
用户控件:
Namespace Vita
Public Class private_UserControls_Fiche_OngletAccueil
Inherits System.Web.UI.UserControl
Public ReadOnly Property modeDebug As Integer
Get
Return DirectCast(Me.Page.Master, private_MasterPage).ModeDebug
End Get
End Property
...
ASPX 页面:
<%@ Page Async="true" Title="" Language="VB" MasterPageFile="~/private/MasterPage.master" AutoEventWireup="false" CodeFile="fiche.aspx.vb" Inherits="Vita.public_fiche" %>
<%@ Register TagPrefix="Tools" TagName="OngletAccueil" Src="UserControls/Fiche/OngletAccueil.ascx" %>
...
因此,我在 UserControl 中遇到了有关 MasterPage class 类型的编译错误:
Type 'private_MasterPage' is not defined.
在 \private\UserControls\Fiche\OngletAccueil.ascx.vb
我什至不明白为什么它不 运行 IISexpress 在以前的框架上没问题...
我给你看代码是为了让你明白代码并不是真正的问题:问题似乎来自智能感知或编译临时文件,比如 MasterPage class 不能被 UserControl 看到(范围访问),因为它们不在同一个临时程序集中。
之前,我遇到了将 userControl 用于另一个 userControl 的相同问题(哪些文件保存在完全相同的文件夹中......),但我能够用 web.config
设置,似乎有效:
<pages>
<controls>
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/PosteUser.ascx" tagName="PosteUser" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/NotesDeFrais.ascx" tagName="NotesDeFrais" />
<add tagPrefix="Tools" src="~/private/UserControls/Fiche/Evals_CollaborateursInternes.ascx" tagName="EvalsCollaborateursInternes" />
</controls>
</pages>
但是在这里,MasterPage不是一个控件,它是一个页面,我不能用同样的技巧...
感谢大家的帮助,我已经花了很多时间在这上面 post 之前我确实分析了一堆问答和 MSDN 文档,你是我最后的希望: '(
这里是关于 web.config
的一些最新且有用的信息:
<supportedRuntime version="v4.0"/>
...
<compilation debug="true" batch="false" strict="false" explicit="true" targetFramework="4.5">
...
<pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
...
好的伙计们,我知道了,通过更换 PC...
我认为问题出在不同版本的 VS 上编译项目。
我在 2012 年只对我的项目进行了一次编译,然后在 2015 年的编译出现了这个无法破解的错误...
因此,即使您清除一些临时文件夹,如 AppData\Local\Temp\Temporary ASP.NET Files
、AppData\Local\Temp\VWDWebCache
或 .vs\project\v14\.suo
,也不够。
在对出现的其他内容进行更多调试后,我现在可以零错误进行编译,并且在进行更多调试后也可以发布。现在我在运行时遇到了一些其他问题,它仍然没有像以前那样完全工作,但它越来越接近了;)
更新
我之前为编译所做的工作但没有解决运行时问题(错误在运行时作为 InvalidCastException 返回)。
为了解决运行时问题,我刚刚检查了 Build/Publish 选项 "use fixed naming and single page assemblies",它解决了我的问题:)
取消勾选构建(和发布)选项 "Allow this precompiled site to be updatable"
这里有一些有用的链接:https://msdn.microsoft.com/en-us/library/hh475319(v=vs.110).aspx