Newtonsoft.JSON v9.01 + FileNotFoundException(.NET Core类库) [英] Newtonsoft.JSON v9.01 + FileNotFoundException (.NET Core Class library)

查看:113
本文介绍了Newtonsoft.JSON v9.01 + FileNotFoundException(.NET Core类库)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(VS2015 Update 3 +补丁)

(VS2015 Update 3 + Patch)

我有一个简单的.NET控制台应用程序(.NET 4.6),并引用了一个针对NetStandard v1.3的.NET核心类库. 该类库引用了Newtonsoft.JSON.

I have a plain .NET console application (.NET 4.6) and reference a .NET core class library that targets NetStandard v1.3. The class library has a reference to Newtonsoft.JSON.

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Newtonsoft.Json": "9.0.1"
  },
  "buildOptions": { "platform": "anycpu" },

  "frameworks": {
    "netstandard1.3": {
      "imports": "dnxcore50"
    }
  }
}

引用的NewtonSoft.JSON包已部署在此处:

The referenced NewtonSoft.JSON package is deployed here:

C:\ Users \ UserAccount \ .nuget \ packages \ Newtonsoft.Json \ 9.0.1

C:\Users\UserAccount\.nuget\packages\Newtonsoft.Json\9.0.1

例外:

"System.IO.FileNotFoundException"类型的未处理异常 发生在DotNetConsoleApplication.exe

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in DotNetConsoleApplication.exe

其他信息:无法加载文件或程序集 'Newtonsoft.Json,版本= 9.0.0.0,文化=中性, PublicKeyToken = 30ad4fe6b2a6aeed"或其依赖项之一.这 系统找不到指定的文件.

Additional information: Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.

我想.net核心库将引用netstandard1.0文件夹中的dll.

I guess the .net core lib would reference the dll from the netstandard1.0 folder.

推荐答案

已解决2016年7月31日

创建一个全新的普通.NET控制台应用程序(不是.NET Core)和一个.NET Core类库,而无需在它们之间进行任何前期引用.

场景:
1.基于.NET 4.6的控制台应用,该应用引用了
2. .Net核心类库(已引用Newtonsoft.JSON v9.01)

Solved 31.07.2016

Create a fresh plain .NET console app (not .NET Core) and a .NET Core class library, without doing any referencing between them upfront.

Scenario:
1. Console app based on .NET 4.6, which references a
2. .Net Core Classlibrary (has a reference to Newtonsoft.JSON v9.01)

.NET核心类库的配置如下(project.json):

The .NET core class library is configured as follows (project.json):

{
  "version": "1.0.0-*",

  "dependencies": {
    "NETStandard.Library": "1.6.0",
    "Newtonsoft.Json": "9.0.1"
  },
  "buildOptions": { "platform": "anycpu" },

  "frameworks": {
    "netstandard1.3": {
      "imports": "dnxcore50"
    }
  }
}


解决方案

1.)首先从.Net核心类库项目中创建一个Nuget包.


Solution

1.) Create a Nuget package from the .Net core class library project first.

以admin身份打开命令行. 转到(cd).NET核心类库项目(.xproj)的项目文件夹.

运行以下命令:

Open the command line as admin. Go (cd) to the project folder of the .NET core class library project (.xproj).

Run the following command:

dotnet包

"pack"参数将根据.NET Core类库创建一个nuget程序包,并将该程序包复制到debug/release文件夹,具体取决于您的项目配置.

The "pack" parameter will create a nuget package out of the .NET Core class library and copy the package to the debug/release folder, depends on your project configuration.

将nuget软件包文件复制到一个托管本地nuget软件包的文件夹中. 我已经将它们复制到:

Copy the nuget package files to a folder where you host your local nuget packages. I have copied them to:

C:\ Users \ Admin.nuget \ packages \ LocalPackages \ NetCore46ClassLibrary

C:\Users\Admin.nuget\packages\LocalPackages\NetCore46ClassLibrary


屏幕截图:
2.)如果您没有本地的Nuget提要,则必须先创建一个!


Screenshot:
2.) If you don't have a local Nuget feed,you have to create one first!

本地Nuget文件夹(我将其命名为"LocalPackages")将托管您的自定义Nuget软件包.本地Nuget Feed将指向"LocalPackages",这是所有本地软件包的根文件夹.

The local Nuget folder (I named it "LocalPackages") will host your custom Nuget packages. The local Nuget Feed will point to "LocalPackages", which is the root folder for all local packages.

创建本地nuget提要并将.net核心类库的nuget程序包复制到localPackages文件夹下的某个位置之后,即可开始安装.net核心类库的nuget程序包.

After you have created the local nuget feed and copied the nuget package of your .net core class library somewhere beneath the localPackages folder, you are ready to install your .net core class library nuget package.

3.)将.NET Core库Nuget软件包安装到.NET控制台应用程序中

您现在必须再次打开程序包管理器控制台". 选择包裹来源:本地包裹(这是我的本地供稿名称,可能有所不同). 默认项目应该是您的.NET控制台应用程序.

you now have to open the Package Manager Console again. Choose Package Source: Local Packages (This is my local feed name, may be different). And the default project should be your .NET console app.

在我的情况下,将.net核心类库nuget软件包安装到控制台应用程序中

Install your .net core class library nuget package into the console app, in my case:

install-package NetCore46ClassLibrary

就是这样!

我的系统:

My system:

dotnet --version
1.0.0-preview2-003121

dotnet --version
1.0.0-preview2-003121

这篇关于Newtonsoft.JSON v9.01 + FileNotFoundException(.NET Core类库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆