How do I compile an XNA project from C# with MSBuild 14?

Viewed 216

I have an XNA project I have that compiles perfectly fine in Visual Studio 2015, that makes use of C# 6 features.

Previously, I had some tools coded in C# that would auto-compile the project when it was using C# 5 under VS 2013, but the change to C# 6 has broken things somehow.

To reproduce this I created a new console application, referenced Microsoft.Build, Microsoft.Build.Framework, and Microsoft.Build.Utilities.Core assemblies from C:\Program Files (x86)\MSBuild\14.0\Bin.

I then created my C# compiler project with the following code:

namespace CompileXna
{
    class Program
    {
        static void Main(string[] args)
        {
            const string solutionPath = @"D:\Code\My Projects\FrbTest\FrbTest.sln";

            var properties = new Dictionary<string, string>()
            {
                {"Configuration", "Debug"},
                {"Platform", "x86" }
            };

            var parameters = new BuildParameters
            {
                Loggers = new ILogger[] {new BuildLogger()}
            };

            var request = new BuildRequestData(solutionPath, properties, null, new string[] {"Build"}, null);
            var manager = BuildManager.DefaultBuildManager.Build(parameters, request);

            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }

    class BuildLogger : Logger
    {
        public override void Initialize(IEventSource eventSource)
        {
            eventSource.ErrorRaised += (sender, args) =>
                Console.WriteLine($"Error: File {args.File} line {args.LineNumber} message {args.Message}");

            eventSource.WarningRaised += (sender, args) =>
                Console.WriteLine($"Warning: File {args.File} line {args.LineNumber} message {args.Message}");
        }
    }
}

Unfortunately, when this runs I get the following error:

Error: File C:\Program Files (x86)\MSBuild\Microsoft\XNA Game Studio\v4.0\Microsoft.Xna.GameStudio.ContentPipeline.targets line 78 message The "BuildContent" task could not be instantiated from the assembly "Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Xna.Framework.Content.Pipeline.Tasks.BuildContent' to type 'Microsoft.Build.Framework.ITask'.

I tried looking in the details of the build output in Visual Studio 2015 when it successfully compiles my XNA project, but even with Detailed logging all I could find (seemingly) relevant was:

1>Using "BuildContent" task from assembly "Microsoft.Xna.Framework.Content.Pipeline, Version=4.0.0.0, Culture=neutral, PublicKeyToken=842cf8be1de50553".
1>Task "BuildContent"
1>Done executing task "BuildContent".

Anyone have any success on this?

0 Answers
Related