简体   繁体   中英

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

I am using the following code to build a project. I want to perform a Clean first (or just force a ReBuild I suppose?) - but I can't find any documentation stating how I do this:

    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)

Credit to @JerryM for pointing in the right direction.

I couldn't seem to find an appropriate overload of the Build method that accepted the targets and a logger at the same time, so I am doing this in two steps for now, this seems to do what I want:

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

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

        buildSuceeded = thisProject.Build(_logger)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM