Roslyn: el espacio de trabajo se carga en la aplicación de consola pero no en la tarea msbuild

Tengo una tarea msbuild personalizada con este comando:

var workspace = Workspace.LoadStandAloneProject(csprojPath);

Cuando lo ejecuto, arroja el siguiente error:

  System.InvalidCastException was unhandled by user code
  Message=Unable to cast transparent proxy to type 'Roslyn.Utilities.SerializableDataStorage'.
  Source=Roslyn.Services
  StackTrace:
       at Roslyn.Utilities.RemoteServices.CreateInstance[T]()
       at Roslyn.Services.Host.TemporaryStorageServiceFactory.CreateService(IWorkspaceServiceProvider workspaceServices)
       at Roslyn.Services.Host.WorkspaceServiceProviderFactory.Provider.c__DisplayClass7.b__4()
       at Roslyn.Utilities.NonReentrantLazy`1.get_Value()
       at Roslyn.Services.Host.WorkspaceServiceProviderFactory.Provider.GetService[TWorkspaceService]()
       at Roslyn.Services.SolutionServices..ctor(IWorkspaceServiceProvider workspaceServices, ILanguageServiceProviderFactory languageServicesFactory)
       at Roslyn.Services.Solution..ctor(SolutionId id, String filePath, VersionStamp version, VersionStamp latestProjectVersion, ILanguageServiceProviderFactory languageServiceProviderFactory, IWorkspaceServiceProvider workspaceServices)
       at Roslyn.Services.Host.SolutionFactoryServiceFactory.SolutionFactoryService.CreateSolution(SolutionId id)
       at Roslyn.Services.Host.TrackingWorkspace.CreateNewSolution(ISolutionFactoryService solutionFactory, SolutionId id)
       at Roslyn.Services.Host.TrackingWorkspace..ctor(IWorkspaceServiceProvider workspaceServiceProvider, Boolean enableBackgroundCompilation, Boolean enableInProgressSolutions)
       at Roslyn.Services.Host.HostWorkspace..ctor(IWorkspaceServiceProvider workspaceServiceProvider, Boolean enableBackgroundCompilation, Boolean enableInProgressSolutions, Boolean enableFileTracking)
       at Roslyn.Services.Host.LoadedWorkspace..ctor(ILanguageServiceProviderFactory languageServiceProviderFactory, IWorkspaceServiceProvider workspaceServiceProvider, IProjectFileService projectFileFactsService, IDictionary`2 globalProperties, Boolean enableBackgroundCompilation, Boolean enableFileTracking)
       at Roslyn.Services.Host.LoadedWorkspace..ctor(ExportProvider exportProvider, Boolean solutionLoadOnly, Boolean enableFileTracking)
       at Roslyn.Services.Host.LoadedWorkspace..ctor(Boolean enableFileTracking)
       at Roslyn.Services.Host.LoadedWorkspace.LoadStandAloneProject(String projectFileName, String configuration, String platform, String language, Boolean enableFileTracking)
       at Roslyn.Services.Workspace.LoadStandAloneProject(String projectFileName, String configuration, String platform, String language, Boolean enableFileTracking)
       ...

El mismo código, cuando se ejecuta en una aplicación de consola, con el mismo proyecto, funciona bien.

¿Algunas ideas? Google no ha sido útil!

Respuestas a la pregunta(2)

Su respuesta a la pregunta