如何使用 Microsoft.Build.Evaluation (MSBuild) 在构建之前执行清理

How do I perform a Clean before Building using Microsoft.Build.Evaluation (MSBuild)

我正在使用以下代码构建项目。我想先执行清理(或者我想只是强制执行重建?) - 但我找不到任何说明我如何执行此操作的文档:

    Private Shared _globalProp As Dictionary(Of String, String)
    Private Shared _logger As BuildLogger

    Dim thisProject As Project = Nothing
    Dim buildSuceeded As Boolean

    If _globalProp Is Nothing Then
        _globalProp = New Dictionary(Of String, String)
        _globalProp.Add("Configuration", "Release")
        _globalProp.Add("Platform", "x86")
    End If
    _logger = New BuildLogger

    thisProject = New Project(projectFilename, _globalProp, "14.0")
    buildSuceeded = thisProject.Build(_logger)

感谢@JerryM 指出了正确的方向。

我似乎找不到同时接受目标和记录器的 Build 方法的适当重载,所以我现在分两步进行,这似乎是我想要的:

        thisProject = New Project(projectFilename, _globalProp, "14.0")

        Dim targets As String() = {"Clean"}
        cleanSucceeded = thisProject.Build(targets)

        buildSuceeded = thisProject.Build(_logger)