[英]RoslynPad FileNotFoundException in Visual Studio Extension
是否有人成功地在Visual Studio Extension(VSIX)中運行WPF RoslynPad編輯器(僅供參考:我正在使用Visual Studio 2015 Enterprise)?
當嘗試像這樣在VSIX中初始化Roslyn主機時:
var host = new RoslynHost(additionalAssemblies: new[]
{
Assembly.Load("RoslynPad.Roslyn.Windows"),
Assembly.Load("RoslynPad.Editor.Windows")
});
我收到以下錯誤:
無法加載文件或程序集'System.Collections.Immutable,版本= 1..2.0.0,區域性=中性,PublicKeyToken = b03f5f7f11d50a3a'或其依賴項之一。 系統找不到指定的文件。“:”“ System.Collections.Immutable,版本= 1.2.0.0,區域性=中性,PublicKeyToken = b03f5f7f11d50a3a”
堆棧跟蹤為:
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeAssembly.get_DefinedTypes()
at RoslynPad.Roslyn.RoslynHost.<>c.<.ctor>b__20_0(Assembly x)
at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
at System.Composition.Hosting.ContainerConfiguration.CreateContainer()
at RoslynPad.Roslyn.RoslynHost..ctor(NuGetConfiguration nuGetConfiguration, IEnumerable`1 additionalAssemblies, RoslynHostReferences references)
請注意,RoslynPad提供的“ RosylnPadPelSample” WPF應用程序中可以使用相同的代碼。
讓我大吃一驚的是,它正在尋找System.Collections.Immutable版本1.2.0.0(我相信這是System.Reflection.Metadata.dll中的依賴項),因為示例應用程序不包含此文件。 它具有版本1.2.0.1(與擴展名相同),但具有綁定重定向,可以彌補其遺漏:
<dependentAssembly>
<assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.2.1.0" newVersion="1.2.1.0" />
</dependentAssembly>
如果我明確添加System.Collections.Immutable
版本1.2.0.0作為參考,那么我會從RoslynPad獲得相同的異常,但是這次它找不到System.Collections.Immutable
版本1.2.0.1! 綁定重定向在Visual Studio擴展中似乎沒有生效。 有誰知道如何在Visual Studio Extensions中完成綁定重定向或如何解決此問題?
我相信您不能在VS中使用.config文件進行程序集綁定重定向,但是可以使用AppDomain.AssemblyResolve
事件來實現類似的效果。
例如,請參閱此博客文章 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.