前天以為安裝好DotNET Core至CentOS,看到ASP.NET頁面,應該就可以專心進入開發程序。
但這兩天預到的問題實在太多,由Visual Studio本身對.NET Core的兼容性,.NET Core本身的問題,到Project設定,再到Apache等等問題,我都花了不少時間解決。
始終.NET Core還是很新的產品,Google後都很難找到實際解決方法,所以我把預到的問題和解決方法寫下來,希望幫到其他人。
開發環境可以參照我前天所寫的
ASP.NET Core + CentOS 7 + Apache安裝攻略
Error 1 - The project has not been restored or restore failed - run `dotnet restore`
一次就出現4個Error Message:
Severity Code Description Project File Line Suppression State
Error 3. You may be trying to publish a library, which is not supported. Use `dotnet pack` to distribute libraries. SkinCV C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 262
Error 2. The project does not list one of 'win10-x64, win81-x64, win8-x64, win7-x64' in the 'runtimes' section. SkinCV C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 262
Error 1. The project has not been restored or restore failed - run `dotnet restore` SkinCV C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 262
Error Can not find runtime target for framework '.NETCoreApp,Version=v1.0' compatible with one of the target runtimes: 'win10-x64, win81-x64, win8-x64, win7-x64'. Possible causes: SkinCV C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet\Microsoft.DotNet.Common.Targets 262
這個錯誤大多數出現在當你以Core 1.0.0開新Project後,做第一次Nuget Package更新到v1.0.1後,就會出現。
幸好這個問題已經在Github上有人
報告issue #2442。
解決方法是打開project.json,加上:
"runtimes": {
"win10-x64": {},
"win8-x64": {}
},
之後找出"
Microsoft.NETCore.App",修改為
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
}
或者你會發現,在
dependencies裡同樣都有
"Microsoft.NETCore.App": "1.0.1",我自己就把這個刪除,但大家視乎情況而定。