我在试图引用导入到空白项目中的项目中的方法/类时,真的被困住了。重新创建这一过程的确切步骤如下
如果您现在构建并运行该项目,则项目运行良好,没有任何错误。
5在VS解决方案资源管理器中,右击所有导入的文件并选择Include In Project
现在,尝试重新构建项目,我得到了错误
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?)因此,我知道我必须使用GetAdminMasterPage来引用Using xxxxxx;,但我只是找不出正确的语法。
首先,为什么错误只发生在我选择“包括在项目”,而不是当只是复制?
其次,如何用正确的GetAdminMasterPage路径修复错误?
发布于 2013-08-19 20:27:08
将项目作为网站打开后,右键单击该项目并选择“转换为web应用程序”。转换的结果是您想要移动到您的空白项目,或者您可能希望保留更改的位置。
发布于 2013-08-19 19:56:41
你必须把这个项目作为一个网站来打开。
如果您使用的是VS2010,那么它将提示您升级到.net 4.0。你可以选择不。
但是如果您在VS2012中打开它,它将在没有提示的情况下打开它。
两者都会成功地建立起来。
https://stackoverflow.com/questions/18321507
复制相似问题