升级到Visual Studio 2010后-类型或命名空间名称';xxxxxxxxx-ascx';不存在于

本文关键字:不存在 命名空间 xxxxxxxxx-ascx Visual Studio 2010 类型 | 更新日期: 2023-09-27 18:28:21

我们最近将网站项目升级到Visual Studio 2010。

每当我尝试在选中"允许此预编译网站可更新"的情况下发布网站时,我都会收到此错误。

这在以前使用Visual Studio 2008时起作用,所以我不确定为什么现在不起作用。

The type or namespace name 'xxxxxxxxx_ascx' does not exist in the namespace 'ASP' 
(are you     missing an assembly reference?)

导致错误的行都在做这种事情。

ASP.content_Controls_Info_ascx infoControl = new ASP.content_Controls_Info_ascx();
infoControl.Stages =  query.ToList();
PlaceHolder1.Controls.Add(infoControl);

我没有升级任何其他东西,所以点网框架仍然是3.5

该网站构建良好,并且在不选中"允许此预编译网站可更新"的情况下发布即可工作。代码的content_Controls_Info_ascx部分还突出显示了类名,以便查找它。

升级到Visual Studio 2010后-类型或命名空间名称';xxxxxxxxx-ascx';不存在于

.sln文件中查找与网站项目相关的部分。它看起来像这样:

Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "YourWebProject", "..'WEB'YourWebProject", "{A3774FE1-AA19-4A0F-94C9-FA58084B2429}"
    ProjectSection(WebsiteProperties) = preProject
        TargetFrameworkMoniker = ".NETFramework,Version%3Dv4.0"
        ProjectReferences = "..."
        Debug.AspNetCompiler.VirtualPath = "/YourWebProject"
        Debug.AspNetCompiler.PhysicalPath = "..'WEB'YourWebProject'"
        Debug.AspNetCompiler.TargetPath = "PrecompiledWeb'YourWebProject'"
        Debug.AspNetCompiler.Updateable = "true"
        Debug.AspNetCompiler.ForceOverwrite = "true"
        Debug.AspNetCompiler.FixedNames = "false"
        Debug.AspNetCompiler.Debug = "True"
        Release.AspNetCompiler.VirtualPath = "/YourWebProject"
        Release.AspNetCompiler.PhysicalPath = "..'WEB'YourWebProject'"
        Release.AspNetCompiler.TargetPath = "PrecompiledWeb'YourWebProject'"
        Release.AspNetCompiler.Updateable = "true"
        Release.AspNetCompiler.ForceOverwrite = "true"
        Release.AspNetCompiler.FixedNames = "false"
        Release.AspNetCompiler.Debug = "False"
        VWDPort = "2487"
    EndProjectSection
EndProject

并将以下属性设置为"false"(我使用记事本编辑.sln文件):

  • Debug.AspNetCompiler.Updateable="false"
  • Release.AspNetCompiler.Updateable="false"

默认情况下,它们被设置为"true",并出现错误:

命名空间"ASP"中不存在类型或命名空间名称"xxxxxxxxx_ascx"(您是否缺少装配参考?)

这个解决方案帮助了我。

这是网站模板的一个已知问题。解决方案是转换为Web应用程序项目。更多信息:

http://codersbarn.com/post/2008/06/01/ASPNET-Web-Site-versus-Web-Application-Project.aspx

http://www.west-wind.com/weblog/posts/2005/Sep/12/Understanding-Page-Inheritance-in-ASPNET-20

你可以检查你的参考资料,以防发生这种情况,但使用网站模板,你可能会再次遇到这个问题,尤其是在用户控件和外部项目/库方面。