BuildDependency.AddProject 方法
向必须首先生成的项目的列表中添加项目。
命名空间: EnvDTE
程序集: EnvDTE(在 EnvDTE.dll 中)
语法
声明
Sub AddProject ( _
ProjectUniqueName As String _
)
void AddProject(
string ProjectUniqueName
)
void AddProject(
String^ ProjectUniqueName
)
abstract AddProject :
ProjectUniqueName:string -> unit
function AddProject(
ProjectUniqueName : String
)
参数
- ProjectUniqueName
类型:System.String
必选。UniqueName 属性中要作为依赖项添加的项目的名称。
备注
如果 AddProject 调用创建了一个生成依赖项循环,则调用将失败。
示例
Sub AddProjectExample(ByVal dte As DTE)
' Create a new solution.
Dim soln As Solution = dte.Solution
Dim solnName As String = "NewSolution.sln"
Dim tempPath As String = System.IO.Path.GetTempPath()
soln.Create(tempPath, solnName)
' Create two new Visual Basic Console Application projects.
Dim templatePath As String = <template path>
templatePath &= "ConsoleApplication.vsz"
Dim projName As String = "Project1"
soln.AddFromTemplate(templatePath, tempPath & projName, projName)
Dim proj1 As Project = soln.Item(1)
projName = "Project2"
soln.AddFromTemplate(templatePath, tempPath & projName, projName)
Dim proj2 As Project = soln.Item(2)
' Make Project1 dependent on Project2.
Dim bd As BuildDependency = _
soln.SolutionBuild.BuildDependencies.Item(proj1.UniqueName)
bd.AddProject(proj2.UniqueName)
' Enumerate Project1's dependencies.
Dim depends As String = ""
Dim proj As Project
For Each proj In CType(bd.RequiredProjects, Array)
depends &= proj.Name & vbCrLf
Next
MsgBox(bd.Project.Name & " has the following dependencies:" & _
vbCrLf & vbCrLf & depends)
End Sub
public void AddProjectExample(DTE dte)
{
// Create a new solution.
Solution soln = dte.Solution;
string solnName = "NewSolution.sln";
string tempPath = System.IO.Path.GetTempPath();
soln.Create(tempPath, solnName);
// Create two new C# Console Application projects.
string templatePath = <template path>;
templatePath += "CSharpConsole.vsz";
string projName = "Project1";
soln.AddFromTemplate(templatePath, tempPath + projName,
projName, false);
Project proj1 = soln.Item(1);
projName = "Project2";
soln.AddFromTemplate(templatePath, tempPath + projName,
projName, false);
Project proj2 = soln.Item(2);
// Make Project1 dependent on Project2.
BuildDependency bd =
soln.SolutionBuild.BuildDependencies.Item(proj1.UniqueName);
bd.AddProject(proj2.UniqueName);
// Enumerate Project1's dependencies.
string depends = "";
foreach (Project proj in (Array)bd.RequiredProjects)
{
depends += proj.Name + Environment.NewLine;
}
MessageBox.Show(bd.Project.Name +
" has the following dependencies:" + "\r\n\r\n" + depends);
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。