VSIX newtonsoft isn't in package (VS>15.5) suppress package

巧了我就是萌 提交于 2019-12-05 14:27:57

Include the Newtonsoft.Json.dll as a linked item in the extension csproj.

<Content Include="..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll">
  <Link>Newtonsoft.Json.dll</Link>
  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
  <IncludeInVSIX>true</IncludeInVSIX>
</Content>

The file can then be easily added through the VSIX Manifest Editor as a Microsoft.VisualStudio.Assembly. This should result in the following Asset defined in the .vsixmanifest file.

<Asset d:Source="File" Path="Newtonsoft.Json.dll" Type="Microsoft.VisualStudio.Assembly" AssemblyName="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed" />

This is far from a perfect solution because this linked item won't follow a package upgrade and you'll have to manage that yourself. Obviously a perfect solution would be not needing to do this at all and Newtonsoft.Json.dll would be included like any other referenced assembly. However, this is the least invasive solution we found that allowed us to control the version of Newtonsoft.Json.dll included in the vsix package and also not rely on the version found in C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PrivateAssemblies.

The VS behavior is meant to prevent you from shipping a copy of Newtonsoft.Json. The reason for this is that VS ships a copy itself (or several at one point in time...), and includes a binding redirect to that version. Even if you were to place one in your VSIX, it should never be loaded anyways.

If you do by some means force VS to load your version of Newtonsoft.Json, you create an opportunity to break other features within VS that depend on the VS-included version.

This is long after the original question was posted, but if your %LocalAppData%\Microsoft\VisualStudio\15.0_<instanceID>\devenv.exe.config does not contain a codebase and a binding redirect for Newtonsoft.Json, I would open a feedback ticket to follow up with the VS team.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!