The Windows 10 UWP app CleanupVS is now in The Store. Its a free app for cleaning up Visual Studio workspaces by recursively deleting bin and obj folders from Visual Studio project folders. This article covers some of the code techniques used in he app.

Including, quick folder count, app metadata, using the Feedback Hub and populating a RichTextbox.

 

About the App

When you clean up a disk via the FileExplorer-Property Dialog as a developer there is a workspace that sace that isn’t touched.. Your Visual Studio projects workspace; that is the bin and obj folders in VS project folders.  I find that for, say, 4G of project space 3G can be regained by deleting those 2 folders in every VS project folder.

This Windows 10 UWP app can recursively seek out VS project folders and delete all bin and obj folders there in. There is a DummyMode which runs through the descendent folders counting the folders to delete and the space to be gained. You can also zip up the whole folder first.

The CleanupVS app in The Store.

 

cleanupvs-5

  The App

 

The app recursively searches the selected folder for folders that contain a Visual Studio project file as specified by the “Project File Types”; a CSV list; of the relevant file extensions without the dot. It then looks for “Folders to Delete”, specified as a CSV list, in each project folder so found.

 

[1] A Quick count of a folder and its sub folder space

This works quite quickly:

private async Task<long> GetFolderSize(StorageFolder fldr)
{
    // Query all files in the folder. Make sure to add the CommonFileQuery
    // So that it goes through all sub-folders as well
    var folders = fldr.CreateFileQuery(CommonFileQuery.OrderByName);

    // Await the query, then for each file create a new Task which gets the size
    var fileSizeTasks = (await folders.GetFilesAsync()).Select(async file => (await file.GetBasicPropertiesAsync()).Size);

    // Wait for all of these tasks to complete. WhenAll thankfully returns each result
    // as a whole list
    var sizes = await Task.WhenAll(fileSizeTasks);

    // Sum all of them up. You have to convert it to a long because Sum does not accept ulong.
    long folderSize = sizes.Sum(l => (long)l);
    return folderSize;
}

Ref: I found this on StackOverflow Thx Nate.

 

[2] Get App Assembly MetaData

This is app settings you set on the Project Properties-Application-Assembly Information dialog

var assembly = this.GetType().GetTypeInfo().Assembly;
var appName = assembly.GetName().Name;
var appVersion = assembly.GetName().Version;

String appVersionVal = String.Format(
   "{0}.{1}.{2}.{3}" 
   ,
   appVersion.Major, appVersion.Minor, appVersion.Build, appVersion.Revision
   );

[2.1] Get App Assembly Custom Attributes

var assembly = this.GetType().GetTypeInfo().Assembly;
var custonAppAttributes = assembly.CustomAttributes;
string version1Val="";
string descriptiontVal = "";
string copyyrightVal = "";
var version1 = assembly.GetCustomAttribute<System.Reflection.AssemblyVersionAttribute>();
if (version1 != null)
    version1Val = version1.Version;
var desciption = assembly.GetCustomAttribute<System.Reflection.AssemblyDescriptionAttribute>();
if (desciption != null)
    descriptiontVal = desciption.Description;
var copyright = assembly.GetCustomAttribute<System.Reflection.AssemblyCopyrightAttribute>();
if (copyright != null)
    copyyrightVal = copyright.Copyright;

There are other custom attributes that you can get, Look for Classes of the format of AssemblyXXXXXXAttribute  at https://docs.microsoft.com/en-us/dotnet/api/system.reflection

Nb The second method for getting Version came up blank whereas the first worked.

 

[3] Get Package MetaInfo

Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;

msg += "\nPackage Info\n";
msg += String.Format(
               "Name: \"{0}\"\n" +
               "Version: {1}.{2}.{3}.{4}\n" +
               "Architecture: {5}\n" +
               "Publisher: \"{6}\"\n" +
                "Description: \"{7}\"\n"
               ,
               package.DisplayName,
               version.Major, version.Minor, version.Build, version.Revision,
               packageId.Architecture,
               package.PublisherDisplayName,
               package.Description
               );

Got this from StackOverflow as well. Thx Maxim

 

[4] Using the Feedback Hub for feedback from app users for your Store App

The Feedback Hub that has been used for some time, especially with respect to Windows Insiders, can be used for your Store App feedback as well.

private async void feedbackButton_Click(object sender, RoutedEventArgs e)
{
    if (Microsoft.Services.Store.Engagement.StoreServicesFeedbackLauncher.IsSupported())
    {
        var launcher = Microsoft.Services.Store.Engagement.StoreServicesFeedbackLauncher.GetDefault();
        await launcher.LaunchAsync();
    }
}

Ref: https://docs.microsoft.com/en-au/windows/uwp/monetize/launch-feedback-hub-from-your-app

 

[5] Adding content to a UWP RichTextBox

You add content to an XAML RichTextBox  by adding paragraphs. A paragraph can have content added by adding formatted Runs or by adding Spans. A Span has one or more Runs added to embellish it.

private void PopulateRichTextBox(string heading, string txt)
{
        Paragraph paragraph = new Paragraph();
        Run runHeading = new Run();
 
        runHeading.Foreground = new SolidColorBrush(Windows.UI.Colors.Red);
        runHeading.FontWeight = Windows.UI.Text.FontWeights.SemiBold;
        runHeading.Text = heading;

        Span span = new Span();
        span.FontWeight = Windows.UI.Text.FontWeights.Normal;
        Run run1 = new Run();
        run1.FontStyle = Windows.UI.Text.FontStyle.Italic;
        run1.Text = txt;
        span.Inlines.Add(run1);

        paragraph.Inlines.Add(runHeading);
        paragraph.Inlines.Add(span);
        AboutRichTextBlock.Blocks.Add(paragraph);
}


Hope this helps. SmileThumbs up

Will post some more later.