This commit is contained in:
Wiesław Šoltés 2017-11-09 22:40:00 +01:00
Родитель 723f037493
Коммит dc155c297d
3 изменённых файлов: 47 добавлений и 22 удалений

Просмотреть файл

@ -4,16 +4,41 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" mc:Ignorable="d"
Title="MainWindow" Height="600" Width="800" Title="MainWindow" Height="700" Width="1000"
WindowStartupLocation="CenterScreen" WindowStartupLocation="CenterScreen"
UseLayoutRounding="True" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display"> UseLayoutRounding="True" SnapsToDevicePixels="True" TextOptions.TextFormattingMode="Display">
<Grid> <Grid>
<DataGrid ItemsSource="{Binding GroupedReferences}"> <Grid.ColumnDefinitions>
<DataGrid.RowDetailsTemplate> <ColumnDefinition Width="250"/>
<DataTemplate> <ColumnDefinition Width="10"/>
<DataGrid ItemsSource="{Binding}"/> <ColumnDefinition Width="*"/>
</DataTemplate> </Grid.ColumnDefinitions>
</DataGrid.RowDetailsTemplate> <Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="3">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBox x:Name="textSearchPath" Text="C:\DOWNLOADS\GitHub\" Grid.Row="0"/>
<TextBox x:Name="textSearchPattern" Text="*.props" Grid.Row="1"/>
<Button x:Name="buttonSearch" Content="_Search" Click="buttonSearch_Click" Grid.Row="2"/>
</Grid>
<DataGrid x:Name="groups" ItemsSource="{Binding GroupedReferences}" CanUserAddRows="False" AutoGenerateColumns="False" Grid.Row="1" Grid.Column="0">
<DataGrid.Columns>
<DataGridTextColumn Header="Key" Binding="{Binding Key}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid>
<GridSplitter ResizeDirection="Columns" ResizeBehavior="PreviousAndNext" Width="10" Grid.Row="1" Grid.Column="1"/>
<DataGrid x:Name="references" ItemsSource="{Binding ElementName=groups, Path=SelectedItem.Value}" CanUserAddRows="False" AutoGenerateColumns="False" Grid.Row="1" Grid.Column="2">
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Binding="{Binding Name}" IsReadOnly="True"/>
<DataGridTextColumn Header="Version" Binding="{Binding Version}" IsReadOnly="False"/>
<DataGridTextColumn Header="FileName" Binding="{Binding FileName}" IsReadOnly="True"/>
</DataGrid.Columns>
</DataGrid> </DataGrid>
</Grid> </Grid>
</Window> </Window>

Просмотреть файл

@ -7,14 +7,14 @@ namespace MSBuildPropsUpdater
public MainWindow() public MainWindow()
{ {
InitializeComponent(); InitializeComponent();
}
var updater = Updater.Create(@"C:\DOWNLOADS\GitHub\", "*.props", new string[] { }); private void buttonSearch_Click(object sender, RoutedEventArgs e)
{
updater.PrintVersions(); //var updater = Updater.Create(@"C:\DOWNLOADS\GitHub\", "*.props", new string[] { });
//updater.PrintVersions();
updater.ValidateVersions(); //updater.ValidateVersions();
DataContext = Updater.Create(textSearchPath.Text, textSearchPattern.Text, new string[] { });
DataContext = updater;
} }
} }
} }

Просмотреть файл

@ -9,9 +9,9 @@ namespace MSBuildPropsUpdater
{ {
public class Updater public class Updater
{ {
public IList<XDocument> Documents { get; private set; } public IList<XDocument> Documents { get; set; }
public IList<PackageReference> References { get; private set; } public IList<PackageReference> References { get; set; }
public IEnumerable<IGrouping<string, PackageReference>> GroupedReferences { get; private set; } public Dictionary<string, List<PackageReference>> GroupedReferences { get; set; }
public static string NormalizePath(string path) public static string NormalizePath(string path)
{ {
@ -57,7 +57,7 @@ namespace MSBuildPropsUpdater
FindReferences(searchPath, searchPattern, ignoredPaths, updater.References, updater.Documents); FindReferences(searchPath, searchPattern, ignoredPaths, updater.References, updater.Documents);
updater.GroupedReferences = updater.References.GroupBy(x => x.Name); updater.GroupedReferences = updater.References.GroupBy(x => x.Name).OrderBy(x => x.Key).ToDictionary(x => x.Key, x => x.ToList());
return updater; return updater;
} }
@ -68,7 +68,7 @@ namespace MSBuildPropsUpdater
foreach (var package in GroupedReferences) foreach (var package in GroupedReferences)
{ {
Debug.WriteLine($"Package {package.Key} is installed:"); Debug.WriteLine($"Package {package.Key} is installed:");
foreach (var v in package) foreach (var v in package.Value)
{ {
Debug.WriteLine($"{v.Version}, {v.FileName}"); Debug.WriteLine($"{v.Version}, {v.FileName}");
} }
@ -80,12 +80,12 @@ namespace MSBuildPropsUpdater
Debug.WriteLine("Checking installed NuGet package dependencies versions:"); Debug.WriteLine("Checking installed NuGet package dependencies versions:");
foreach (var package in GroupedReferences) foreach (var package in GroupedReferences)
{ {
var packageVersion = package.First().Version; var packageVersion = package.Value.First().Version;
bool isValidVersion = package.All(x => x.Version == packageVersion); bool isValidVersion = package.Value.All(x => x.Version == packageVersion);
if (!isValidVersion) if (!isValidVersion)
{ {
Debug.WriteLine($"Error: package {package.Key} has multiple versions installed:"); Debug.WriteLine($"Error: package {package.Key} has multiple versions installed:");
foreach (var v in package) foreach (var v in package.Value)
{ {
Debug.WriteLine($"{v.Version}, {v.FileName}"); Debug.WriteLine($"{v.Version}, {v.FileName}");
} }