clean build artifacts

This commit is contained in:
Matthew Parker [SSW]
2023-11-15 22:16:57 +10:00
parent b9b2d2c4ec
commit 0907901ca0
3 changed files with 45 additions and 1 deletions

View File

@@ -135,6 +135,24 @@ public partial class MainWindowViewModel : ViewModelBase
ParityResults?.Add(e.Message);
}
}
[RelayCommand]
private async Task DeleteBinAndObjFoldersInFolder(CancellationToken token)
{
ErrorMessages?.Clear();
ParityResults.Clear();
ResultsLabel = string.Empty;
try
{
CleanFolder.DeleteFolderWithOnlyBinAndObjSubFolders(SolutionFolderPath);
ResultsLabel = "Successfully deleted bin and obj folders";
}
catch (Exception e)
{
ResultsLabel = "Failed to delete bin and obj folders";
ParityResults?.Add(e.Message);
}
}
[RelayCommand]
private async Task LoadSolutionFile(CancellationToken token)

View File

@@ -31,7 +31,7 @@
<TextBlock Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center" Name="CsprojFilePath" Text="{Binding CsprojFilePath}" />
<Button Grid.Column="2" Width="60" HorizontalContentAlignment="Center" Command="{Binding ClearCsprojFileCommand}">Clear</Button>
</Grid>
<Grid Margin="0 5 0 0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ShowGridLines="False" RowDefinitions="*,*" ColumnDefinitions="*,*,*">
<Grid Margin="0 5 0 0" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ShowGridLines="False" RowDefinitions="*,*,*" ColumnDefinitions="*,*,*">
<Button Grid.Row="0" Grid.Column="0" MinHeight="130" Padding="10" Margin="5"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
@@ -86,6 +86,15 @@
Check For Missing Treat Warnings as Errors
</TextBlock>
</Button>
<Button Grid.Row="2" Grid.Column="0" MinHeight="130" Padding="10" Margin="5"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
VerticalContentAlignment="Center" HorizontalContentAlignment="Center"
IsEnabled="{Binding SolutionFilePath, Mode=OneWay, Converter={x:Static StringConverters.IsNotNullOrEmpty}}"
Command="{Binding DeleteBinAndObjFoldersInFolderCommand}">
<TextBlock TextWrapping="Wrap">
Clear bin and obj folders
</TextBlock>
</Button>
</Grid>
<Label HorizontalAlignment="Center" Name="ResultsLabel" Content="{Binding ResultsLabel}"></Label>
</StackPanel>

View File

@@ -0,0 +1,17 @@
namespace DotNetSolutionTools.Core;
public static class CleanFolder
{
public static void DeleteFolderWithOnlyBinAndObjSubFolders(string folderPath)
{
var binAndObjFolders = Directory.GetDirectories(folderPath, "*", SearchOption.AllDirectories)
.Where(x => x.EndsWith(Path.DirectorySeparatorChar + "bin") || x.EndsWith(Path.DirectorySeparatorChar + "obj"))
.ToList();
foreach (var folder in binAndObjFolders)
{
Directory.Delete(folder, true);
}
}
}