2013-08-19 41 views
1

我遇到困难,试图在导入到空白项目的项目中引用方法/类。具体步骤重新创建此情况如下如何为导入的项目定义名称空间

  1. 下载并解压到一个临时文件夹http://mywsat.codeplex.com/
  2. 创建VS一个新的项目 - 一个名为WebApplication1
  3. 复制所有文件Asp.Net空的Web应用程序.NET 3.5从MYWSAT35文件夹跨越到新的项目
  4. 在VS解决方案资源管理器中,选择显示所有文件

如果现在建立和运行项目运行正常,没有错误。

5在VS解决方案资源管理,为所有导入的文件点击右键,选择包含在项目

现在尝试重建项目中,我得到的错误

The type or namespace name 'GetAdminMasterPage' could not be found 
(are you missing a using directive or an assembly reference?) 

GetAdminMasterPage.cs位于WebApplication1\App_Code\class\GetAdminMasterPage.cs看起来像这样

#region using references 
using System; 
using System.Configuration; 
using System.Data; 
using System.Data.SqlClient; 
using System.Web.Caching; 
using System.Web.UI; 
#endregion 

/// <summary> 
/// Gets the MasterPage for the user selected Admin Theme. 
/// </summary> 
public class GetAdminMasterPage : System.Web.UI.Page 
{ 
    #region Get Admin MasterPage 

    protected override void OnPreInit(EventArgs e) 
    { 
     if (Cache["cachedAdminMaster"] == null) 
     { 
      GetDefaultMasterPage(); 
     } 
     else 
     { 
      string loadMasterFromCache = Cache["cachedAdminMaster"].ToString(); 
      Page.MasterPageFile = loadMasterFromCache; 
     } 
    } 

    private void GetDefaultMasterPage() 
    { 
     try 
     { 
      SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbMyCMSConnectionString"].ConnectionString); 
      SqlCommand cmd = new SqlCommand("sp_admin_SelectMasterPage", con); 
      cmd.CommandType = CommandType.StoredProcedure; 

      con.Open(); 

      SqlDataReader myReader = cmd.ExecuteReader(CommandBehavior.SingleResult); 

      if (myReader.Read()) 
      { 
       string masterPageFileName = myReader["ThemeUrl"] as string; 
       Cache.Insert("cachedAdminMaster", masterPageFileName, null, DateTime.Now.AddSeconds(300), System.Web.Caching.Cache.NoSlidingExpiration); 
       Page.MasterPageFile = masterPageFileName; 
      } 

      myReader.Close(); 
      con.Close(); 
      con.Dispose(); 
     } 
     catch (Exception ex) 
     { 
      Response.Write(ex.Message); 
     } 
    } 

    #endregion 
} 

的,现在给出了一个错误的方法之一的一个例子是

using System; 

public partial class admin_admin_edit_css : GetAdminMasterPage 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
} 

//gives error The type or namespace name 'GetAdminMasterPage' could not be found 
(are you missing a using directive or an assembly reference?) 

所以我知道我必须参考GetAddminMasterPage Using xxxxxx;但只是不能找出正确的语法。

首先,为什么错误只发生在我选择“Include In Project”而不是刚被复制时?

其次,我该如何解决与GetAdminMasterPage的正确路径的错误?

+0

原始代码是网站“项目”吗?您的空白项目是一个Web应用程序项目吗? –

+0

是的,我认为是。这是否意味着这是不可能的? – user3357963

+0

这意味着你正在将苹果与橘子混合在一起,并且应该会有麻烦。我建议在本地下载下载的网站,右键单击并转换为Web应用程序,然后尝试使用该代码。 –

回答

2

将项目作为网站打开后,右键单击该项目并选择“转换为Web应用程序”。转换的结果是您想要移至空白项目的内容,或者您​​可能希望保留这些更改。

+0

谢谢 - 此链接非常有用http://blogs.msdn.com/b/webdev/archive/2009/10/29/converting-a-web-site-project-to-a-web-application-project。 ASPX – user3357963

2

注意:您不需要创建新项目。

1.复印在驱动器中MYWSAT35文件夹(例如:d:\ MYWSAT35)
2.in Visual Studio中转到文件 - >打开网站
3.select d:\ MYWSAT35并点击打开
4.按F5键运行应用程序

2

您必须将该项目作为网站打开。

如果您使用的是VS2010,那么它会提示您升级到.net 4.0。你可以选择不。

但是,如果您在VS2012中打开,它将在没有任何提示的情况下打开它。

两者都将成功构建。

相关问题