locked
Microsoft.Build.BuildEngine Throwing Unexpected Errors RRS feed

  • Question

  • I am using the Microsoft.Build.BuildEngine to build a couple of .csproj files.  With the release of Beta 2 I have updated the application using the Microsoft.Build.BuildEngine to .net 4.0 beta 2.  I have two current issues:

    1) Projects that have been upgraded to .net 4.0 beta 2
    These projects build fine in VS2010 beta 2, but when using the Microsoft.Build.BuildEngine I get a number of CS0246 "The type or namespace name 'XYZ' could not be found (are you missing a using directive or an assembly reference?)" and then a "Done building target "CoreCompile" in project "p5h2skhj.tmp_proj" -- FAILED.  It appears to build all the "real" projects correctly, but then fails on a couple of these ".tmp_proj" ones.  But I am unable to find these .tmp_proj or references to them (not in solution or project files etc...).  I've read they might be "blend related", but why/how are they trying to be built?  How do I stop that from occurring?


    2) Projects that have not been upgraded and are using .net 3.5 SP1
    These projects build fine in VS2008, but when using the Microsoft.Build.BuildEngine I get a number of CS0246 "The type or namespace name 'XYZ' could not be found (are you missing a using directive or an assembly reference?)" - I do not get these errors in the code and everything appears to be referenced correctly.  Is it not possible to build .net 3.5 SP1 applications with .net 4.0 Microsoft.Build.BuildEngine?

    Thanks for any help on either of these two issues,
    Chris

    UPDATE: if I have a .net 4.0 beta 2 application with no dependencies it will build that application correctly. however, as soon as i add a class library and reference that class library from the application being built it will fail with a message about not being able to reference the object etc...
    Thursday, December 17, 2009 1:20 AM

Answers

  • 1) This works for me (without any errors):
    // Compile: csc.exe /r:Microsoft.Build.Engine.dll /r:Microsoft.Build.Framework.dll 
    //                  /r:Microsoft.Build.dll MyBuilder.cs
    using Microsoft.Build.Evaluation;
    class MyBuilder
    {
      static void Main(string[] args)
      {
        Project project = ProjectCollection.GlobalProjectCollection.LoadProject(args[0]);
        project.Build(new Microsoft.Build.BuildEngine.ConsoleLogger());
      }
    }

    2) The above example compiles 3.5 projects fine as well.

    -Karel
    Thursday, December 17, 2009 6:22 PM
    Moderator
  • Re: Using BuildEngine.Project ... pay attention to the compiler warnings - it will tell you that this API is obsolete (MSDN also mentions it).

    Please use new thread for follow up questions next time.

    Here are some answers:
    1) GetEvaluatedProperty was probably moved to Project.GetPropertyValue.
    2) I don't think there's a document like that. I can ask MSBuild team if they plan to publish such conversion document - I agree it would be handy. I had quite hard time to figure out how to make the new API work.

    -Karel
    Tuesday, December 22, 2009 7:16 PM
    Moderator

All replies

  • 1) Create a small repro (10-20 lines) of your building application and paste it here.

    BTW: class Microsoft.Build.BuildEngine.Engine seems to be obsolete in 4.0 Beta2, did you use ProjectCollection?
    When I used the obsolete class Engine, the C# compiler command didn't get the reference to the dependent project binary which caused different error, but I guess it is in the same category.

    2) Did you set correct Toolset (2.0/3.5)?

    -Karel

    Thursday, December 17, 2009 6:03 PM
    Moderator
  • 1) This works for me (without any errors):
    // Compile: csc.exe /r:Microsoft.Build.Engine.dll /r:Microsoft.Build.Framework.dll 
    //                  /r:Microsoft.Build.dll MyBuilder.cs
    using Microsoft.Build.Evaluation;
    class MyBuilder
    {
      static void Main(string[] args)
      {
        Project project = ProjectCollection.GlobalProjectCollection.LoadProject(args[0]);
        project.Build(new Microsoft.Build.BuildEngine.ConsoleLogger());
      }
    }

    2) The above example compiles 3.5 projects fine as well.

    -Karel
    Thursday, December 17, 2009 6:22 PM
    Moderator
  • I had been using:
    var projectToBuild = new Microsoft.Build.BuildEngine.Project(engine);
    projectToBuild.Load(sourceProjectFile);
    projectToBuild.SetProperty("Configuration", "Release");
    var successfulBuild = projectToBuild.Build();
    I was able to get that to build single projects, but as soon as I would add another project to the "build project" it would fail (i.e. a console app would work fine, but a console app that had a reference to a class library project would fail)

    I've tried your suggestion and migrated the code to be:
    var projectToBuild = Microsoft.Build.Evaluation.ProjectCollection.GlobalProjectCollection.LoadProject(
        buildFile.FullName);
    projectToBuild.SetProperty("Configuration", "Release");
    var successfulBuild = projectToBuild.Build();
    That appears to be working for my sample application, going to do some more testing.  Thanks so much!


    Follow up questions:
    • There doesn't appear to be a "GetEvaluatedProperty" on the projectToBuild object, know where that has been moved to?
    • Is there a document or web site that lists these types of changes (i.e. "you were using X, now use Y"?) and what the impacts of those changes are (i.e. BuildEngine.Project won't compile 4.0 applications with references)

    Thanks so much for you assistance!
    Chris
    Thursday, December 17, 2009 11:03 PM
  • Re: Using BuildEngine.Project ... pay attention to the compiler warnings - it will tell you that this API is obsolete (MSDN also mentions it).

    Please use new thread for follow up questions next time.

    Here are some answers:
    1) GetEvaluatedProperty was probably moved to Project.GetPropertyValue.
    2) I don't think there's a document like that. I can ask MSBuild team if they plan to publish such conversion document - I agree it would be handy. I had quite hard time to figure out how to make the new API work.

    -Karel
    Tuesday, December 22, 2009 7:16 PM
    Moderator