Solution3.AddFromFile 方法
向基于已存储在系统中的项目文件的解决方案添加一个项目。
命名空间: EnvDTE90
程序集: EnvDTE90(在 EnvDTE90.dll 中)
语法
声明
Function AddFromFile ( _
FileName As String, _
Exclusive As Boolean _
) As Project
Project AddFromFile(
string FileName,
bool Exclusive
)
Project^ AddFromFile(
[InAttribute] String^ FileName,
[InAttribute] bool Exclusive
)
abstract AddFromFile :
FileName:string *
Exclusive:bool -> Project
function AddFromFile(
FileName : String,
Exclusive : boolean
) : Project
参数
FileName
类型:String必需。 项目文件的完整路径及其文件名。
Exclusive
类型:Boolean可选。 指示项目是加载到当前解决方案中还是加载到它自己的解决方案中;如果当前解决方案已关闭,并且项目添加到新的解决方案中,则为 true;如果项目添加到已打开的现有解决方案中,则为 false。
返回值
类型:Project
一个 Project 对象。
备注
如果要在向导执行过程中不显示其用户界面,可以使用 LaunchWizard 方法来执行它,而不使用 AddFromFile。 LaunchWizard 具有一个可以禁用 UI 的参数。
示例
有关如何运行此外接程序代码的信息,请参见如何:编译和运行自动化对象模型代码示例。
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)
AddFromFileExample(_applicationObject)
End Sub
Sub AddFromFileExample(ByVal dte As DTE2)
' This add-in creates a solution and adds an
' existing project to it.
Try
Dim soln As Solution3 = _
CType(_applicationObject.Solution, Solution3)
' Create a new solution.
' Make sure the path below exists on your computer.
' You can modify the path.
soln.Create("c:\temp2", "MyNewSolution")
' Add an existing project to the new solution.
' Modify the path to a location that contains a
' Visual Studio project.
soln.AddFromFile _
("<default project location>\Visual Studio 2005\ _
Projects\ConsoleApplication\ConsoleApplication\ _
ConsoleApplication.csproj")
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
AddFromFileExample((DTE2)_applicationObject);
}
public void AddFromFileExample(DTE2 dte)
{
// This add-in creates a soultion and adds an
// existing project to it.
try
{
Solution3 soln = (Solution3)_applicationObject.Solution;
// Create a solution.
// Make sure that the file path specified below
// exists on your computer.
// You can modify the path.
soln.Create("c:\temp2", "MyNewSolution");
// Add an existing project to the new solution.
// Modify the path to a location that contains
// a Visual Studio project.
soln.AddFromFile(@"<default project location>
\Visual Studio 2005\Projects\ConsoleApplication
\ConsoleApplication\ ConsoleApplication.csproj", true);
}
catch(SystemException ex)
{
MessageBox.Show("ERROR: " + ex);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。