2016-10-31 61 views
3

我有我正在開發的dotnet核心應用程序,它是跨平臺的。我想用野田佳彥在我的項目的實用程序,但得到甚至儘管我已經nodatime定義爲我的項目依賴以下錯誤:NodaTime是否與NetCoreApp 1.0兼容?

System.IO.FileNotFoundException: Could not load file or assembly 'NodaTimestrong text, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1'. The system cannot find the file specified. 
     File name: 'NodaTime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=4226afe0d9b296d1' 
     at project.ef.CalendarHelper.ValidateTimeZone(String timezoneTypeName) 
     at project.ef.CalendarHelper. 

下面是該項目的配置文件:

API項目

{ 
    "buildOptions": { 
    "preserveCompilationContext": true, 
    "emitEntryPoint": true, 
    "warningsAsErrors": true, 
    "debugType": "portable", 
    "copyToOutput": { 
     "include": [ 
     "config.json", 
     "Certificate.pfx" 
     ] 
    } 
    }, 
    "dependencies": { 
    "AspNet.Security.OAuth.Introspection": "1.0.0-alpha2-final", 
    "AspNet.Security.OAuth.Validation": "1.0.0-alpha2-final", 
    "Microsoft.AspNetCore.Diagnostics": "1.0.0", 
    "Microsoft.AspNetCore.Mvc": "1.0.0", 
    "Microsoft.AspNetCore.Mvc.Formatters.Json": "1.0.0", 
    "Microsoft.AspNetCore.Mvc.Cors": "1.0.0", 
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0", 
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0", 
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", 
    "Microsoft.Extensions.Configuration.Json": "1.0.0", 
    "Microsoft.Extensions.Logging.Console": "1.0.0", 
    "Microsoft.Extensions.Logging.Debug": "1.0.0", 
    "Microsoft.EntityFrameworkCore.Design": { 
     "type": "build", 
     "version": "1.0.0-preview2-final" 
    }, 
    "Microsoft.NETCore.App": "1.0.0", 
    "project.ef": "1.0.0-*" 
    }, 
    "tools": { 
     "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final" 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ "portable-dnxcore50+net45+win8+wp8+wpa81" ] 
    } 
    }, 
    "publishOptions": { 
    "include": [ 
     "config.json" 
    ] 
    }, 
    "runtimes": { 
     "win10-x64": {}, 
     "osx.10.11-x64": {}, 
     "ubuntu.14.04-x64": {} 
    } 
} 

EF項目

{ 
    "dependencies": { 
    "NETStandard.Library": "1.6.0", 
    "Npgsql.EntityFrameworkCore.PostgreSQL": "1.0.1", 
    "Npgsql.EntityFrameworkCore.PostgreSQL.Design": "1.0.1",  
    "project.Internal.ERP": "1.1.0-*", 
    "project.models": "1.0.0-*", 
    "NodaTime": "2.0.0-alpha-*" 
    }, 
    "frameworks": { 
    "netstandard1.6": { 
     "imports": [ 
     "dnxcore50", 
     "portable-net451+win8" 
     ] 
    } 
    } 
} 
+0

你的依賴是什麼樣的? 2.0.0-alpha20160729應該和netcoreapp1.0一樣好,不需要任何導入。 –

+0

它似乎是:https://www.nuget.org/packages/NodaTime/2.0.0-alpha20160729 - 目標netstandard1.1所以你應該沒問題。你能顯示你的project.json嗎?我查看了包裝內容,並且它只包含NodaTime,不包含NodaTimestrong組件。 – Pawel

+0

我修改了我的問題以包含更多詳細信息。我有兩個project.json - 一個用於api,另一個用於我的數據庫邏輯。是否有一個示例dotnet核心項目張貼在我可以交叉引用的地方? @JonSkeet我在下面的示例中看到,你引用1.0.1和im引用1.0.0,也許這裏有一些東西。我使用NodaTime複製這個問題的解決方案http://stackoverflow.com/questions/17348807/how-to-translate-between-windows-and-iana-time-zones – chris

回答

4

Noda Time 1.x僅針對PCL。你可能能夠得到它與netcoreapp1.0一起工作,但我不會保證它。

但是Noda Time 2.0的目標是netstandard1.1,所以應該沒問題。這是僅作爲一個alpha版本的權利,但它工作正常:

project.json內容:

{ 
    "buildOptions": { 
    "emitEntryPoint": true 
    }, 
    "dependencies": { 
    "NodaTime": "2.0.0-alpha20160729" 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "type": "platform", 
      "version": "1.0.1" 
     } 
     } 
    } 
    } 
} 

Program.cs內容:

using System; 
using NodaTime; 

public class Program 
{ 
    public static void Main(string[] args) 
    { 
     Console.WriteLine(SystemClock.Instance.GetCurrentInstant()); 
    } 
} 

這沒有問題運行。

+0

結果顯式定義了nodatime依賴項的版本號解決了我的問題。有時它是最簡單的解決方案哈哈 - 謝謝! – chris

+0

@chris:你可能想看看它以前的版本 - 如果你看看'project.lock.json',你可以看到確切解決的依賴關係。 –

+0

哦哇 - 我看着我的nuget緩存,它以前使用NodaTime.2.0.0-alpha20140807.nupkg。這可能解釋它哈哈 – chris