0

我正在针对目标框架进行开发.NET Framework 3.5。一个项目Logger使用以下库

Newtonsoft.Json.dll
Version = 4.5.0.0
AssemblyFileVersion = 5.0.8.16617
PublicKeyToken = 30ad4fe6b2a6aeed
TargetFramework = v3.5

这是项目中的一个引用程序集。

应用程序MyApp具有对项目的项目引用Logger,因此间接引用Newtonsoft.Json.dll.

将该Copy Local属性设置为true将强制Newtonsoft.Json.dll复制到输出目录。编译MyApp也会将其复制Newtonsoft.Json.dll到相应的输出目录中。请注意,Newtonsoft.Json.dllGAC中没有

到目前为止还好。

现在我将以下库安装到.NET Framework 4.0GAC ( %windir%\Microsoft.NET\assembly):

Newtonsoft.Json.dll
Version = 4.5.0.0
AssemblyFileVersion = 4.5.8.15203
PublicKeyToken = 30ad4fe6b2a6aeed
TargetFramework = v4.0

将此库安装在 GAC.NET Framework 4.0中将导致引用的项目Newtonsoft.Json.dll不再复制到MyApp. 但它仍然被复制到Logger.

我试图向自己解释这种行为:引用的项目Newtonsoft.Json.dll被复制到输出目录,Logger因为它的Copy Local属性设置为true.

但我不明白为什么Newtonsoft.Json.dll不再将其复制到MyApp. 我安装到 GAC 的库.NET Framework 4.0应该(在我看来)对构建系统不“可见”,因为我的项目是针对.NET Framework 3.5.

在运行时会有一个System.IO.FileNotFoundException因为Newtonsoft.Json.dll找不到库(这对我来说很清楚,因为库位于 4.0 GAC 中,而不是 GAC 3.5 使用的MyApp)。

  • 为什么目标框架 3.5 项目的构建系统知道 GAC 中的程序集.NET Framework 4.0
  • 如何将Newtonsoft.Json.dll目标框架3.5引用的本地复制到GAC 4.0中MyApp有a时的输出目录?Newtonsoft.Json.dll
4

1 回答 1

0

Have you tried setting Specific version to true under properties for the reference? I suspect that the GAC will be searched first during compilation, so if you don't specify a version, any version will be considered "acceptable", and no other version will be exported.

If you specify a version, that from the GAC should not be considered valid, and the other one should be exported, as before.

Update: I did a quick search, and discovered that the Newtonsoft package seems to be released under an MIT liscence, which effectively means you can do whatever you want with it.

A solution for you might therefor be to compile it yourself, with whatever target framework and version number you need.

于 2013-10-23T13:08:03.923 回答