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

时间:2016-01-11 11:47:29

标签: .net vb.net build msbuild rebuild

我使用以下代码来构建项目。我想首先执行一个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)

1 个答案:

答案 0 :(得分:1)

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

我似乎无法找到同时接受目标和记录器的Build方法的适当重载,所以我现在分两步执行此操作,这似乎做了我想要的:

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

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

        buildSuceeded = thisProject.Build(_logger)