我正在开发与项目的构建/重建/清理相关的VS扩展。有谁知道如何通过VSSDK触发项目的构建/重建/清理操作?
答案 0 :(得分:1)
需要使用DTE实现:
Visual Studio自动化对象模型中的顶级对象。 有关此功能,请参考_DTE。不要从此实例化 课。
/// <summary>
/// Represents the field that
/// contain the AsyncPackage
/// instance.
/// </summary>
protected AsyncPackage AsyncPackage { get; set; }
/// <summary>
/// Represents the method that
/// retrieve the service with
/// the passed type.
/// </summary>
public async Task<T> GetServiceByTypeAsync<T>() where T : class
{
return await AsyncPackage.GetServiceAsync(typeof(T)) as T;
}
使用示例:
Env.DTE dte = await GetServiceByTypeAsync<EnvDTE.DTE>()
然后您可以访问当前的解决方案并构建配置:
dte.Solution.SolutionBuild.Build();
dte.Solution.SolutionBuild.Clean();
dte.Solution.SolutionBuild.BuildProject("Release", "UniqueName");
要查找某些项目:
foreach (Project project in dte.Solution.Projects)
{
dte.Solution.SolutionBuild.BuildProject("Release", project.UniqueName);
}
_DTE Interface | _Solution Interface | SolutionBuild Interface
答案 1 :(得分:0)
如果您不想使用DTE,请使用IVsSolutionBuildManager.StartSimpleUpdateSolutionConfiguration。
例如,这将重建解决方案
IVsSolutionBuildManager2 buildManager = ServiceProvider.GlobalProvider.GetService(typeof(SVsSolutionBuildManager)) as IVsSolutionBuildManager2;
if (ErrorHandler.Failed(buildManager.StartSimpleUpdateSolutionConfiguration((uint)(VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_FORCE_UPDATE | VSSOLNBUILDUPDATEFLAGS.SBF_OPERATION_BUILD),
(uint)VSSOLNBUILDQUERYRESULTS.VSSBQR_OUTOFDATE_QUERY_YES,
0/*false*/)))
{
//handle the error
}