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

我使用以下代码来构建项目.我想首先执行一个Clean(或者只是强制一个ReBuild我想?) – 但我找不到任何文档说明我是如何做到这一点的:

    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)
点赞