Opening solution with msbuildworkspace gives diagnostic errors without details

I am trying to parse a solution with Roslyn using MSBuildWorkspace. The solution is a new solution that has 2 class libraries, one of which references the other.

They are built in Visual Studio 2017, .Net 4.6.2.

When I open the solution, I get two general errors in the workspace. Diagnostics: Msbuild was unable to process the PathToProject file, There is nothing else in the diagnostic or output window to indicate WHY it was unable to process the project file.

Code to open solution:

namespace RoslynAnalyse
    {
    class Program
    {
        static void Main(string[] args)
        {
            LocalAnalysis();
        }

        private static void LocalAnalysis()
        {
            var workspace = MSBuildWorkspace.Create();
            var solution = workspace.OpenSolutionAsync(@"D:\Code\Roslyn\RoslynAnalyse\SolutionToAnalyse\SolutionToAnalyse.sln").Result;
            var workspaceDiagnostics = workspace.Diagnostics;

        }
    }
}

      

Microsoft.CodeAnalysis version is 2.0.0.0. Does anyone know why MSBuild failed, how can I get more information?

+3


source to share


1 answer


When MSBuildWorkspace cannot open a project or solution in this way, it is almost always because the application using MSBuildWorkspace does not include the same bind redirects as in the msbuild.exe.config file.

MSBuild uses linking redirection to resolve tasks (typically already compiled C # code using possibly different versions of the msbuild APIs) to use all the existing msbuild APIs. Otherwise, msbuild gets load errors at runtime.



The solution is to add the app.config file to your project and copy the binding redirects (assemblyBinding section of msbuild.exe.config file) to your file.

+3


source







All Articles