The answer to the above question should be “nothing, unless you’re trying to build a project that references entity framework”, but apparently it isn’t so.
Say you have a project you’ve built, and you want to build it through code, using the Engine class of Microsoft.Build.Engine assembly.
The code should look something like this (taken from MSDN):
// Instantiate a new Engine object Engine engine = new Engine(); // Instantiate a new FileLogger to generate build log FileLogger logger = new FileLogger(); // Set the logfile parameter to indicate the log destination logger.Parameters = @"logfile=C:\temp\build.log"; // Register the logger with the engine engine.RegisterLogger(logger); // Build a project file bool success = engine.BuildProjectFile(@"c:\somewhere\someproject.csproj"); //Unregister all loggers to close the log file engine.UnregisterAllLoggers(); if (success) Console.WriteLine("Build succeeded."); else Console.WriteLine(@"Build failed. View C:\temp\build.log for details");
Some notes about the code:
If you refer to the sample code given in the MSDN: http://msdn.microsoft.com/en-us/library/microsoft.build.buildengine.engine.registerlogger.aspx, you can drop the line that sets the BinPath – the property is obsolete, but for some reason remained in the sample code.
Don’t forget to add both Microsoft.Build.Engine and Microsoft.Build.Framework assemblies to your code (both in the 3.5 version)
When you try to run the code on a project with a target framework of 3.5, you might get an error like this in your log file (‘I’ve marked the important stuff in bold):
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.targets(40,5): error MSB4127: The "EntityDeploy" task could not be instantiated from the assembly "C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.Build.Tasks.dll". 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.Data.Entity.Build.Tasks.EntityDeploy’ to type ‘Microsoft.Build.Framework.ITask’.
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Data.Entity.targets(40,5): error MSB4060: The "EntityDeploy" task has been declared or used incorrectly, or failed during construction. Check the spelling of the task name and the assembly name.
Done building target "EntityDeploy" in project "SampleClassLibrary.csproj" — FAILED.
If you look at the Microsoft.Data.Entity.Build.Tasks assembly, you will notice that this assembly uses both versions of Microsoft.Build.Framework – both version 2.0 and 3.5
Of course, if you try to add both versions to your project, it just won’t work, because both have the same name.
So, how can we make it work? just let the application know that it should always use version 3.5, even if version 2.0 is specified (implied in the error message). To do that, you need to add an assemblyBinding to your config file:
<?xml version="1.0" encoding="utf-8" ?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.Build.Framework"
publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/> <bindingRedirect oldVersion="0.0.0.0-22.214.171.124" newVersion="126.96.36.199"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
And that’s it