ubuntuで.net coreを動かしたらnuget動かんかったのでその対処とAngular追加
タイトルどおりです。なんにも動かんくなったので、対処法を書く。
まず以下のエラーが発生
Unhandled Exception: System.IO.FileLoadException: Could not load file or assembly 'System.Runtime.Extensions, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
おなじみのアセンブリエラーですが、.net coreは.net Frameworkと違ってbin配下にnugetライブラリが入りません。以下のコマンド打つとパスが表示されます。
saito@saito-Aspire-one-1-131:~$ dotnet --info .NET コマンド ライン ツール (2.0.0) Product Information: Version: 2.0.0 Commit SHA-1 hash: cdcd1928c9 Runtime Environment: OS Name: ubuntu OS Version: 16.04 OS Platform: Linux RID: ubuntu.16.04-x64 Base Path: /usr/share/dotnet/sdk/2.0.0/ Microsoft .NET Core Shared Framework Host Version : 2.0.0 Build : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d
パスが「/usr/share/dotnet/sdk/」なのでlsすると.Net Core1.0からいっぱい入ってました。ログ取るの忘れていたので「2.0」となってますが、本当はPreviewがはいってました
これが原因で、Nuget参照するときにどのバージョンでNugetを参照するかわかんなかったみたいです(これ予想なのであてにしないで下さい)
全部いらないんで、過去のバージョンをすべて削除
sudo apt remove dotnet*
全部なくなりました。次に.Net Core2.0をインストールします。以下の記事を参考に
kledgeb.blogspot.jp
これでdotnet new mvc、dotnet restore、dotnet build、dotnet runをやってみて確認で完了。
次にAngularテンプレートを入れます。Windowsとちょっと違いました。
SPAテンプレートを取得
dotnet new --install Microsoft.DotNet.Web.Spa.ProjectTemplates::2.0.0-rc1-final
いろんな記事に「dotnet new --install Microsoft.AspNetCore.SpaTemplates::*」と書いてあるけど、ubuntuだと出来ませんでした。Windowsだと出来た気がするけど。
ログは出力されてReact、Vueなど様々なスキャフォールディングが使えます、超便利。
Restoring packages for /home/saito/.templateengine/dotnetcli/v2.0.0/scratch/restore.csproj... Installing Microsoft.DotNet.Web.Spa.ProjectTemplates 2.0.0-rc1-final. Generating MSBuild file /home/saito/.templateengine/dotnetcli/v2.0.0/scratch/obj/restore.csproj.nuget.g.props. Generating MSBuild file /home/saito/.templateengine/dotnetcli/v2.0.0/scratch/obj/restore.csproj.nuget.g.targets. Restore completed in 3.7 sec for /home/saito/.templateengine/dotnetcli/v2.0.0/scratch/restore.csproj. テンプレート 短い名前 言語 タグ -------------------------------------------------------------------------------------------------------- Console Application console [C#], F#, VB Common/Console Class library classlib [C#], F#, VB Common/Library Unit Test Project mstest [C#], F#, VB Test/MSTest xUnit Test Project xunit [C#], F#, VB Test/xUnit ASP.NET Core Empty web [C#], F# Web/Empty ASP.NET Core Web App (Model-View-Controller) mvc [C#], F# Web/MVC ASP.NET Core Web App razor [C#] Web/MVC/Razor Pages ASP.NET Core with Angular angular [C#] Web/MVC/SPA ASP.NET Core with React.js react [C#] Web/MVC/SPA ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA ASP.NET Core Web API webapi [C#], F# Web/WebAPI global.json file globaljson Config Nuget Config nugetconfig Config Web Config webconfig Config Solution File sln Solution Razor Page page Web/ASP.NET MVC ViewImports viewimports Web/ASP.NET MVC ViewStart viewstart Web/ASP.NET Examples: dotnet new mvc --auth Individual dotnet new mstest dotnet new --help
これで以下のコマンド打てばAngularプロジェクトが完成。
mkdir test cd test dotnet new angular npm i dotnet restore dotnet buld dotnet run