Visual Studio 2017を使ってみた
いよいよリリースされたVisual Studio 2017
さっそくPCにインストールしてみました。
まぁ、ぶっちゃけどんな機能が追加されたのかは以下のページを参照したほうが手っ取り早いです。
www.atmarkit.co.jp
www.visualstudio.com
リリースノートは以下から。
www.visualstudio.com
最初インストールしたときには気が付かなかったんですが、"Live Unit Testing"の機能はEnterpriseにしかないそうで。
Communityエディションにはありませんので注意。
もう一つ気になったのですが…
"XML をクラスとして貼り付ける"のメニュー無くね?
あれか、XMLはもはや時代遅れということか…
もはや定番拡張機能となったProductivity Power Toolsの2017向けツールもリリースされています。
blogs.msdn.microsoft.com
Team Foundation Server 2017
また、TFSも次期バージョンがリリースされています。
www.visualstudio.com
WPFでPathListBoxを使う
WPFのコントロールにPathListBoxというものがあります。
これは、通常のItemsControlとは少し異なる動作をします。
百聞は一見にしかず、まずは以下のイメージを御覧ください。
単純な動作ではありますが他のList系コントロールとは明らかに動作が異なります。
このような一風変わったPathListBoxですが、かなり簡単に実装することができます。
PathListBoxのプロパティ
PathListBoxには以下のプロパティがあります。
- StartItemIndex
- WrapItems
- LayoutPaths
StartItemIndex
ItemsSourceに設定したコレクション要素の開始インデックスのプロパティです。
例えば"StartItemIndex=2"に設定すると以下の様になります。
WrapItems
このプロパティをtrueにすると、表示範囲外にあるコレクション要素をラップします。
falseにすると、表示範囲外のコレクション要素はラップされずに見切れてしまいます。
LayoutPaths
ItemsSourceにバインドしたコレクションを配置するためのレイアウト要素を設定することができます。
上記のサンプルでは、赤いPathを作成し、そのPathをLayoutPathsに設定しています。
以下、サンプルのソースです。
事前準備
PathListBoxを使用するには、以下のアセンブリを参照する必要があります。
Blendを使用すればドラッグアンドドロップで自動的に参照が追加されます。
PathListBoxを参照するには、予め以下の名前空間を追加しておきましょう。
xmlns:ec="http://schemas.microsoft.com/expression/2010/controls"
- MainWindow.xaml
<Window x:Class="PathListBoxSample.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:ec="http://schemas.microsoft.com/expression/2010/controls" xmlns:local="clr-namespace:PathListBoxSample" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" Title="MainWindow" Width="240" Height="240" mc:Ignorable="d"> <Window.DataContext> <local:MainViewModel /> </Window.DataContext> <Grid> <ec:PathListBox ItemsSource="{Binding Values, Mode=OneWay}" StartItemIndex="2" WrapItems="True"> <ec:PathListBox.LayoutPaths> <ec:LayoutPath SourceElement="{Binding ElementName=path}" /> </ec:PathListBox.LayoutPaths> </ec:PathListBox> <Border> <Path x:Name="path" Margin="47.958,56.296,51.484,48.649" Data="M167.9651,297.05052 C167.1821,300.96551 298.95333,358.22029 298.95333,358.22029 L336.53545,481.93313 501.22995,268.87785 584.51969,339.3325" Stretch="Fill" Stroke="#FFE40000" /> </Border> <Button Width="32" HorizontalAlignment="Left" VerticalAlignment="Top" Command="{Binding AddCommand, Mode=OneWay}" Content="+" /> <Button Width="32" Margin="36,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" Command="{Binding SubCommand, Mode=OneWay}" Content="-" /> </Grid> </Window>
- MainViewModel.cs
namespace PathListBoxSample { using System.Collections.ObjectModel; using System.Linq; using Microsoft.Practices.Prism.Commands; using Microsoft.Practices.Prism.Mvvm; public class MainViewModel : BindableBase { public ObservableCollection<int> Values { get; private set; } public DelegateCommand AddCommand { get; private set; } public DelegateCommand SubCommand { get; private set; } public MainViewModel() { Values = new ObservableCollection<int>(Enumerable.Range(1, 5)); AddCommand = new DelegateCommand(() => Values.Add(Values.Max() + 1)); SubCommand = new DelegateCommand(() => { if (Values.Any()) Values.Remove(Values.Max()); }); } } }
このようにPathListBoxはWPFの中でもかなり特殊なコントロールです。
以下のページにもう少し詳しい使い方が記述されています。
今回作成したサンプルはこちら↓↓↓↓↓
github.com
JenkinsでxUnitを実行・レポート出力する方法
JenkinsでxUnitを実行したときに少しハマったのでメモメモ。
JenkinsでxUnitを使用している場合、MSTestと同じ方法では実行できません。
xUnitを使用するには、"xunit.runner.console"が必要です。
以下、実行環境です。
- Jenkins : 2.31.2
- .NET Framework : 4.6
- xUnit : 2.1.0
1.xUnitをNuGetパッケージから取得する。
NuGetで以下のパッケージを取得します。
- xunit
- xunit.runner.console
2.JenkinsでxUnit実行ジョブを設定する。
Jenkinsのジョブ設定で、ビルドから"Windowsバッチコマンドの実行"を追加して以下のコマンドを入力します。
::過去の結果があれば削除 rmdir /S /Q <レポート出力フォルダ> mkdir <レポート出力フォルダ> ::xUnitは通常のMSTestではなく、以下の方法で実行する必要がある。 cd %WORKSPACE%\packages\xunit.runner.console.2.1.0\tools xunit.console.exe "%WORKSPACE%<ユニットテストプロジェクトDLLパス>" -nunit "%WORKSPACE%<レポート出力フォルダ>\<レポートファイル名>.xml"
"xunit.console.exe"はxUnitをコンソールで実行するための実行ファイルです。
ちなみに、"-?"で以下のようなヘルプが表示されます。
Valid options: -nologo : do not show the copyright message -nocolor : do not output results with colors -noappdomain : do not use app domains to run test code -failskips : convert skipped tests into failures -parallel option : set parallelization based on option : none - turn off all parallelization : collections - only parallelize collections : assemblies - only parallelize assemblies : all - parallelize assemblies & collections -maxthreads count : maximum thread count for collection parallelization : default - run with default (1 thread per CPU thread) : unlimited - run with unbounded thread count : (number) - limit task thread pool size to 'count' -noshadow : do not shadow copy assemblies -wait : wait for input after completion -diagnostics : enable diagnostics messages for all test assemblies -debug : launch the debugger to debug the tests -serialize : serialize all test cases (for diagnostic purposes only) -trait "name=value" : only run tests with matching name/value traits : if specified more than once, acts as an OR operation -notrait "name=value" : do not run tests with matching name/value traits : if specified more than once, acts as an AND operation -method "name" : run a given test method (should be fully specified; : i.e., 'MyNamespace.MyClass.MyTestMethod') : if specified more than once, acts as an OR operation -class "name" : run all methods in a given test class (should be fully : specified; i.e., 'MyNamespace.MyClass') : if specified more than once, acts as an OR operation -namespace "name" : run all methods in a given namespace (i.e., : 'MyNamespace.MySubNamespace') : if specified more than once, acts as an OR operation Reporters: (optional, choose only one) -appveyor : forces AppVeyor CI mode (normally auto-detected) -quiet : do not show progress messages -teamcity : forces TeamCity mode (normally auto-detected) -verbose : show verbose progress messages Result formats: (optional, choose one or more) -xml <filename> : output results to xUnit.net v2 style XML file -xmlv1 <filename> : output results to xUnit.net v1 style XML file -nunit <filename> : output results to NUnit-style XML file -html <filename> : output results to HTML file
Jenkinsには、xUnitでのレポート出力フォーマットに対応していないので、NUnitのフォーマットで出力します。
Publish HTML reportプラグインでレポートを確認したい場合は、HTML出力も追加してもいいかもしれません。
Jenkinsでインストーラーを作成する方法
Visual Studio 2012以降、昔ながらのインストーラセットアップ プロジェクトが拡張機能で使用することができます。
(Visual Studio 2010は、Install Shield一択だったのですがあれは何だったのか…)
できればこのあたりもJenkinsで実行できれば、
ということができます。
まずは下準備としてJenkinsを起動しているPCのVisual Studioの拡張機能からインストーラーを追加します。
[ツール] - [拡張機能と更新プログラム]を選択し、オンラインから"install"で検索してインストーラープロジェクトを追加します。
次にレジストリエディタを開いて以下の値を追加します。
"12.0_Config"と言うのは"Visual Studio 2013"の構成情報のことです。
2012の場合は、"11.0_Config"、2015の場合は、"14.0_Config"となっています。
ちなみに、これを追加しないとビルドしても以下のようなメッセージが出力されてインストーラーが作成されません。
(これに結構ハマってました…)
ERROR: An error occurred while validating. HRESULT = '8000000A'
続いてJenkinsの設定です。
ジョブの設定から、"Windowsバッチコマンドの実行"を選択して以下のコマンドを入力します。
:: 開発環境によって実行フォルダを変えてください。 cd C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE devenv "%WORKSPACE%<ソリューションファイルパス>" /Project "%WORKSPACE%<セットアッププロジェクトパス>" /Build "Release"
上記では"Release"モードでビルドしていますが、ここは必要に応じて変更してください。
なお、"devenv.exe"のコマンドライン引数は以下を参照してください。