VSProject.GetUniqueFilename(Object, String, String) 方法

定义

在项目中生成唯一的文件名。 用于命名新项目项。

public:
 System::String ^ GetUniqueFilename(System::Object ^ pDispatch, System::String ^ bstrRoot, System::String ^ bstrDesiredExt);
public:
 Platform::String ^ GetUniqueFilename(Platform::Object ^ pDispatch, Platform::String ^ bstrRoot, Platform::String ^ bstrDesiredExt);
std::wstring GetUniqueFilename(winrt::Windows::Foundation::IInspectable const & pDispatch, std::wstring const & bstrRoot, std::wstring const & bstrDesiredExt);
[System.Runtime.InteropServices.DispId(16)]
public string GetUniqueFilename (object pDispatch, string bstrRoot, string bstrDesiredExt);
[<System.Runtime.InteropServices.DispId(16)>]
abstract member GetUniqueFilename : obj * string * string -> string
Public Function GetUniqueFilename (pDispatch As Object, bstrRoot As String, bstrDesiredExt As String) As String

参数

pDispatch
Object

生成的名称将此值作为扩展。

bstrRoot
String

Project对象或文件夹 ProjectItem 对象。 生成的文件名在此上下文中是唯一的。

bstrDesiredExt
String

生成的名称将以该字符串开头。

返回

String

项目或项目文件夹中唯一的文件名。 如果第一个参数是 Project 实例,则生成的名称将在根项目文件夹中是唯一的。 文件名的格式为 Root。扩展,其中? (1、2、3等) 上的一个或多个数字。

属性

示例

[Visual Basic]

' This macro displays a file name that is unique in the   
' project folder, in the form root?.ext.  
' Macro editor  
Imports VSLangProj  
Imports VSLangProj80  
Sub GetUniqueName()  
   Dim proj As Project  
   proj = DTE.Solution.Projects.Item(1)  
   Dim vsproj As VSLangProj.VSProject = _  
      CType(proj.Object, VSLangProj.VSProject)  
   MsgBox(vsproj.GetUniqueFilename(proj, "Root", "ext"))  
End Sub  

注解

此方法的典型用途是为新的项目项生成名称。

如果将 KeyFile 作为根和 .snk 作为扩展调用此方法,则返回的字符串为 keyfile,如果文件 keyfile 不存在,则返回。 如果文件 KeyFile 已存在,则返回 KeyFile1 。 请注意,如果对此方法进行了多个调用,并且没有从返回的文件名创建任何文件,则所有调用都将返回相同的值。 结果仅依赖于方法调用时存在的文件。

适用于