0

I have MS Build script for building my project. Building logic is not trivial, so I implement custom MS Build task, which runed by build script. In task i use such code

   project.Build();

but, when this code called, I saw exception, with message:"can't start build, building already running". How can I build project programmatically, using MS Build API, in custom task, which runned by build script?

Code of task:

    public class SimpleTask : Task
{
    public override bool Execute()
    {
        try
        {
            var project = ProjectCollection.GlobalProjectCollection.LoadProject("C:/dummy.csproj");
            project.Build();
            return true;

        }
        catch (Exception ex)
        {
            return false;
        }
    }
}

Example of using inside ms build script

    <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
       <UsingTask TaskName="ClassLibrary1.SimpleTask" 
    AssemblyFile="ClassLibrary1.dll"/>
       <Target Name="MyTarget">
         <SimpleTask />
       </Target>
   </Project>

Command that failed :project.Build(); Exception message:"Could not complete the operation because the building is already in progress."

IComparable
  • 71
  • 1
  • 1
  • 10

0 Answers0