我在Visual Studio扩展中使用JSON.NET,它不包含在发行版中(by design by Microsoft)。
在链接的票证中,他们只是声明应该使用v9.0.1。支持多个VStudio版本“使事情复杂化”。
另一个SO question给出并回答哪些在所有情况下都不起作用。
我使用nuget包,而后者依赖于Newtonsoft.Json 10.0.x.有没有什么办法可以继续使用JSON.NET v10.x而不会给Visual Studio带来任何麻烦?
一种可能的解决方案是使用AppDomain并在新的AppDomain中包装所有与Newtonsoft.json相关的调用:
myDomain = AppDomain.CreateDomain("myDomain", AppDomain.CurrentDomain.Evidence,
new AppDomainSetup()
{
ApplicationBase = extensionPath,
ConfigurationFile = Path.Combine(extensionPath, configurationFileName)
});
文件configurationFileName应随您的扩展程序一起提供,其内容如下所示:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-10.0.0.0" newVersion="10.0.0.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>