共用方式為


VSProject2.GetUniqueFilename 方法

會在專案內的唯一檔名。它用來命名新的專案項目使用。

命名空間:  VSLangProj80
組件:  VSLangProj80 (在 VSLangProj80.dll 中)

語法

'宣告
Function GetUniqueFilename ( _
    pDispatch As Object, _
    bstrRoot As String, _
    bstrDesiredExt As String _
) As String
string GetUniqueFilename(
    Object pDispatch,
    string bstrRoot,
    string bstrDesiredExt
)
String^ GetUniqueFilename(
    [InAttribute] Object^ pDispatch, 
    [InAttribute] String^ bstrRoot, 
    [InAttribute] String^ bstrDesiredExt
)
abstract GetUniqueFilename : 
        pDispatch:Object * 
        bstrRoot:string * 
        bstrDesiredExt:string -> string
function GetUniqueFilename(
    pDispatch : Object, 
    bstrRoot : String, 
    bstrDesiredExt : String
) : String

參數

  • pDispatch
    類型:Object

    產生的檔名將以這個值當做副檔名。

  • bstrRoot
    類型:String

    Project 物件或資料夾 ProjectItem 物件。 產生的檔名是這個內容內的唯一檔名。

  • bstrDesiredExt
    類型:String

    產生的檔名將以這個字串開頭。

傳回值

類型:String
字串,代表專案或專案資料夾中唯一的檔名。如果第一個參數是 Project 執行個體,則產生的檔名在根專案資料夾內就不會與其他檔名重複。這個檔案名稱的格式為 Root?.Extension,其中 ? 為一個或多個數字 (1、2、3 依此類推)。

備註

這個方法的典型用法是產生新專案項目的名稱。

如果您使用 KeyFile 做為根和 snk 做為副檔名來呼叫這個方法,並且如果 KeyFile.snk 檔尚未存在,則傳回的字串為 KeyFile.snk。 如果 KeyFile.snk 檔已存在,則傳回的字串為 KeyFile1.snk。 請注意,如果對這個方法進行多次呼叫,則不會從傳回的檔名來建立檔案,所有的呼叫都將傳回相同值。 結果僅取決於呼叫方法時存在的檔案。

範例

這個範例顯示專案資料夾中的唯一檔名,其格式為 root?.ext。若要將此範例當做增益集來執行,請參閱 如何:編譯和執行 Automation 物件模型程式碼範例。 開啟 Visual Basic 或 Visual C# 專案,再執行此範例。

[Visual Basic]

' This example displays a file name that is unique in the 
     ' project folder, in the form, root?.ext.
Public Sub OnConnection(ByVal application As Object,_
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    applicationObject = CType(application, DTE2)
    addInInstance = CType(addInInst, AddIn)
    GetUniqueName(applicationObject)
End Sub
Sub GetUniqueName(ByVal dte As DTE2)
    Dim proj As Project
    proj = applicationObject.Solution.Projects.Item(1)
    Dim vsproj As VSLangProj80.VSProject2 = _
    CType(proj.Object, VSLangProj80.VSProject2)
    MsgBox(vsproj.GetUniqueFilename(proj, "Root", "ext"))
End Sub

[C#]

using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
// This example displays a file name that is unique in the 
// project folder, in the form, root?.ext.
public void OnConnection(object application,
 ext_ConnectMode connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    GetUniqueName((DTE2)applicationObject);
}
public void GetUniqueName(DTE2 dte)
{
    Project proj = null;
    proj = applicationObject.Solution.Projects.Item(1);
    VSLangProj80.VSProject2 vsproj = 
((VSLangProj80.VSProject2)(proj.Object));
    MessageBox.Show(vsproj.GetUniqueFilename(proj, "Root", "ext"));
}

.NET Framework 安全性

請參閱

參考

VSProject2 介面

VSLangProj80 命名空間