DTE.SolutionBuild不构建项目

时间:2018-11-01 13:45:39

标签: c# .net msbuild visual-studio-extensions csproj

im试图使用DTE.SolutionBuild接口在Visual Studio扩展(.vsix)中构建csproj:

private void BuildProject(Project vsProject)
{
        var sb = vsProject.DTE.Solution.SolutionBuild as SolutionBuild;
        sb.SolutionConfigurations.Item(1).Activate();
        sb.BuildProject(sb.SolutionConfigurations.Item(1).Name, vsProject.UniqueName, true);
}

但是由于某种原因,该项目没有编译。没有显示错误,创建了一个名为SolutionConfiguration的文件夹,但未生成项目程序集。任何帮助都非常感谢。

UPDATE1:我也尝试过,结果是相同的:

Microsoft.Build.Evaluation.Project p = new Microsoft.Build.Evaluation.Project(vsProject.FullName);
p.Build();

1 个答案:

答案 0 :(得分:1)

我是这样的:

private void Execute(object sender, EventArgs e)
{
    ThreadHelper.ThrowIfNotOnUIThread();

    _SelectedObject = this.GetProjectItem();
    _VsProject = _SelectedObject.ContainingProject;
    this.BuildProject(_VsProject);
}

private void BuildProject(EnvDTE.Project vsProject)
{
    DTE2 dte = Package.GetGlobalService(typeof(EnvDTE.DTE)) as DTE2;
    dte.Events.BuildEvents.OnBuildDone -= BuildEvents_OnBuildDone;
    dte.Events.BuildEvents.OnBuildDone += BuildEvents_OnBuildDone;
    dte.ExecuteCommand("Build.RebuildSolution");
}

private void BuildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
{
    //Your action after build here
}