Ok, I am at my wits' end. We have a VB.Net application with many dependent assemblies (all contained in the solution), that builds well from with the Visual Studio IDE. Now I want to automate the build to produce three different versions (and copy the results to our installer package). After some research I came up with the following code, which I use from a C# console project:
var projectFileName = @"D:\NetCode\60-40\Applications\ControlViewer\BridgeIt.vbproj";
string target = "Build";
var properties = new Dictionary<string, string>();
properties.Add("Configuration","NBBR");
properties.Add("Platform", "AnyCPU");
var buildRequest = new BuildRequestData(projectFileName, properties, null, new[] { target }, null);
var buildParams= new BuildParameters(new ProjectCollection());
var logger = new BasicLogger();
buildParams.Loggers = new List<ILogger>() { logger};
BuildManager.DefaultBuildManager.ResetCaches();
var result = BuildManager.DefaultBuildManager.Build(buildParams, buildRequest);
Debug.Print(logger.GetLogString());
This builds all assemblies, only at the very last I get the following error:`
ERROR C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(1657,5): The "GetReferenceNearestTargetFrameworkTask" task could not be instantiated from the assembly "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet\NuGet.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. Kan een object van het type NuGet.Build.Tasks.GetReferenceNearestTargetFrameworkTask niet converteren naar het type Microsoft.Build.Framework.ITask. : The final remark is in Dutch and describes an `InvalidCastException'.
I tried:
- Updating the NuGetPackages for Microsoft.Build.
- Installing the NuGet Tools from the VS-installer
- Registered the build dll's in the gac as explained in this link (Though I fear that this was unwise)
Well, nothing works. Could it be a C#/VB.Net compatibility issue?
Other thoughts: Most of the projects in the solution have come from VS 2015. Currently we are using VS 2017.