我想构建一个使用Roslyn NuGet包的C#应用程序.我有Visual Studio 2013.事情进展顺利,直到我遇到一个ReflectionTypeLoadException,寻找Microsoft.Build版本14,我把它带到VS 2015 CTP(参见这个问题).
我的问题是,如果没有遇到这个问题,你能在多大程度上得到Roslyn?您是否只需要避免使用MSBuildWorkspace类?有哪些替代方案?是否可以在使用2013 IDE时从2015年下载并使用Microsoft.Build程序集?
我尝试在.NET Compiler Platform("Roslyn")Samples中创建类似ConsoleClassifier的东西.(Microsoft.CodeAnalysis v0.7 ......)此时我得到了ReflectionTypeLoadException:
CustomWorkspace workspace = new CustomWorkspace();
ReflectionTypeLoadException
{"Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."}
LoaderExceptions: FileNotFoundException
{"Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. A rendszer nem találja a megadott fájlt.":"Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
堆栈跟踪:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.get_InnerCatalog()
at System.ComponentModel.Composition.Hosting.AssemblyCatalog.GetExports(ImportDefinition definition)
at System.ComponentModel.Composition.Hosting.AggregateCatalog.GetExports(ImportDefinition definition)
at System.ComponentModel.Composition.Hosting.CatalogExportProvider.InternalGetExportsCore(ImportDefinition definition, AtomicComposition atomicComposition)
at …Run Code Online (Sandbox Code Playgroud) 对于我的硕士论文,我正在构建一个Visual Studio插件,该插件应该对当前打开的解决方案执行一些代码分析.为了做到这一点,我决定尝试使用Roslyn,使用相应的nuget包.
一切正常(SyntaxTree导航代码,...),直到我尝试使用MSBuildWorkspace.Create().
此最后一次调用导致以下异常:
无法加载文件或程序集'Microsoft.Build,Version = 14.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一.系统找不到指定的文件.":"Microsoft.Build,Version = 14.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a
我找到了这两个帖子:
据我所知,我需要Visual Studio 14的MSBuild工具,它位于相关的iso中.
我不想安装完整的Visual Studio 14,这也是因为我正在编写的插件应该在Visual Studio 2013下运行.从这两个帖子看来我似乎只能安装VS 14的这一部分.
我的问题实际上是:如果我为Visual Studio 14安装MSBuild工具,那么我目前正在处理的所有其他Visual Studio项目会发生什么?目前他们使用Visual Studio 2013的MSBuild工具.仍然可以使用它?
更新
我实际上想要得到的是找到一个给定的方法是否在项目中有引用.这个想法是按照这篇文章进行的.