2016-09-16 45 views
1

我擁有生產裝配和單元測試裝配的最簡單解決方案設置。首先,這裏是相關配置:無法獲得.NET Core NUnit測試項目對我的生產類庫的參考,無法正常工作

Common.sln 
global.json 
-- src 
---- Common 
------ project.json 
-- test 
---- UnitTests 
------ project.json 

global.json

{ 
    "projects: [ "src", "test" ] 
} 

Common\project.json

{ 
    "name": "<redacted>", 
    "version": "2.0.0-*", 
    "description": "<redacted>", 
    "copyright": "© 2016 <redacted>", 
    "title": "<redacted>", 
    "authors": [ "<redacted>" ], 
    "language": "en-US", 
    "buildOptions": { 
    "platform": "anycpu", 
    "xmlDoc": true 
    }, 
    "dependencies": { 
    "NETStandard.Library": "1.6.0" 
    }, 
    "frameworks": { 
    "netstandard1.6": { 
     "imports": "dnxcore50" 
    } 
    } 
} 

UnitTests\project.json

{ 
    "version": "0.0.0-*", 
    "testRunner": "nunit", 
    "dependencies": { 
    "Common": { 
     "target": "project" 
    }, 
    "NUnit": "3.4.1", 
    "dotnet-test-nunit": "3.4.0-beta-2" 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": [ 
     "netcoreapp1.0", 
     "portable-net45+win8" 
     ], 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "version": "1.0.1-*", 
      "type": "platform" 
     } 
     } 
    } 
    } 
} 

當我編譯,我在錯誤列表中得到這些錯誤:

Error NU1002 The dependency Common does not support framework .NETCoreApp,Version=v1.0. UnitTests <redacted>\UnitTests\project.json 5 
Error   The given key was not present in the dictionary. UnitTests  1 

這是怎麼回事?我已經遵循了我可以找到的每個教程來嘗試設置這些項目,但沒有一個能夠工作。自從教程創建以來,.NET Core land中的某些內容可能已經發生了變化?我需要更改什麼才能讓UnitTests項目識別我的Common項目?其他

兩個較小的顧慮:

  1. 我運行Windows 7 SP1。這是否導致portable-net45+win8導入問題?
  2. 還有更新版本Microsoft.NETCore.App:1.0.1。原來,project.json引用的是1.0.0版本,所以我改變了它。但是,在解決方案資源管理器中,我仍然看到1.0.0。

參考文獻:

http://www.alteridem.net/2016/06/18/nunit-3-testing-net-core-rc2/

+0

你使用Visual Studio?我猜根據SLN文件是。另外,你的global.json是否包含每個項目?你能編輯你的答案並添加global.json嗎? –

+0

是的,VS 2015更新3,完全修補。 – NathanAldenSr

+0

我已經更新了相應的問題。 – NathanAldenSr

回答

0

事實證明,幾乎所有我看到的是簡單的工裝問題。我希望微軟很快解決這個問題。在錯誤列表中看到陳舊的錯誤消息是非常令人困惑的。從命令行運行dotnet builddotnet test時,一切正常。

我現在的目標是netstandard1.5,因爲從我能收集的數據來看,它有parity with .NET Framework 4.6.2,這是我在這項工作之前的目標。

這裏是project.json最終版本:

Common\project.json

{ 
    "name": "<redacted>", 
    "version": "2.0.0-*", 
    "description": "<redacted>", 
    "copyright": "<redacted>", 
    "title": "<redacted>", 
    "authors": [ "<redacted>" ], 
    "language": "en-US", 
    "packOptions": { 
    "tags": [ 
     "GM", 
     "UAS", 
     "Common" 
    ], 
    "iconUrl": "<redacted>", 
    "repository": { 
     "type": "git", 
     "url": "<redacted>" 
    } 
    }, 
    "buildOptions": { 
    "xmlDoc": true, 
    "compile": { 
     "include": [ 
     "GlobalAssemblyInfo.cs" 
     ] 
    } 
    }, 
    "dependencies": { 
    "NETStandard.Library": "1.6.0" 
    }, 
    "frameworks": { 
    "netstandard1.5": {} 
    } 
} 

UnitTests\project.json

{ 
    "version": "0.0.0", 
    "testRunner": "nunit", 
    "dependencies": { 
    "NUnit": "3.4.0", 
    "dotnet-test-nunit": "3.4.0-beta-2", 
    "Common": { 
     "target": "project" 
    } 
    }, 
    "frameworks": { 
    "netcoreapp1.0": { 
     "imports": "portable-net45+win8", 
     "dependencies": { 
     "Microsoft.NETCore.App": { 
      "version": "1.0.0-*", 
      "type": "platform" 
     } 
     } 
    } 
    } 
} 
相關問題