VSProject2.GetUniqueFilename(Object, String, String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在项目中生成唯一的文件名。 它用于命名新项目项。
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
生成的名称以该字符串开头。
返回
一个字符串,该字符串表示在项目或项目文件夹中唯一的文件名。 如果第一个参数是 Project 实例,则生成的名称在根项目文件夹中是唯一的。 文件名的格式为 Root。扩展,其中? (1、2、3等) 上的一个或多个数字。
实现
- 属性
示例
此示例显示项目文件夹中唯一的文件名,格式为 root?。宋体. 若要将此示例作为外接程序运行,请参阅 如何:编译和运行自动化对象模型代码示例。 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"));
}
注解
此方法的典型用途是为新的项目项生成名称。
如果将 KeyFile 作为根和 .snk 作为扩展调用此方法,则返回的字符串为 KeyFile,如果文件 KeyFile 不存在,则返回。 如果文件 KeyFile 已存在,则返回 KeyFile1。 请注意,如果对此方法进行了多个调用,并且没有从返回的文件名创建文件,则所有调用都将返回相同的值。 结果仅依赖于方法调用时存在的文件。