Xamarin開発環境をととのえる
目次

Xamarinに手を出し始めたのは良いのですが、その開発環境がどうにも手になじまず試行錯誤しています。今回の記事で解決できるかというと微妙ではありますが、やれるだけのことはやってみようと思います。
PROBLEM
- Xamarin開発環境がサーバー側のそれとかい離している
- Visual Studio Community 2015の動作がもっさりしている
- 適切な開発フローがわからない
- 適切なアプリケーションフレームワークがわからない
- 適切なXAMLプレビュワーがわからない
- 適切なAndroidエミュレーターがわからない
SOLUTION
というわけで、動作が快適になったといわれるVisual Studio 2017がでたのでそちらを中心に開発環境を暫定で整理します、永遠のWIPです。
開発フロー
まず、想定している開発フローは下記の通り。
- テスト駆動開発
- デバッグ
- エミュレーター画面の動作確認 - ビルドスピード等考慮してUWPでおこなう
- アウトプット - Debug.WriteLineなどの確認
- イミディエイト - 変数の追跡
- C# REPL - C#やパッケージの動作確認
- XAMLのプレビュー - いらない子
- テスト
- 単体テスト - NUnit
- UIテスト - 保留
- Github Flowにそったデプロイ
featureブランチをきってプルリクエストをたてる- 当該ブランチに対してCIツールでビルド・テスト・配布を自動化 - ビルド・テスト後にレビュアーにメールにて配布しスマホで確認してもらう流れ。
- CIツール
- Visual Studio Mobile Center - HockeyApp(クラッシュレポート)とXamarin Test Cloud(UIテスト)を統合したCIサービス。Xamarin.Formsは2017年3月18日現在iOS対応、Android非対応という状況。UWPは知らない。
- Wercker -
masterマージ後にいらなくなったfeatureブランチを消すなどの後片付け役。
- Appストアへデプロイ
- Android
- iOS
- UWP
ちなみにWerckerでのfeatureブランチなどの後片付けはこんな感じです。masterマージのタイミングで走らせます。
box: ruby:2.4.0
build:
steps:
- add-ssh-key:
host: github.com
keyname: GITHUB
- add-to-known_hosts:
hostname: github.com
fingerprint: 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
- script:
name: Add git-tag
code: |
_tag=$(date -u -d '9 hours' +%Y-%m-%d-%H-%M-%S)
git remote add origin git@github.com:nabinno/utagaki.git
git config --global user.email 'wercker@blahfe.com'
git config --global user.name 'Wercker Bot'
git tag -a $_tag master -m 'wercker deploy'
git push origin $_tag
after-steps:
- wantedly/pretty-slack-notify:
webhook_url: ${SLACK_WEBHOOK_URL}
channel: general
開発環境
その上で開発環境は下記の通りに設定します。Visual Studio 2017版Xamarinは現時点でHypervisorがHyper-Vを考慮していない、Intel HAXMやVirtualBoxなどのホスト型を前提としています。ただ私見としては、VirtualBoxなどのホスト型はWindowsアップデート時に動作検証対象となっておらずクラッシュが起きやすいです。Hyper-Vを開発環境とすることをお薦めします。いずれにせよ、デバッグはビルドスピード等がHypervisorに左右されるAndroidではなくUWPで行うと良いでしょう。
- IDE
- Visual Studio Community 2017
- Basic extentions
- Microsoft Visual Studio Community 2017 Version 15.0.26228.9 D15RTWSVC
- Microsoft .NET Framework Version 4.6.01586
- Visual C# 2017
- JavaScript Language Service 2.0
- JavaScript Project System 2.0
- JavaScript UWP Project System 2.0
- TypeScript 2.1.5.0
- Microsoft Visual Studio VC Package 1.0
- Xamarin 4.3.0.784 (73f58d6)
- Xamarin.Android SDK 7.1.0.41 (9578cdc)
- Xamarin.iOS and Xamarin.Mac SDK 10.4.0.123 (35d1ccd)
- Visual Studio Tools for Unity 3.0.0.1
- Visual Studio Tools for Universal Windows Apps 15.0.26228.00
- Mono Debugging for Visual Studio Mono.Debugging.VisualStudio
- ASP.NET and Web Tools 2017 15.0.30223.0
- NuGet Package Manager 4.0.0
- Common Azure Tools 1.9
- NpgsqlVSPackage Extension 1.0
- Merq 1.1.13-alpha (2f64b6d)
- VSPackage Extension 1.2
- Other extentions
- JetBrains ReSharper Ultimate 2016.3.2 - なにはともあれ入れておく。
- CodeMaid 10.2.7 - 気軽にコード整形してくれる。
- .ignore 1.2.71
- Markdown Editor 1.11.201
- File Nesting 2.6.67
- GitHub.VisualStudio 2.2.0.8
- VSColorOutput 2.5
- HideMenu 1.0 - MinimaliticViewとの組み合わせでEmacsっぽい画面になる。
- MinimaliticView Extension 1.0
- Debug用エミュレーター
- XAML Previewer for Xamarin.Forms - Gorilla PlayerはVS2017未対応の上、Data Bindingを参照できないため機能的にXAML Previewer for Xamarin.Formsとほぼかわらない様子。
- Android Emulator Manager/Android SDK Manager - VS2017ではHyper-VベースのVisual Studio Emulator for Xamarinがなくなり、Intel HAXMベースのAndroid Emulator Manager/Android SDK Manager (Google)のみとなった。
- DevStack
- Prism
- Prism template - スキャフォールド、スニペット便利
- Profile78 - Profile259になっているがWindows 8必要ないので
- Newtonsoft.Json
- FubarCoder.RestSharp.Portable.HttpClient
- NUnit
- Moq
キーバインド
おまけのEmacs風キーバインド。Edit.Emacsメソッドは1級市民ではないのでその周辺で代替します。Edit.LineCut、Edit.Outline、ReSharpeのいらないキーバインドは削除しています。
| category | command | keybind |
|---|---|---|
| Navigation | CodeMaid.SwitchFile | C-c,: |
| Navigation | Edit.CharLeft | C-b |
| Navigation | Edit.CharRight | C-f |
| Navigation | Edit.DocumentBottom | M-> |
| Navigation | Edit.DocumentTop | M-< |
| Navigation | Edit.GoTo | M-g |
| Navigation | Edit.IncrementalSearch | C-s |
| Navigation | Edit.LineDown | C-n |
| Navigation | Edit.LineEnd | C-e |
| Navigation | Edit.LineStart | C-a |
| Navigation | Edit.LineUp | C-p |
| Navigation | Edit.NextMethod | M-} |
| Navigation | Edit.PageDown | C-v |
| Navigation | Edit.PageUp | M-v |
| Navigation | Edit.PreviousMethod | M-{ |
| Navigation | Edit.ScrollLineCenter | C-l |
| Navigation | Edit.ToggleAllOutling | C-u,M-c |
| Navigation | Edit.ToggleOutlingExpansion | C-i |
| Navigation | Edit.WordNext | M-f |
| Navigation | Edit.WordPrevious | M-b |
| Navigation | ReSharper.ReSharper_GotoRecentFiles | M-x,b |
| Navigation | Team.TeamExplorerSearch | C-x,g |
| Navigation | View.C#Interactive | C-c,i |
| Navigation | Window.NewVerticalTabGroup | C-x,| |
| Navigation | Window.PreviousTabGroup | C-x,1 |
| Edit | Build.BuildSolution | C-c,b |
| Edit | Build.RebuildSolution | C-c,r |
| Edit | CodeMaid.JoinLine | C-c,j |
| Edit | CodeMaid.SortLines | M-x,s |
| Edit | Debug.Start | C-c,d |
| Edit | Edit.BackwardDelete | C-h |
| Edit | Edit.BackwardDelete | M-h |
| Edit | Edit.BreakLine | C-m |
| Edit | Edit.Capitalize | M-c |
| Edit | Edit.CommentSelection | M-; |
| Edit | Edit.Delete | C-d |
| Edit | Edit.InsertSnippet | C-, |
| Edit | Edit.LineCut | C-k |
| Edit | Edit.LineDownExtendColumn | M-. |
| Edit | Edit.LineUpExtendColumn | M-, |
| Edit | Edit.MakeLowercase | M-l |
| Edit | Edit.MakeUppercase | M-u |
| Edit | Edit.Paste | C-y |
| Edit | Edit.SelectCurrentWord | C-SPC |
| Edit | Edit.UncommentSelection | M-: |
| Edit | Edit.Undo | M-/ |
| Edit | File.Close | C-x,k |
| Edit | File.SaveSelection | C-x,C-s |
| Edit | Project.AddNewItem | C-c,s |
| Edit | ReSharpe._ReSharper_DuplicateText | C-c,p |
| Edit | ReSharper.ReSharper_GotoRelatedFile | C-c,; |
| Edit | ReSharper.ReSharper_GotoText | C-c,g |
| Edit | Tools.ManageNuGetPackagesforSolution | C-c,n |
| Edit | Tools.Options | M-0 |
| Edit | View.PackageManagerConsole | C-q,1 |
WRAPUP
途中途中心の声が漏れていますが、なんとか触れる状態になってきました。ただ、モチベーションとしては下がり気味なのでこのままXamarinをさわり続けるかは分かりません。やはり文化が違いますね。
