簡體   English   中英

如何為導入的項目定義名稱空間

[英]How to define namespace for imported project

我真的很難嘗試引用導入到空白項目的項目中的方法/類。 重新創建此文件的確切步驟如下

  1. 下載並解壓縮到臨時文件夾http://mywsat.codeplex.com/
  2. 在VS中創建一個新項目-Asp.Net空Web應用程序.NET 3.5,名為WebApplication1
  3. 將所有文件從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?)

所以我知道我必須Using xxxxxx;來引用GetAdminMasterPage Using xxxxxx; 但只是找不到正確的語法。

首先,為什么僅當我選擇“包含在項目中”而不是僅在復制時才發生錯誤?

其次,如何使用正確的GetAdminMasterPage路徑修復錯誤?

注意:您不創建新項目。

1.將MYWSAT35文件夾復制到驅動器中(例如:d:\\ MYWSAT35)
2.在Visual Studio中轉到文件->打開網站
3.選擇d:\\ MYWSAT35並單擊打開
4.按F5鍵運行應用程序

您必須作為網站打開該項目。

如果您使用的是VS2010,它將提示您升級到.net 4.0。 您可以選擇不。

但是,如果您在VS2012中打開,它將在沒有提示的情況下將其打開。

兩者都將成功構建。

在將項目作為網站打開后,右鍵單擊該項目,然后選擇“轉換為Web應用程序”。 轉換的結果是您想要移至空白項目的內容,或者您​​可能希望將更改保留在原處。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM